Skip to content
Permalink
Browse files
8241894: [lworld] crash in ZGC running InlineOops.java#id3
Reviewed-by: fparain
  • Loading branch information
David Simms committed Feb 9, 2021
1 parent 3d47537 commit 84c3e324726fc08dfad4d2bc214e7943b60133d0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 31 deletions.
@@ -1814,7 +1814,7 @@ WB_ENTRY(jobjectArray, WB_getObjectsViaKlassOopMaps(JNIEnv* env, jobject wb, job
return NULL;
}
instanceHandle ih(THREAD, (instanceOop) aoop);
InstanceKlass* klass = InstanceKlass::cast(aoop->klass());
InstanceKlass* klass = InstanceKlass::cast(ih->klass());
if (klass->nonstatic_oop_map_count() == 0) {
return NULL;
}
@@ -1826,61 +1826,56 @@ WB_ENTRY(jobjectArray, WB_getObjectsViaKlassOopMaps(JNIEnv* env, jobject wb, job
map++;
}

objArrayOop result_array =
oopFactory::new_objArray(vmClasses::Object_klass(), oop_count, CHECK_NULL);
objArrayHandle result_array =
oopFactory::new_objArray_handle(vmClasses::Object_klass(), oop_count, CHECK_NULL);
map = klass->start_of_nonstatic_oop_maps();
instanceOop ioop = ih();
int index = 0;
while (map < end) {
int offset = map->offset();
for (unsigned int j = 0; j < map->count(); j++) {
result_array->obj_at_put(index++, ioop->obj_field(offset));
result_array->obj_at_put(index++, ih->obj_field(offset));
offset += heapOopSize;
}
map++;
}
return (jobjectArray)JNIHandles::make_local(THREAD, result_array);
return (jobjectArray)JNIHandles::make_local(THREAD, result_array());
WB_END

class CollectOops : public BasicOopIterateClosure {
public:
GrowableArray<Handle>* array;

objArrayOop create_results(TRAPS) {
objArrayOop result_array =
oopFactory::new_objArray(vmClasses::Object_klass(), array->length(), CHECK_NULL);
jobjectArray create_jni_result(JNIEnv* env, TRAPS) {
objArrayHandle result_array =
oopFactory::new_objArray_handle(vmClasses::Object_klass(), array->length(), CHECK_NULL);
for (int i = 0 ; i < array->length(); i++) {
result_array->obj_at_put(i, array->at(i)());
}
return result_array;
}

jobjectArray create_jni_result(JNIEnv* env, TRAPS) {
return (jobjectArray)JNIHandles::make_local(THREAD, create_results(THREAD));
return (jobjectArray)JNIHandles::make_local(THREAD, result_array());
}

void add_oop(oop o) {
Handle oh = Handle(Thread::current(), o);
// Value might be oop, but JLS can't see as Object, just iterate through it...
if (o != NULL && o->is_inline_type()) {
o->oop_iterate(this);
if (oh != NULL && oh->is_inline_type()) {
oh->oop_iterate(this);
} else {
array->append(Handle(Thread::current(), o));
array->append(oh);
}
}

void do_oop(oop* o) { add_oop(*o); }
void do_oop(narrowOop* v) { add_oop(CompressedOops::decode(*v)); }
void do_oop(oop* o) { add_oop(HeapAccess<>::oop_load(o)); }
void do_oop(narrowOop* v) { add_oop(HeapAccess<>::oop_load(v)); }
};


WB_ENTRY(jobjectArray, WB_getObjectsViaOopIterator(JNIEnv* env, jobject wb, jobject thing))
ResourceMark rm(THREAD);
ResourceMark rm(thread);
Handle objh(thread, JNIHandles::resolve(thing));
GrowableArray<Handle>* array = new GrowableArray<Handle>(128);
CollectOops collectOops;
collectOops.array = array;

JNIHandles::resolve(thing)->oop_iterate(&collectOops);

objh->oop_iterate(&collectOops);
return collectOops.create_jni_result(env, THREAD);
WB_END

@@ -298,14 +298,14 @@ public static void testOopMaps() {

// Sanity check, FixMe need more test cases
objects = testFrameOops(couple);
//assertTrue(objects.length == 5, "Number of frame oops incorrect = " + objects.length);
//assertTrue(objects[0] == couple, "Bad oop 0");
//assertTrue(objects[1] == fn1, "Bad oop 1");
//assertTrue(objects[2] == ln1, "Bad oop 2");
//assertTrue(objects[3] == TEST_STRING1, "Bad oop 3");
//assertTrue(objects[4] == TEST_STRING2, "Bad oop 4");

//testFrameOopsVBytecodes();
assertTrue(objects.length == 5, "Number of frame oops incorrect = " + objects.length);
assertTrue(objects[0] == couple, "Bad oop 0");
assertTrue(objects[1] == fn1, "Bad oop 1");
assertTrue(objects[2] == ln1, "Bad oop 2");
assertTrue(objects[3] == TEST_STRING1, "Bad oop 3");
assertTrue(objects[4] == TEST_STRING2, "Bad oop 4");

testFrameOopsVBytecodes();
}

static final String GET_OOP_MAP_NAME = "getOopMap";

0 comments on commit 84c3e32

Please sign in to comment.