Skip to content

Commit a933faa

Browse files
committed
Add functions in the GC interface to get object hash
1 parent 31cea77 commit a933faa

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

src/builtins.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -344,13 +344,10 @@ static uintptr_t type_object_id_(jl_value_t *v, jl_varidx_t *env) JL_NOTSAFEPOIN
344344
i++;
345345
pe = pe->prev;
346346
}
347-
// FIXME: Pinning objects that get hashed
348-
// until we implement address space hashing.
349-
OBJ_PIN(v);
350347
uintptr_t bits = jl_astaggedvalue(v)->header;
351348
if (bits & GC_IN_IMAGE)
352349
return ((uintptr_t*)v)[-2];
353-
return inthash((uintptr_t)v);
350+
return inthash(jl_gc_get_obj_hash(v));
354351
}
355352
if (tv == jl_uniontype_type) {
356353
return bitmix(bitmix(jl_object_id((jl_value_t*)tv),
@@ -403,12 +400,7 @@ static uintptr_t immut_id_(jl_datatype_t *dt, jl_value_t *v, uintptr_t h) JL_NOT
403400
// a few select pointers (notably symbol) also have special hash values
404401
// which may affect the stability of the objectid hash, even though
405402
// they don't affect egal comparison
406-
407-
// FIXME: Pinning objects that get hashed
408-
// until we implement address space hashing.
409-
PTR_PIN(v); // This has to be a pointer pin -- v could be an internal pointer
410-
411-
return bits_hash(v, sz) ^ h;
403+
return bits_hash((const void*)jl_gc_get_ptr_hash(v), sz) ^ h;
412404
}
413405
if (dt == jl_unionall_type)
414406
return type_object_id_(v, NULL);
@@ -469,10 +461,7 @@ static uintptr_t NOINLINE jl_object_id__cold(uintptr_t tv, jl_value_t *v) JL_NOT
469461
if (bits & GC_IN_IMAGE)
470462
return ((uintptr_t*)v)[-2];
471463

472-
// FIXME: Pinning objects that get hashed
473-
// until we implement address space hashing.
474-
OBJ_PIN(v);
475-
return inthash((uintptr_t)v);
464+
return inthash(jl_gc_get_obj_hash(v));
476465
}
477466
return immut_id_(dt, v, dt->hash);
478467
}

src/gc-interface.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ JL_DLLEXPORT void jl_gc_preserve_begin_hook(int n, ...) JL_NOTSAFEPOINT;
123123
// Runtime hook for gc preserve end. The GC needs to make sure that the preserved objects and its children stay alive and won't move.
124124
JL_DLLEXPORT void jl_gc_preserve_end_hook(void) JL_NOTSAFEPOINT;
125125

126+
JL_DLLEXPORT uintptr_t jl_gc_get_obj_hash(void* obj) JL_NOTSAFEPOINT;
127+
JL_DLLEXPORT uintptr_t jl_gc_get_ptr_hash(void* ptr) JL_NOTSAFEPOINT;
128+
126129
// ========================================================================= //
127130
// Metrics
128131
// ========================================================================= //

src/gc-mmtk.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,6 +1623,14 @@ JL_DLLEXPORT void jl_gc_preserve_end_hook(void) JL_NOTSAFEPOINT
16231623
JL_GC_POP_PRESERVE_ROOT_OBJS();
16241624
}
16251625

1626+
JL_DLLEXPORT uintptr_t jl_gc_get_obj_hash(void* obj) JL_NOTSAFEPOINT {
1627+
return mmtk_get_object_hash(obj);
1628+
}
1629+
1630+
JL_DLLEXPORT uintptr_t jl_gc_get_ptr_hash(void* ptr) JL_NOTSAFEPOINT {
1631+
return mmtk_get_ptr_hash(ptr);
1632+
}
1633+
16261634
#ifdef __cplusplus
16271635
}
16281636
#endif

src/gc-stock.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4127,6 +4127,14 @@ JL_DLLEXPORT void jl_gc_notify_thread_yield(jl_ptls_t ptls, void* ctx) {
41274127
// Do nothing before a thread yields
41284128
}
41294129

4130+
JL_DLLEXPORT uintptr_t jl_gc_get_obj_hash(void* obj) JL_NOTSAFEPOINT {
4131+
return (uintptr_t)obj;
4132+
}
4133+
4134+
JL_DLLEXPORT uintptr_t jl_gc_get_ptr_hash(void* ptr) JL_NOTSAFEPOINT {
4135+
return (uintptr_t)ptr;
4136+
}
4137+
41304138
#ifdef __cplusplus
41314139
}
41324140
#endif

0 commit comments

Comments
 (0)