Skip to content

Commit 7cc1371

Browse files
Mandy Chunglfoltandholmes-orahseigelsspitsyn
committed
8238358: Implementation of JEP 371: Hidden Classes
Co-authored-by: Lois Foltan <lois.foltan@oracle.com> Co-authored-by: David Holmes <david.holmes@oracle.com> Co-authored-by: Harold Seigel <harold.seigel@oracle.com> Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com> Co-authored-by: Alex Buckley <alex.buckley@oracle.com> Co-authored-by: Jamsheed Mohammed C M <jamsheed.c.m@oracle.com> Co-authored-by: Jan Lahoda <jan.lahoda@oracle.com> Co-authored-by: Amy Lu <amy.lu@oracle.com> Reviewed-by: alanb, cjplummer, coleenp, dholmes, dlong, forax, jlahoda, psandoz, plevart, sspitsyn, vromero
1 parent 642041a commit 7cc1371

198 files changed

Lines changed: 9523 additions & 1572 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

make/data/jdwp/jdwp.spec

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ JDWP "Java(tm) Debug Wire Protocol"
7070
)
7171
(Command AllClasses=3
7272
"Returns reference types for all classes currently loaded by the "
73-
"target VM."
73+
"target VM. "
74+
"See <a href=\"../jvmti.html#GetLoadedClasses\">JVM TI GetLoadedClasses</a>."
7475
(Out
7576
)
7677
(Reply
@@ -600,14 +601,9 @@ JDWP "Java(tm) Debug Wire Protocol"
600601

601602
(CommandSet ReferenceType=2
602603
(Command Signature=1
603-
"Returns the JNI signature of a reference type. "
604-
"JNI signature formats are described in the "
605-
"<a href=\"../jni/index.html\">Java Native Interface Specification</a>"
606-
"<p>
607-
"For primitive classes "
608-
"the returned signature is the signature of the corresponding primitive "
609-
"type; for example, \"I\" is returned as the signature of the class "
610-
"represented by java.lang.Integer.TYPE."
604+
"Returns the type signature of a reference type. "
605+
"Type signature formats are the same as specified in "
606+
"<a href=\"../jvmti.html#GetClassSignature\">JVM TI GetClassSignature</a>."
611607
(Out
612608
(referenceType refType "The reference type ID.")
613609
)
@@ -2266,11 +2262,12 @@ JDWP "Java(tm) Debug Wire Protocol"
22662262
)
22672263
(CommandSet ClassLoaderReference=14
22682264
(Command VisibleClasses=1
2269-
"Returns a list of all classes which this class loader has "
2270-
"been requested to load. This class loader is considered to be "
2271-
"an <i>initiating</i> class loader for each class in the returned "
2272-
"list. The list contains each "
2273-
"reference type defined by this loader and any types for which "
2265+
"Returns a list of all classes which this class loader can find "
2266+
"by name via <code>ClassLoader::loadClass</code>, "
2267+
"<code>Class::forName</code> and bytecode linkage. That is, "
2268+
"all classes for which this class loader has been recorded as an "
2269+
"<i>initiating</i> loader. The list contains each "
2270+
"reference type created by this loader and any types for which "
22742271
"loading was delegated by this class loader to another class loader. "
22752272
"<p>"
22762273
"The visible class list has useful properties with respect to "
@@ -2280,6 +2277,8 @@ JDWP "Java(tm) Debug Wire Protocol"
22802277
"this class loader must be resolved to that single type. "
22812278
"<p>"
22822279
"No ordering of the returned list is guaranteed. "
2280+
"<p>"
2281+
"See <a href=\"../jvmti.html#GetClassLoaderClasses\">JVM TI GetClassLoaderClasses</a>. "
22832282
(Out
22842283
(classLoaderObject classLoaderObject "The class loader object ID. ")
22852284
)

make/hotspot/symbols/symbols-unix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ JVM_Interrupt
142142
JVM_InvokeMethod
143143
JVM_IsArrayClass
144144
JVM_IsConstructorIx
145+
JVM_IsHiddenClass
145146
JVM_IsInterface
146147
JVM_IsPrimitiveClass
147148
JVM_IsRecord
@@ -151,6 +152,7 @@ JVM_IsThreadAlive
151152
JVM_IsVMGeneratedMethodIx
152153
JVM_LatestUserDefinedLoader
153154
JVM_LoadLibrary
155+
JVM_LookupDefineClass
154156
JVM_MaxMemory
155157
JVM_MaxObjectInspectionAge
156158
JVM_MonitorNotify

src/hotspot/share/aot/aotCodeHeap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ bool AOTCodeHeap::reconcile_dynamic_klass(AOTCompiledMethod *caller, InstanceKla
10491049

10501050
InstanceKlass* dyno = InstanceKlass::cast(dyno_klass);
10511051

1052-
if (!dyno->is_unsafe_anonymous()) {
1052+
if (!dyno->is_hidden() && !dyno->is_unsafe_anonymous()) {
10531053
if (_klasses_got[dyno_data->_got_index] != dyno) {
10541054
// compile-time class different from runtime class, fail and deoptimize
10551055
sweep_dependent_methods(holder_data);

src/hotspot/share/aot/aotLoader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ GrowableArray<AOTLib*>* AOTLoader::_libraries = new(ResourceObj::C_HEAP, mtCode)
4343
#define FOR_ALL_AOT_LIBRARIES(lib) for (GrowableArrayIterator<AOTLib*> lib = libraries()->begin(); lib != libraries()->end(); ++lib)
4444

4545
void AOTLoader::load_for_klass(InstanceKlass* ik, Thread* thread) {
46-
if (ik->is_unsafe_anonymous()) {
46+
if (ik->is_hidden() || ik->is_unsafe_anonymous()) {
4747
// don't even bother
4848
return;
4949
}
@@ -58,7 +58,7 @@ void AOTLoader::load_for_klass(InstanceKlass* ik, Thread* thread) {
5858

5959
uint64_t AOTLoader::get_saved_fingerprint(InstanceKlass* ik) {
6060
assert(UseAOT, "called only when AOT is enabled");
61-
if (ik->is_unsafe_anonymous()) {
61+
if (ik->is_hidden() || ik->is_unsafe_anonymous()) {
6262
// don't even bother
6363
return 0;
6464
}

src/hotspot/share/ci/ciField.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,10 @@ static bool trust_final_non_static_fields(ciInstanceKlass* holder) {
223223
holder->is_in_package("jdk/internal/foreign") || holder->is_in_package("jdk/incubator/foreign") ||
224224
holder->is_in_package("java/lang"))
225225
return true;
226-
// Trust VM unsafe anonymous classes. They are private API (jdk.internal.misc.Unsafe)
227-
// and can't be serialized, so there is no hacking of finals going on with them.
228-
if (holder->is_unsafe_anonymous())
226+
// Trust hidden classes and VM unsafe anonymous classes. They are created via
227+
// Lookup.defineHiddenClass or the private jdk.internal.misc.Unsafe API and
228+
// can't be serialized, so there is no hacking of finals going on with them.
229+
if (holder->is_hidden() || holder->is_unsafe_anonymous())
229230
return true;
230231
// Trust final fields in all boxed classes
231232
if (holder->is_box_klass())

src/hotspot/share/ci/ciInstanceKlass.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ ciInstanceKlass::ciInstanceKlass(Klass* k) :
6363
_has_nonstatic_fields = ik->has_nonstatic_fields();
6464
_has_nonstatic_concrete_methods = ik->has_nonstatic_concrete_methods();
6565
_is_unsafe_anonymous = ik->is_unsafe_anonymous();
66+
_is_hidden = ik->is_hidden();
6667
_nonstatic_fields = NULL; // initialized lazily by compute_nonstatic_fields:
6768
_has_injected_fields = -1;
6869
_implementor = NULL; // we will fill these lazily
@@ -73,13 +74,13 @@ ciInstanceKlass::ciInstanceKlass(Klass* k) :
7374
// InstanceKlass are created for both weak and strong metadata. Ensuring this metadata
7475
// alive covers the cases where there are weak roots without performance cost.
7576
oop holder = ik->klass_holder();
76-
if (ik->is_unsafe_anonymous()) {
77+
if (ik->class_loader_data()->has_class_mirror_holder()) {
7778
// Though ciInstanceKlass records class loader oop, it's not enough to keep
78-
// VM unsafe anonymous classes alive (loader == NULL). Klass holder should
79+
// non-strong hidden classes and VM unsafe anonymous classes alive (loader == NULL). Klass holder should
7980
// be used instead. It is enough to record a ciObject, since cached elements are never removed
8081
// during ciObjectFactory lifetime. ciObjectFactory itself is created for
8182
// every compilation and lives for the whole duration of the compilation.
82-
assert(holder != NULL, "holder of unsafe anonymous class is the mirror which is never null");
83+
assert(holder != NULL, "holder of hidden or unsafe anonymous class is the mirror which is never null");
8384
(void)CURRENT_ENV->get_object(holder);
8485
}
8586

@@ -123,6 +124,7 @@ ciInstanceKlass::ciInstanceKlass(ciSymbol* name,
123124
_nonstatic_fields = NULL;
124125
_has_injected_fields = -1;
125126
_is_unsafe_anonymous = false;
127+
_is_hidden = false;
126128
_loader = loader;
127129
_protection_domain = protection_domain;
128130
_is_shared = false;

src/hotspot/share/ci/ciInstanceKlass.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class ciInstanceKlass : public ciKlass {
5656
bool _has_nonstatic_fields;
5757
bool _has_nonstatic_concrete_methods;
5858
bool _is_unsafe_anonymous;
59+
bool _is_hidden;
5960

6061
ciFlags _flags;
6162
jint _nonstatic_field_size;
@@ -191,10 +192,14 @@ class ciInstanceKlass : public ciKlass {
191192
return _has_nonstatic_concrete_methods;
192193
}
193194

194-
bool is_unsafe_anonymous() {
195+
bool is_unsafe_anonymous() const {
195196
return _is_unsafe_anonymous;
196197
}
197198

199+
bool is_hidden() const {
200+
return _is_hidden;
201+
}
202+
198203
ciInstanceKlass* get_canonical_holder(int offset);
199204
ciField* get_field_by_offset(int field_offset, bool is_static);
200205
ciField* get_field_by_name(ciSymbol* name, ciSymbol* signature, bool is_static);

0 commit comments

Comments
 (0)