Skip to content

Commit 7d7b470

Browse files
Fixed the issue where gc was triggered during the attribute search process and a hashmap was recreated.
JerryScript-DCO-1.0-Signed-off-by: tangbin [email protected]
1 parent 5020015 commit 7d7b470

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

jerry-core/ecma/base/ecma-gc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,6 +2109,7 @@ ecma_gc_free_object (ecma_object_t *object_p) /**< object to free */
21092109
void
21102110
ecma_gc_run (void)
21112111
{
2112+
JERRY_CONTEXT(running_gc_count)++;
21122113
#if (JERRY_GC_MARK_LIMIT != 0)
21132114
JERRY_ASSERT (JERRY_CONTEXT (ecma_gc_mark_recursion_limit) == JERRY_GC_MARK_LIMIT);
21142115
#endif /* (JERRY_GC_MARK_LIMIT != 0) */
@@ -2235,6 +2236,7 @@ ecma_gc_run (void)
22352236
/* Free RegExp bytecodes stored in cache */
22362237
re_cache_gc ();
22372238
#endif /* JERRY_BUILTIN_REGEXP */
2239+
JERRY_CONTEXT(running_gc_count)--;
22382240
} /* ecma_gc_run */
22392241

22402242
/**

jerry-core/ecma/base/ecma-helpers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ ecma_find_named_property (ecma_object_t *obj_p, /**< object to find property in
729729
}
730730

731731
#if JERRY_PROPERTY_HASHMAP
732-
if (steps >= (ECMA_PROPERTY_HASMAP_MINIMUM_SIZE / 2))
732+
if (steps >= (ECMA_PROPERTY_HASMAP_MINIMUM_SIZE / 2) && JERRY_CONTEXT(running_gc_count) == 0)
733733
{
734734
ecma_property_hashmap_create (obj_p);
735735
}

jerry-core/jcontext/jcontext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ struct jerry_context_t
156156
jerry_external_string_free_cb_t external_string_free_callback_p; /**< free callback for external strings */
157157
void *error_object_created_callback_user_p; /**< user pointer for error_object_update_callback_p */
158158
jerry_error_object_created_cb_t error_object_created_callback_p; /**< decorator callback for Error objects */
159+
uint32_t running_gc_count; /**< The current status of gc */
159160
size_t ecma_gc_objects_number; /**< number of currently allocated objects */
160161
size_t ecma_gc_new_objects; /**< number of newly allocated objects since last GC session */
161162
size_t jmem_heap_allocated_size; /**< size of allocated regions */

jerry-core/jmem/jmem-heap.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ jmem_heap_init (void)
103103
JMEM_VALGRIND_NOACCESS_SPACE (JERRY_HEAP_CONTEXT (area), JMEM_HEAP_AREA_SIZE);
104104

105105
#endif /* !JERRY_SYSTEM_ALLOCATOR */
106+
JERRY_CONTEXT(running_gc_count) = 0;
106107
JMEM_HEAP_STAT_INIT ();
107108
} /* jmem_heap_init */
108109

tests/jerry/gc-hashmap.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
var a = [ ];
16+
for (var v = 0; v < 256; v++)
17+
{
18+
var n = Object.create(null);
19+
a.push(n, a);
20+
n = new WeakSet(a);
21+
n.o = 1;
22+
}

0 commit comments

Comments
 (0)