Skip to content

Commit 330ce86

Browse files
author
Harold Seigel
committedDec 16, 2020
8257700: Add logging for sealed classes in JVM_GetPermittedSubclasses
Reviewed-by: lfoltan, coleenp, dholmes
1 parent c463264 commit 330ce86

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed
 

‎src/hotspot/share/prims/jvm.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -1851,7 +1851,6 @@ JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass,
18511851
}
18521852
JVM_END
18531853

1854-
18551854
// A class is a record if and only if it is final and a direct subclass of
18561855
// java.lang.Record and has a Record attribute; otherwise, it is not a record.
18571856
JVM_ENTRY(jboolean, JVM_IsRecord(JNIEnv *env, jclass cls))
@@ -2127,10 +2126,16 @@ JVM_ENTRY(jobjectArray, JVM_GetPermittedSubclasses(JNIEnv* env, jclass current))
21272126
Klass* c = java_lang_Class::as_Klass(mirror);
21282127
assert(c->is_instance_klass(), "must be");
21292128
InstanceKlass* ik = InstanceKlass::cast(c);
2129+
ResourceMark rm(THREAD);
2130+
log_trace(class, sealed)("Calling GetPermittedSubclasses for %s type %s",
2131+
ik->is_sealed() ? "sealed" : "non-sealed", ik->external_name());
21302132
if (ik->is_sealed()) {
21312133
JvmtiVMObjectAllocEventCollector oam;
21322134
Array<u2>* subclasses = ik->permitted_subclasses();
21332135
int length = subclasses->length();
2136+
2137+
log_trace(class, sealed)(" - sealed class has %d permitted subclasses", length);
2138+
21342139
objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(),
21352140
length, CHECK_NULL);
21362141
objArrayHandle result(THREAD, r);
@@ -2142,14 +2147,24 @@ JVM_ENTRY(jobjectArray, JVM_GetPermittedSubclasses(JNIEnv* env, jclass current))
21422147
if (PENDING_EXCEPTION->is_a(SystemDictionary::VirtualMachineError_klass())) {
21432148
return NULL; // propagate VMEs
21442149
}
2150+
if (log_is_enabled(Trace, class, sealed)) {
2151+
stringStream ss;
2152+
char* permitted_subclass = ik->constants()->klass_name_at(cp_index)->as_C_string();
2153+
ss.print(" - resolution of permitted subclass %s failed: ", permitted_subclass);
2154+
java_lang_Throwable::print(PENDING_EXCEPTION, &ss);
2155+
log_trace(class, sealed)("%s", ss.as_string());
2156+
}
2157+
21452158
CLEAR_PENDING_EXCEPTION;
21462159
continue;
21472160
}
21482161
if (k->is_instance_klass()) {
21492162
result->obj_at_put(count++, k->java_mirror());
2163+
log_trace(class, sealed)(" - [%d] = %s", count, k->external_name());
21502164
}
21512165
}
21522166
if (count < length) {
2167+
// we had invalid entries so we need to compact the array
21532168
objArrayOop r2 = oopFactory::new_objArray(SystemDictionary::Class_klass(),
21542169
count, CHECK_NULL);
21552170
objArrayHandle result2(THREAD, r2);

0 commit comments

Comments
 (0)
Please sign in to comment.