Skip to content

Commit

Permalink
Merge pull request #54 from openwebf/feat/proto-ic
Browse files Browse the repository at this point in the history
Feat/proto ic
  • Loading branch information
ErosZy authored Jan 4, 2024
2 parents 3c5ba26 + 6f54e7e commit 32acbde
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[submodule "vendor/mimalloc"]
path = vendor/mimalloc
url = https://github.com/microsoft/mimalloc
branch = v1.7.9
branch = v1.8.2
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ add_subdirectory(vendor/mimalloc)

set(COMPILE_FLAGS -Wall -MMD -Wno-array-bounds -Wno-format-truncation)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(COMPILE_FLAGS ${COMPILE_FLAGS} -g)
set(MI_ASAN ON)
set(COMPILE_FLAGS ${COMPILE_FLAGS} -g -fsanitize=address)
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
set(COMPILE_FLAGS ${COMPILE_FLAGS} -O3)
endif()
Expand Down
4 changes: 2 additions & 2 deletions src/core/bytecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ static int JS_WriteFunctionTag(BCWriterState* s, JSValueConst obj) {
dbuf_putc(&s->dbuf, 255);
dbuf_putc(&s->dbuf, 73); // 'I'
dbuf_putc(&s->dbuf, 67); // 'C'
if (b->ic == NULL) {
if (b->ic == NULL) {
bc_put_leb128(s, 0);
} else {
bc_put_leb128(s, b->ic->count);
Expand Down Expand Up @@ -1607,7 +1607,7 @@ static JSValue JS_ReadFunctionTag(BCReaderState* s) {
}

/** special column number check logic for V1(.kbc1 file) bytecode format. */
if (s->buf_end - s->ptr > 4 && s->ptr[0] == 255 && s->ptr[1] == 67 && s->ptr[2] == 79 && s->ptr[3] == 76) {
if (s->buf_end - s->ptr > 4 && s->ptr[0] == 255 && s->ptr[1] == 67 && s->ptr[2] == 79 && s->ptr[3] == 76) {
s->ptr += 4;
if (bc_get_leb128_int(s, &b->debug.column_num)) {
goto fail;
Expand Down
6 changes: 4 additions & 2 deletions src/core/ic.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,13 @@ force_inline uint32_t add_ic_slot(InlineCache *ic, JSAtom atom, JSObject *object
}

i = (i + 1) % IC_CACHE_ITEM_CAPACITY;
if (unlikely(i == cr->index))
if (unlikely(i == cr->index)) {
cr->index = (cr->index + 1) % IC_CACHE_ITEM_CAPACITY;
break;
}
}

ci = cr->buffer + i;
ci = cr->buffer + cr->index;
sh = ci->shape;
if (ci->watchpoint_ref)
// must be called before js_free_shape_null
Expand Down
2 changes: 1 addition & 1 deletion src/core/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ JSValue JS_GetPropertyInternal(JSContext *ctx, JSValueConst obj,
}
} else {
// basic poly ic is only used for fast path
if (ic && p->shape->is_hashed) {
if (ic && p1->shape->is_hashed && p->shape->is_hashed) {
ic->updated = TRUE;
ic->updated_offset = add_ic_slot(ic, prop, p1, offset, proto_depth > 0 ? p : NULL);
}
Expand Down
4 changes: 4 additions & 0 deletions src/core/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -7555,6 +7555,10 @@ static void js_free_function_def(JSContext *ctx, JSFunctionDef *fd)

free_bytecode_atoms(ctx->rt, fd->byte_code.buf, fd->byte_code.size,
fd->use_short_opcodes);
if (fd->ic) {
rebuild_ic(fd->ic);
free_ic(fd->ic);
}
dbuf_free(&fd->byte_code);
js_free(ctx, fd->jump_slots);
js_free(ctx, fd->label_slots);
Expand Down

0 comments on commit 32acbde

Please sign in to comment.