Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into beta/0.14.4
Browse files Browse the repository at this point in the history
  • Loading branch information
andycall committed Jan 8, 2024
2 parents b6a9ce2 + 7b8d54d commit 7119463
Show file tree
Hide file tree
Showing 17 changed files with 294 additions and 47 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ This ensures that users can reliably receive updates for three minor WebF versio
| `>= 0.12.0 < 0.14.0` | `3.0.5` |
| `>= 0.14.0 < 0.15.0` | `3.3.10` and `3.7.3` |
| `>= 0.15.0 < 0.16.0` | `3.10.x` |
| `>= 0.16.0 < 0.17.0` | `3.13.x` |
| `>= 0.17.0 < 0.18.0` | `3.16.x` |
| `>= 0.16.0 < 0.17.0` | `3.13.x` and `3.16.x` |


<img width="817" alt="image" src="https://github.com/openwebf/webf/assets/4409743/2d5cf5a1-e670-424b-8766-324f475bbc0a">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ DEF( typeof_is_function, 1, 1, 1, none)
DEF( get_field_ic, 5, 1, 1, none)
DEF( get_field2_ic, 5, 1, 2, none)
DEF( put_field_ic, 5, 2, 0, none)
DEF( debugger, 1, 0, 0, none)

#undef DEF
#undef def
Expand Down
6 changes: 3 additions & 3 deletions bridge/third_party/quickjs/src/core/bytecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,9 @@ static int JS_WriteFunctionTag(BCWriterState* s, JSValueConst obj) {
bc_put_leb128(s, b->debug.line_num);
bc_put_leb128(s, b->debug.pc2line_len);
dbuf_put(&s->dbuf, b->debug.pc2line_buf, b->debug.pc2line_len);
/**
/**
* purely for compatibility with WebF/Kraken V1 quickjs compiler (kbc1 file format).
* determination of whether a column number is available by
* determination of whether a column number is available by
* adding a special sequence of characters.
*/
dbuf_putc(&s->dbuf, 255);
Expand Down Expand Up @@ -2173,4 +2173,4 @@ JSValue JS_ReadObject(JSContext* ctx, const uint8_t* buf, size_t buf_len, int fl
}
bc_reader_free(s);
return obj;
}
}
5 changes: 4 additions & 1 deletion bridge/third_party/quickjs/src/core/function.c
Original file line number Diff line number Diff line change
Expand Up @@ -1520,7 +1520,7 @@ JSValue JS_CallInternal(JSContext* caller_ctx,
atom = get_u32(pc);
pc += 4;

val = JS_GetPropertyInternal(ctx, sp[-1], atom, sp[-1], NULL, FALSE);
val = JS_GetPropertyInternal(ctx, sp[-1], atom, sp[-1], ic, FALSE);
if (unlikely(JS_IsException(val)))
goto exception;
if (ic != NULL && ic->updated == TRUE) {
Expand Down Expand Up @@ -1588,6 +1588,9 @@ JSValue JS_CallInternal(JSContext* caller_ctx,
}
BREAK;

CASE(OP_debugger):
BREAK;

CASE(OP_private_symbol) : {
JSAtom atom;
JSValue val;
Expand Down
5 changes: 4 additions & 1 deletion bridge/third_party/quickjs/src/core/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,9 +645,12 @@ void mark_children(JSRuntime* rt, JSGCObjectHeader* gp, JS_MarkFunc* mark_func)
if (b->ic) {
for (i = 0; i < b->ic->count; i++) {
buffer = b->ic->cache[i].buffer;
for (j = 0; j < IC_CACHE_ITEM_CAPACITY; j++)
for (j = 0; j < IC_CACHE_ITEM_CAPACITY; j++) {
if (buffer[j].shape)
mark_func(rt, &buffer[j].shape->header);
if (buffer[j].proto)
mark_func(rt, &buffer[j].proto->header);
}
}
}
}
Expand Down
150 changes: 140 additions & 10 deletions bridge/third_party/quickjs/src/core/ic.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,25 @@ int resize_ic_hash(InlineCache *ic) {

int free_ic(InlineCache *ic) {
uint32_t i, j;
JSRuntime *rt;
JSShape *sh;
InlineCacheHashSlot *ch, *ch_next;
InlineCacheRingItem *buffer;
ICWatchpoint *o;
rt = ic->ctx->rt;
for (i = 0; i < ic->count; i++) {
buffer = ic->cache[i].buffer;
JS_FreeAtom(ic->ctx, ic->cache[i].atom);
for (j = 0; j < IC_CACHE_ITEM_CAPACITY; j++) {
js_free_shape_null(ic->ctx->rt, buffer[j].shape);
sh = buffer[j].shape;
o = buffer[j].watchpoint_ref;
if (o) {
if (o->free_callback)
o->free_callback(rt, o->ref, o->atom);
list_del(&o->link);
js_free_rt(rt, o);
}
js_free_shape_null(rt, sh);
}
}
for (i = 0; i < ic->capacity; i++) {
Expand All @@ -124,14 +136,26 @@ int free_ic(InlineCache *ic) {
return 0;
}

#if _MSC_VER
uint32_t add_ic_slot(InlineCache *ic, JSAtom atom, JSObject *object,
uint32_t prop_offset) {
uint32_t prop_offset, JSObject* prototype)
#else
force_inline uint32_t add_ic_slot(InlineCache *ic, JSAtom atom, JSObject *object,
uint32_t prop_offset, JSObject* prototype)
#endif
{
int32_t i;
uint32_t h;
InlineCacheHashSlot *ch;
InlineCacheRingSlot *cr;
InlineCacheRingItem *ci;
JSRuntime* rt;
JSShape *sh;
JSObject *proto;
cr = NULL;
rt = ic->ctx->rt;
sh = NULL;
proto = NULL;
h = get_index_hash(atom, ic->hash_bits);
for (ch = ic->hash[h]; ch != NULL; ch = ch->next)
if (ch->atom == atom) {
Expand All @@ -142,25 +166,46 @@ uint32_t add_ic_slot(InlineCache *ic, JSAtom atom, JSObject *object,
assert(cr != NULL);
i = cr->index;
for (;;) {
if (object->shape == cr->buffer[i].shape) {
cr->buffer[i].prop_offset = prop_offset;
ci = cr->buffer + i;
if (object->shape == ci->shape && prototype == ci->proto) {
ci->prop_offset = prop_offset;
goto end;
}

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;
}
}

sh = cr->buffer[i].shape;
cr->buffer[i].shape = js_dup_shape(object->shape);
js_free_shape_null(ic->ctx->rt, sh);
cr->buffer[i].prop_offset = prop_offset;
ci = cr->buffer + cr->index;
sh = ci->shape;
if (ci->watchpoint_ref)
// must be called before js_free_shape_null
js_shape_delete_watchpoints(rt, sh, ci);
ci->prop_offset = prop_offset;
ci->shape = js_dup_shape(object->shape);
js_free_shape_null(rt, sh);
if (prototype) {
// the atom and prototype SHOULE BE freed by watchpoint_remove/clear_callback
JS_DupValue(ic->ctx, JS_MKPTR(JS_TAG_OBJECT, prototype));
ci->proto = prototype;
ci->watchpoint_ref = js_shape_create_watchpoint(rt, ci->shape, (intptr_t)ci,
JS_DupAtom(ic->ctx, atom),
ic_watchpoint_delete_handler,
ic_watchpoint_free_handler);
}
end:
return ch->index;
}

uint32_t add_ic_slot1(InlineCache *ic, JSAtom atom) {
#if _MSC_VER
uint32_t add_ic_slot1(InlineCache *ic, JSAtom atom)
#else
force_inline uint32_t add_ic_slot1(InlineCache *ic, JSAtom atom)
#endif
{
uint32_t h;
InlineCacheHashSlot *ch;
if (ic->count + 1 >= ic->capacity && resize_ic_hash(ic))
Expand All @@ -179,4 +224,89 @@ uint32_t add_ic_slot1(InlineCache *ic, JSAtom atom) {
ic->count += 1;
end:
return 0;
}

int ic_watchpoint_delete_handler(JSRuntime* rt, intptr_t ref, JSAtom atom, void* target) {
InlineCacheRingItem *ci;
ci = (InlineCacheRingItem *)ref;
if(ref != (intptr_t)target)
return 1;
assert(ci->proto != NULL);
// the shape and prop_offset WILL BE handled by add_ic_slot
// !!! MUST NOT CALL js_free_shape0 TO DOUBLE FREE HERE !!!
JS_FreeValueRT(rt, JS_MKPTR(JS_TAG_OBJECT, ci->proto));
JS_FreeAtomRT(rt, atom);
ci->watchpoint_ref = NULL;
ci->proto = NULL;
ci->prop_offset = 0;
ci->shape = NULL;
return 0;
}

int ic_watchpoint_free_handler(JSRuntime* rt, intptr_t ref, JSAtom atom) {
InlineCacheRingItem *ci;
ci = (InlineCacheRingItem *)ref;
assert(ci->watchpoint_ref != NULL);
assert(ci->proto != NULL);
// the watchpoint_clear_callback ONLY CAN BE called by js_free_shape0
// !!! MUST NOT CALL js_free_shape0 TO DOUBLE FREE HERE !!!
JS_FreeValueRT(rt, JS_MKPTR(JS_TAG_OBJECT, ci->proto));
JS_FreeAtomRT(rt, atom);
ci->watchpoint_ref = NULL;
ci->proto = NULL;
ci->prop_offset = 0;
ci->shape = NULL;
return 0;
}

int ic_delete_shape_proto_watchpoints(JSRuntime *rt, JSShape *shape, JSAtom atom) {
struct list_head *el, *el1;
JSObject *p;
JSAtom *prop;
InlineCacheRingItem *ci;
JSShape *sh;
p = shape->proto;
while(likely(p)) {
if (p->shape->watchpoint)
list_for_each_safe(el, el1, p->shape->watchpoint) {
ICWatchpoint *o = list_entry(el, ICWatchpoint, link);
if (o->atom == atom) {
ci = (InlineCacheRingItem *)o->ref;
sh = ci->shape;
o->delete_callback = NULL;
o->free_callback = NULL;
ic_watchpoint_free_handler(rt, o->ref, o->atom);
js_free_shape_null(rt, shape);
list_del(el);
js_free_rt(rt, o);
}
}
p = p->shape->proto;
}
return 0;
}

int ic_free_shape_proto_watchpoints(JSRuntime *rt, JSShape *shape) {
struct list_head *el, *el1;
JSObject *p;
JSAtom *prop;
InlineCacheRingItem *ci;
JSShape *sh;
p = shape->proto;
while(likely(p)) {
if (p->shape->watchpoint)
list_for_each_safe(el, el1, p->shape->watchpoint) {
ICWatchpoint *o = list_entry(el, ICWatchpoint, link);
ci = (InlineCacheRingItem *)o->ref;
sh = ci->shape;
o->delete_callback = NULL;
o->free_callback = NULL;
ic_watchpoint_free_handler(rt, o->ref, o->atom);
js_free_shape_null(rt, shape);
list_del(el);
js_free_rt(rt, o);
}
p = p->shape->proto;
}
return 0;
}
11 changes: 9 additions & 2 deletions bridge/third_party/quickjs/src/core/ic.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ int rebuild_ic(InlineCache *ic);
int resize_ic_hash(InlineCache *ic);
int free_ic(InlineCache *ic);
uint32_t add_ic_slot(InlineCache *ic, JSAtom atom, JSObject *object,
uint32_t prop_offset);
uint32_t prop_offset, JSObject* prototype);
uint32_t add_ic_slot1(InlineCache *ic, JSAtom atom);
force_inline int32_t get_ic_prop_offset(InlineCache *ic, uint32_t cache_offset,
JSShape *shape) {
JSShape *shape, JSObject **prototype) {
uint32_t i;
InlineCacheRingSlot *cr;
InlineCacheRingItem *buffer;
Expand All @@ -49,6 +49,7 @@ force_inline int32_t get_ic_prop_offset(InlineCache *ic, uint32_t cache_offset,
buffer = cr->buffer + i;
if (likely(buffer->shape == shape)) {
cr->index = i;
*prototype = buffer->proto;
return buffer->prop_offset;
}

Expand All @@ -58,11 +59,17 @@ force_inline int32_t get_ic_prop_offset(InlineCache *ic, uint32_t cache_offset,
}
}

*prototype = NULL;
return -1;
}

force_inline JSAtom get_ic_atom(InlineCache *ic, uint32_t cache_offset) {
assert(cache_offset < ic->capacity);
return ic->cache[cache_offset].atom;
}

int ic_watchpoint_delete_handler(JSRuntime* rt, intptr_t ref, JSAtom atom, void* target);
int ic_watchpoint_free_handler(JSRuntime* rt, intptr_t ref, JSAtom atom);
int ic_delete_shape_proto_watchpoints(JSRuntime *rt, JSShape *shape, JSAtom atom);
int ic_free_shape_proto_watchpoints(JSRuntime *rt, JSShape *shape);
#endif
Loading

0 comments on commit 7119463

Please sign in to comment.