< prev index next >

src/hotspot/share/classfile/classFileParser.cpp

Print this page
rev 52360 : 8212605: Pure-Java implementation of AccessController.doPrivileged


1049       break;
1050     }
1051     default: {
1052       classfile_parse_error("Unable to set initial value %u in class file %s",
1053                              constantvalue_index,
1054                              CHECK);
1055     }
1056   }
1057 }
1058 
1059 class AnnotationCollector : public ResourceObj{
1060 public:
1061   enum Location { _in_field, _in_method, _in_class };
1062   enum ID {
1063     _unknown = 0,
1064     _method_CallerSensitive,
1065     _method_ForceInline,
1066     _method_DontInline,
1067     _method_InjectedProfile,
1068     _method_LambdaForm_Compiled,
1069     _method_LambdaForm_Hidden,
1070     _method_HotSpotIntrinsicCandidate,
1071     _jdk_internal_vm_annotation_Contended,
1072     _field_Stable,
1073     _jdk_internal_vm_annotation_ReservedStackAccess,
1074     _annotation_LIMIT
1075   };
1076   const Location _location;
1077   int _annotations_present;
1078   u2 _contended_group;
1079 
1080   AnnotationCollector(Location location)
1081     : _location(location), _annotations_present(0)
1082   {
1083     assert((int)_annotation_LIMIT <= (int)sizeof(_annotations_present) * BitsPerByte, "");
1084   }
1085   // If this annotation name has an ID, report it (or _none).
1086   ID annotation_index(const ClassLoaderData* loader_data, const Symbol* name);
1087   // Set the annotation name:
1088   void set_annotation(ID id) {
1089     assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");


2104       return _method_ForceInline;
2105     }
2106     case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_DontInline_signature): {
2107       if (_location != _in_method)  break;  // only allow for methods
2108       if (!privileged)              break;  // only allow in privileged code
2109       return _method_DontInline;
2110     }
2111     case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_InjectedProfile_signature): {
2112       if (_location != _in_method)  break;  // only allow for methods
2113       if (!privileged)              break;  // only allow in privileged code
2114       return _method_InjectedProfile;
2115     }
2116     case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_LambdaForm_Compiled_signature): {
2117       if (_location != _in_method)  break;  // only allow for methods
2118       if (!privileged)              break;  // only allow in privileged code
2119       return _method_LambdaForm_Compiled;
2120     }
2121     case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_LambdaForm_Hidden_signature): {
2122       if (_location != _in_method)  break;  // only allow for methods
2123       if (!privileged)              break;  // only allow in privileged code
2124       return _method_LambdaForm_Hidden;





2125     }
2126     case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_HotSpotIntrinsicCandidate_signature): {
2127       if (_location != _in_method)  break;  // only allow for methods
2128       if (!privileged)              break;  // only allow in privileged code
2129       return _method_HotSpotIntrinsicCandidate;
2130     }
2131     case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_Stable_signature): {
2132       if (_location != _in_field)   break;  // only allow for fields
2133       if (!privileged)              break;  // only allow in privileged code
2134       return _field_Stable;
2135     }
2136     case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_Contended_signature): {
2137       if (_location != _in_field && _location != _in_class) {
2138         break;  // only allow for fields and classes
2139       }
2140       if (!EnableContended || (RestrictContended && !privileged)) {
2141         break;  // honor privileges
2142       }
2143       return _jdk_internal_vm_annotation_Contended;
2144     }


2161     f->set_stable(true);
2162 }
2163 
2164 ClassFileParser::FieldAnnotationCollector::~FieldAnnotationCollector() {
2165   // If there's an error deallocate metadata for field annotations
2166   MetadataFactory::free_array<u1>(_loader_data, _field_annotations);
2167   MetadataFactory::free_array<u1>(_loader_data, _field_type_annotations);
2168 }
2169 
2170 void MethodAnnotationCollector::apply_to(const methodHandle& m) {
2171   if (has_annotation(_method_CallerSensitive))
2172     m->set_caller_sensitive(true);
2173   if (has_annotation(_method_ForceInline))
2174     m->set_force_inline(true);
2175   if (has_annotation(_method_DontInline))
2176     m->set_dont_inline(true);
2177   if (has_annotation(_method_InjectedProfile))
2178     m->set_has_injected_profile(true);
2179   if (has_annotation(_method_LambdaForm_Compiled) && m->intrinsic_id() == vmIntrinsics::_none)
2180     m->set_intrinsic_id(vmIntrinsics::_compiledLambdaForm);
2181   if (has_annotation(_method_LambdaForm_Hidden))
2182     m->set_hidden(true);
2183   if (has_annotation(_method_HotSpotIntrinsicCandidate) && !m->is_synthetic())
2184     m->set_intrinsic_candidate(true);
2185   if (has_annotation(_jdk_internal_vm_annotation_ReservedStackAccess))
2186     m->set_has_reserved_stack_access(true);
2187 }
2188 
2189 void ClassFileParser::ClassAnnotationCollector::apply_to(InstanceKlass* ik) {
2190   assert(ik != NULL, "invariant");
2191   ik->set_is_contended(is_contended());
2192 }
2193 
2194 #define MAX_ARGS_SIZE 255
2195 #define MAX_CODE_SIZE 65535
2196 #define INITIAL_MAX_LVT_NUMBER 256
2197 
2198 /* Copy class file LVT's/LVTT's into the HotSpot internal LVT.
2199  *
2200  * Rules for LVT's and LVTT's are:
2201  *   - There can be any number of LVT's and LVTT's.




1049       break;
1050     }
1051     default: {
1052       classfile_parse_error("Unable to set initial value %u in class file %s",
1053                              constantvalue_index,
1054                              CHECK);
1055     }
1056   }
1057 }
1058 
1059 class AnnotationCollector : public ResourceObj{
1060 public:
1061   enum Location { _in_field, _in_method, _in_class };
1062   enum ID {
1063     _unknown = 0,
1064     _method_CallerSensitive,
1065     _method_ForceInline,
1066     _method_DontInline,
1067     _method_InjectedProfile,
1068     _method_LambdaForm_Compiled,
1069     _method_Hidden,
1070     _method_HotSpotIntrinsicCandidate,
1071     _jdk_internal_vm_annotation_Contended,
1072     _field_Stable,
1073     _jdk_internal_vm_annotation_ReservedStackAccess,
1074     _annotation_LIMIT
1075   };
1076   const Location _location;
1077   int _annotations_present;
1078   u2 _contended_group;
1079 
1080   AnnotationCollector(Location location)
1081     : _location(location), _annotations_present(0)
1082   {
1083     assert((int)_annotation_LIMIT <= (int)sizeof(_annotations_present) * BitsPerByte, "");
1084   }
1085   // If this annotation name has an ID, report it (or _none).
1086   ID annotation_index(const ClassLoaderData* loader_data, const Symbol* name);
1087   // Set the annotation name:
1088   void set_annotation(ID id) {
1089     assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");


2104       return _method_ForceInline;
2105     }
2106     case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_DontInline_signature): {
2107       if (_location != _in_method)  break;  // only allow for methods
2108       if (!privileged)              break;  // only allow in privileged code
2109       return _method_DontInline;
2110     }
2111     case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_InjectedProfile_signature): {
2112       if (_location != _in_method)  break;  // only allow for methods
2113       if (!privileged)              break;  // only allow in privileged code
2114       return _method_InjectedProfile;
2115     }
2116     case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_LambdaForm_Compiled_signature): {
2117       if (_location != _in_method)  break;  // only allow for methods
2118       if (!privileged)              break;  // only allow in privileged code
2119       return _method_LambdaForm_Compiled;
2120     }
2121     case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_LambdaForm_Hidden_signature): {
2122       if (_location != _in_method)  break;  // only allow for methods
2123       if (!privileged)              break;  // only allow in privileged code
2124       return _method_Hidden;
2125     }
2126     case vmSymbols::VM_SYMBOL_ENUM_NAME(java_security_AccessController_Hidden_signature): {
2127       if (_location != _in_method)  break;  // only allow for methods
2128       if (!privileged)              break;  // only allow in privileged code
2129       return _method_Hidden;
2130     }
2131     case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_HotSpotIntrinsicCandidate_signature): {
2132       if (_location != _in_method)  break;  // only allow for methods
2133       if (!privileged)              break;  // only allow in privileged code
2134       return _method_HotSpotIntrinsicCandidate;
2135     }
2136     case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_Stable_signature): {
2137       if (_location != _in_field)   break;  // only allow for fields
2138       if (!privileged)              break;  // only allow in privileged code
2139       return _field_Stable;
2140     }
2141     case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_Contended_signature): {
2142       if (_location != _in_field && _location != _in_class) {
2143         break;  // only allow for fields and classes
2144       }
2145       if (!EnableContended || (RestrictContended && !privileged)) {
2146         break;  // honor privileges
2147       }
2148       return _jdk_internal_vm_annotation_Contended;
2149     }


2166     f->set_stable(true);
2167 }
2168 
2169 ClassFileParser::FieldAnnotationCollector::~FieldAnnotationCollector() {
2170   // If there's an error deallocate metadata for field annotations
2171   MetadataFactory::free_array<u1>(_loader_data, _field_annotations);
2172   MetadataFactory::free_array<u1>(_loader_data, _field_type_annotations);
2173 }
2174 
2175 void MethodAnnotationCollector::apply_to(const methodHandle& m) {
2176   if (has_annotation(_method_CallerSensitive))
2177     m->set_caller_sensitive(true);
2178   if (has_annotation(_method_ForceInline))
2179     m->set_force_inline(true);
2180   if (has_annotation(_method_DontInline))
2181     m->set_dont_inline(true);
2182   if (has_annotation(_method_InjectedProfile))
2183     m->set_has_injected_profile(true);
2184   if (has_annotation(_method_LambdaForm_Compiled) && m->intrinsic_id() == vmIntrinsics::_none)
2185     m->set_intrinsic_id(vmIntrinsics::_compiledLambdaForm);
2186   if (has_annotation(_method_Hidden))
2187     m->set_hidden(true);
2188   if (has_annotation(_method_HotSpotIntrinsicCandidate) && !m->is_synthetic())
2189     m->set_intrinsic_candidate(true);
2190   if (has_annotation(_jdk_internal_vm_annotation_ReservedStackAccess))
2191     m->set_has_reserved_stack_access(true);
2192 }
2193 
2194 void ClassFileParser::ClassAnnotationCollector::apply_to(InstanceKlass* ik) {
2195   assert(ik != NULL, "invariant");
2196   ik->set_is_contended(is_contended());
2197 }
2198 
2199 #define MAX_ARGS_SIZE 255
2200 #define MAX_CODE_SIZE 65535
2201 #define INITIAL_MAX_LVT_NUMBER 256
2202 
2203 /* Copy class file LVT's/LVTT's into the HotSpot internal LVT.
2204  *
2205  * Rules for LVT's and LVTT's are:
2206  *   - There can be any number of LVT's and LVTT's.


< prev index next >