--- old/src/hotspot/share/classfile/classFileParser.cpp 2018-10-31 15:59:30.294598156 -0400 +++ new/src/hotspot/share/classfile/classFileParser.cpp 2018-10-31 15:59:29.489927188 -0400 @@ -1083,7 +1083,7 @@ assert((int)_annotation_LIMIT <= (int)sizeof(_annotations_present) * BitsPerByte, ""); } // If this annotation name has an ID, report it (or _none). - ID annotation_index(const ClassLoaderData* loader_data, const Symbol* name); + ID annotation_index(const ClassLoaderData* loader_data, const Symbol* name, const bool can_access_vm_annotations); // Set the annotation name: void set_annotation(ID id) { assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob"); @@ -1216,6 +1216,7 @@ const u1* buffer, int limit, AnnotationCollector* coll, ClassLoaderData* loader_data, + const bool can_access_vm_annotations, TRAPS) { assert(cp != NULL, "invariant"); @@ -1261,7 +1262,7 @@ } // Here is where parsing particular annotations will take place. - AnnotationCollector::ID id = coll->annotation_index(loader_data, aname); + AnnotationCollector::ID id = coll->annotation_index(loader_data, aname, can_access_vm_annotations); if (AnnotationCollector::_unknown == id) continue; coll->set_annotation(id); @@ -1387,6 +1388,7 @@ runtime_visible_annotations_length, parsed_annotations, _loader_data, + _can_access_vm_annotations, CHECK); cfs->skip_u1_fast(runtime_visible_annotations_length); } else if (attribute_name == vmSymbols::tag_runtime_invisible_annotations()) { @@ -2086,12 +2088,14 @@ AnnotationCollector::ID AnnotationCollector::annotation_index(const ClassLoaderData* loader_data, - const Symbol* name) { + const Symbol* name, + const bool can_access_vm_annotations) { const vmSymbols::SID sid = vmSymbols::find_sid(name); // Privileged code can use all annotations. Other code silently drops some. const bool privileged = loader_data->is_the_null_class_loader_data() || loader_data->is_platform_class_loader_data() || - loader_data->is_shortlived(); + loader_data->is_shortlived() || + can_access_vm_annotations; switch (sid) { case vmSymbols::VM_SYMBOL_ENUM_NAME(reflect_CallerSensitive_signature): { if (_location != _in_method) break; // only allow for methods @@ -2710,6 +2714,7 @@ runtime_visible_annotations_length, &parsed_annotations, _loader_data, + _can_access_vm_annotations, CHECK_NULL); cfs->skip_u1_fast(runtime_visible_annotations_length); } else if (method_attribute_name == vmSymbols::tag_runtime_invisible_annotations()) { @@ -3472,6 +3477,7 @@ runtime_visible_annotations_length, parsed_annotations, _loader_data, + _can_access_vm_annotations, CHECK); cfs->skip_u1_fast(runtime_visible_annotations_length); } else if (tag == vmSymbols::tag_runtime_invisible_annotations()) { @@ -5827,7 +5833,8 @@ Handle protection_domain, const InstanceKlass* unsafe_anonymous_host, GrowableArray* cp_patches, - bool is_nonfindable, + const bool is_nonfindable, + const bool can_access_vm_annotations, Publicity pub_level, TRAPS) : _stream(stream), @@ -5836,6 +5843,7 @@ _unsafe_anonymous_host(unsafe_anonymous_host), _cp_patches(cp_patches), _is_nonfindable(is_nonfindable), + _can_access_vm_annotations(can_access_vm_annotations), _num_patched_klasses(0), _max_num_patched_klasses(0), _orig_cp_size(0), --- old/src/hotspot/share/classfile/classFileParser.hpp 2018-10-31 15:59:39.349367161 -0400 +++ new/src/hotspot/share/classfile/classFileParser.hpp 2018-10-31 15:59:38.796538913 -0400 @@ -85,6 +85,7 @@ const InstanceKlass* _unsafe_anonymous_host; GrowableArray* _cp_patches; // overrides for CP entries const bool _is_nonfindable; + const bool _can_access_vm_annotations; int _num_patched_klasses; int _max_num_patched_klasses; int _orig_cp_size; @@ -504,7 +505,8 @@ Handle protection_domain, const InstanceKlass* unsafe_anonymous_host, GrowableArray* cp_patches, - bool is_nonfindable, + const bool is_nonfindable, + const bool can_access_vm_annotations, Publicity pub_level, TRAPS); --- old/src/hotspot/share/classfile/classLoader.cpp 2018-10-31 15:59:48.135614201 -0400 +++ new/src/hotspot/share/classfile/classLoader.cpp 2018-10-31 15:59:47.468771163 -0400 @@ -1402,6 +1402,7 @@ NULL, // unsafe_anonymous_host NULL, // cp_patches false, // is_nonfindable + false, // can_access_vm_annotations THREAD); if (HAS_PENDING_EXCEPTION) { if (DumpSharedSpaces) { --- old/src/hotspot/share/classfile/classLoaderExt.cpp 2018-10-31 15:59:57.019665338 -0400 +++ new/src/hotspot/share/classfile/classLoaderExt.cpp 2018-10-31 15:59:56.408833121 -0400 @@ -301,6 +301,7 @@ NULL, // unsafe_anonymous_host NULL, // cp_patches false, // is_nonfindable + false, // can_access_vm_annotations THREAD); if (HAS_PENDING_EXCEPTION) { --- old/src/hotspot/share/classfile/klassFactory.cpp 2018-10-31 16:00:06.286830607 -0400 +++ new/src/hotspot/share/classfile/klassFactory.cpp 2018-10-31 16:00:05.727508464 -0400 @@ -102,6 +102,7 @@ NULL, // unsafe_anonymous_host NULL, // cp_patches false, // is_nonfindable + false, // can_access_vm_annotations ClassFileParser::BROADCAST, // publicity level CHECK_NULL); InstanceKlass* new_ik = parser.create_instance_klass(true /* changed_by_loadhook */, @@ -186,7 +187,8 @@ Handle protection_domain, const InstanceKlass* unsafe_anonymous_host, GrowableArray* cp_patches, - bool is_nonfindable, + const bool is_nonfindable, + const bool can_access_vm_annotations, TRAPS) { assert(stream != NULL, "invariant"); assert(loader_data != NULL, "invariant"); @@ -219,6 +221,7 @@ unsafe_anonymous_host, cp_patches, is_nonfindable, + can_access_vm_annotations, ClassFileParser::BROADCAST, // publicity level CHECK_NULL); --- old/src/hotspot/share/classfile/klassFactory.hpp 2018-10-31 16:00:14.994644303 -0400 +++ new/src/hotspot/share/classfile/klassFactory.hpp 2018-10-31 16:00:14.445543107 -0400 @@ -74,7 +74,8 @@ Handle protection_domain, const InstanceKlass* unsafe_anonymous_host, GrowableArray* cp_patches, - bool is_nonfindable, + const bool is_nonfindable, + const bool can_access_vm_annotations, TRAPS); public: static InstanceKlass* check_shared_class_file_load_hook( --- old/src/hotspot/share/classfile/systemDictionary.cpp 2018-10-31 16:00:23.837559498 -0400 +++ new/src/hotspot/share/classfile/systemDictionary.cpp 2018-10-31 16:00:23.179322987 -0400 @@ -997,6 +997,7 @@ GrowableArray* cp_patches, const bool is_nonfindable, const bool is_weaknonfindable, + const bool can_access_vm_annotations, TRAPS) { EventClassLoad class_load_start_event; @@ -1037,6 +1038,7 @@ unsafe_anonymous_host, cp_patches, is_nonfindable, + can_access_vm_annotations, CHECK_NULL); if ((is_nonfindable || (unsafe_anonymous_host != NULL)) && k != NULL) { @@ -1139,6 +1141,7 @@ NULL, // unsafe_anonymous_host NULL, // cp_patches false, // is_nonfindable + false, // can_access_vm_annotations CHECK_NULL); } --- old/src/hotspot/share/classfile/systemDictionary.hpp 2018-10-31 16:00:32.843485440 -0400 +++ new/src/hotspot/share/classfile/systemDictionary.hpp 2018-10-31 16:00:32.186945784 -0400 @@ -285,6 +285,7 @@ NULL, // cp_patches false, // is_nonfindable false, // is_weaknonfindable + false, // can_access_vm_annotations THREAD); } static InstanceKlass* parse_stream(Symbol* class_name, @@ -295,6 +296,7 @@ GrowableArray* cp_patches, const bool is_nonfindable, const bool is_weaknonfindable, + const bool can_access_vm_annotations, TRAPS); // Resolve from stream (called by jni_DefineClass and JVM_DefineClass) --- old/src/hotspot/share/jfr/instrumentation/jfrEventClassTransformer.cpp 2018-10-31 16:00:42.736780255 -0400 +++ new/src/hotspot/share/jfr/instrumentation/jfrEventClassTransformer.cpp 2018-10-31 16:00:41.994829986 -0400 @@ -1412,6 +1412,7 @@ NULL, // host klass NULL, // cp_patches false, // is_nonfindable + false, // can_access_vm_annotations ClassFileParser::INTERNAL, // internal visibility THREAD); if (HAS_PENDING_EXCEPTION) { --- old/src/hotspot/share/prims/jvm.cpp 2018-10-31 16:00:52.169806388 -0400 +++ new/src/hotspot/share/prims/jvm.cpp 2018-10-31 16:00:51.341006966 -0400 @@ -1033,7 +1033,8 @@ NULL, // unsafe_anonymous_host NULL, // cp_patches is_nonfindable, - true, // is_weak - workaround to allow access to VM annotations + is_weak, + vm_annotations, CHECK_NULL); if (k == NULL) { THROW_MSG_0(vmSymbols::java_lang_Error(), "Failure to define a nonfindable class"); --- old/src/hotspot/share/prims/unsafe.cpp 2018-10-31 16:01:01.722622893 -0400 +++ new/src/hotspot/share/prims/unsafe.cpp 2018-10-31 16:01:01.100431186 -0400 @@ -821,6 +821,7 @@ cp_patches, false, // is_nonfindable false, // is_weak + false, // can_access_vm_annotations CHECK_NULL); if (anonk == NULL) { return NULL;