745 classfile_parse_error(
746 "Bad method name at constant pool index %u in class file %s",
747 name_ref_index, CHECK);
748 }
749 }
750 break;
751 }
752 case JVM_CONSTANT_MethodHandle: {
753 const int ref_index = cp->method_handle_index_at(index);
754 const int ref_kind = cp->method_handle_ref_kind_at(index);
755 switch (ref_kind) {
756 case JVM_REF_invokeVirtual:
757 case JVM_REF_invokeStatic:
758 case JVM_REF_invokeSpecial:
759 case JVM_REF_newInvokeSpecial: {
760 const int name_and_type_ref_index =
761 cp->name_and_type_ref_index_at(ref_index);
762 const int name_ref_index =
763 cp->name_ref_index_at(name_and_type_ref_index);
764 const Symbol* const name = cp->symbol_at(name_ref_index);
765 if (ref_kind == JVM_REF_newInvokeSpecial) {
766 if (name != vmSymbols::object_initializer_name()) {
767 classfile_parse_error(
768 "Bad constructor name at constant pool index %u in class file %s",
769 name_ref_index, CHECK);
770 }
771 } else {
772 if (name == vmSymbols::object_initializer_name()) {
773 classfile_parse_error(
774 "Bad method name at constant pool index %u in class file %s",
775 name_ref_index, CHECK);
776 }
777 }
778 break;
779 }
780 // Other ref_kinds are already fully checked in previous pass.
781 } // switch(ref_kind)
782 break;
783 }
784 case JVM_CONSTANT_MethodType: {
785 const Symbol* const no_name = vmSymbols::type_name(); // place holder
786 const Symbol* const signature = cp->method_type_signature_at(index);
787 verify_legal_method_signature(no_name, signature, CHECK);
788 break;
789 }
790 case JVM_CONSTANT_Utf8: {
791 assert(cp->symbol_at(index)->refcount() != 0, "count corrupted");
792 }
2076 "Exception name has bad type at constant pool %u in class file %s",
2077 checked_exception, CHECK_NULL);
2078 }
2079 }
2080 // check exceptions attribute length
2081 if (_need_verify) {
2082 guarantee_property(method_attribute_length == (sizeof(*checked_exceptions_length) +
2083 sizeof(u2) * size),
2084 "Exceptions attribute has wrong length in class file %s", CHECK_NULL);
2085 }
2086 return checked_exceptions_start;
2087 }
2088
2089 void ClassFileParser::throwIllegalSignature(const char* type,
2090 const Symbol* name,
2091 const Symbol* sig,
2092 TRAPS) const {
2093 assert(name != NULL, "invariant");
2094 assert(sig != NULL, "invariant");
2095
2096 ResourceMark rm(THREAD);
2097 Exceptions::fthrow(THREAD_AND_LOCATION,
2098 vmSymbols::java_lang_ClassFormatError(),
2099 "%s \"%s\" in class %s has illegal signature \"%s\"", type,
2100 name->as_C_string(), _class_name->as_C_string(), sig->as_C_string());
2101 }
2102
2103 AnnotationCollector::ID
2104 AnnotationCollector::annotation_index(const ClassLoaderData* loader_data,
2105 const Symbol* name) {
2106 const vmSymbols::SID sid = vmSymbols::find_sid(name);
2107 // Privileged code can use all annotations. Other code silently drops some.
2108 const bool privileged = loader_data->is_the_null_class_loader_data() ||
2109 loader_data->is_platform_class_loader_data() ||
2110 loader_data->is_unsafe_anonymous();
2111 switch (sid) {
2112 case vmSymbols::VM_SYMBOL_ENUM_NAME(reflect_CallerSensitive_signature): {
2113 if (_location != _in_method) break; // only allow for methods
2114 if (!privileged) break; // only allow in privileged code
2115 return _method_CallerSensitive;
2116 }
2117 case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_ForceInline_signature): {
2118 if (_location != _in_method) break; // only allow for methods
2119 if (!privileged) break; // only allow in privileged code
2120 return _method_ForceInline;
2391 signature_index, CHECK_NULL);
2392 const Symbol* const signature = cp->symbol_at(signature_index);
2393
2394 if (name == vmSymbols::class_initializer_name()) {
2395 // We ignore the other access flags for a valid class initializer.
2396 // (JVM Spec 2nd ed., chapter 4.6)
2397 if (_major_version < 51) { // backward compatibility
2398 flags = JVM_ACC_STATIC;
2399 } else if ((flags & JVM_ACC_STATIC) == JVM_ACC_STATIC) {
2400 flags &= JVM_ACC_STATIC | JVM_ACC_STRICT;
2401 } else {
2402 classfile_parse_error("Method <clinit> is not static in class file %s", CHECK_NULL);
2403 }
2404 } else {
2405 verify_legal_method_modifiers(flags, is_interface, is_value_type, name, CHECK_NULL);
2406 }
2407
2408 if (name == vmSymbols::object_initializer_name()) {
2409 if (is_interface) {
2410 classfile_parse_error("Interface cannot have a method named <init>, class file %s", CHECK_NULL);
2411 /* TBD: uncomment when javac stops generating <init>() for value types.
2412 } else if (is_value_type) {
2413 classfile_parse_error("Value Type cannot have a method named <init>, class file %s", CHECK_NULL);
2414 */
2415 }
2416 }
2417
2418 int args_size = -1; // only used when _need_verify is true
2419 if (_need_verify) {
2420 args_size = ((flags & JVM_ACC_STATIC) ? 0 : 1) +
2421 verify_legal_method_signature(name, signature, CHECK_NULL);
2422 if (args_size > MAX_ARGS_SIZE) {
2423 classfile_parse_error("Too many arguments in method signature in class file %s", CHECK_NULL);
2424 }
2425 }
2426
2427 AccessFlags access_flags(flags & JVM_RECOGNIZED_METHOD_MODIFIERS);
2428
2429 // Default values for code and exceptions attribute elements
2430 u2 max_stack = 0;
2431 u2 max_locals = 0;
2432 u4 code_length = 0;
2433 const u1* code_start = 0;
2434 u2 exception_table_length = 0;
2435 const unsafe_u2* exception_table_start = NULL; // (potentially unaligned) pointer to array of u2 elements
4992 _class_name->as_C_string()
4993 );
4994 }
4995
4996 if (!_need_verify) { return; }
4997
4998 const bool is_interface = (flags & JVM_ACC_INTERFACE) != 0;
4999 const bool is_abstract = (flags & JVM_ACC_ABSTRACT) != 0;
5000 const bool is_final = (flags & JVM_ACC_FINAL) != 0;
5001 const bool is_super = (flags & JVM_ACC_SUPER) != 0;
5002 const bool is_enum = (flags & JVM_ACC_ENUM) != 0;
5003 const bool is_annotation = (flags & JVM_ACC_ANNOTATION) != 0;
5004 const bool major_gte_15 = _major_version >= JAVA_1_5_VERSION;
5005
5006 if ((is_abstract && is_final) ||
5007 (is_interface && !is_abstract) ||
5008 (is_interface && major_gte_15 && (is_super || is_enum)) ||
5009 (!is_interface && major_gte_15 && is_annotation) ||
5010 (is_value_type && (is_interface || is_abstract || is_enum || !is_final))) {
5011 ResourceMark rm(THREAD);
5012 Exceptions::fthrow(
5013 THREAD_AND_LOCATION,
5014 vmSymbols::java_lang_ClassFormatError(),
5015 "Illegal class modifiers in class %s: 0x%X",
5016 _class_name->as_C_string(), flags
5017 );
5018 return;
5019 }
5020 }
5021
5022 static bool has_illegal_visibility(jint flags) {
5023 const bool is_public = (flags & JVM_ACC_PUBLIC) != 0;
5024 const bool is_protected = (flags & JVM_ACC_PROTECTED) != 0;
5025 const bool is_private = (flags & JVM_ACC_PRIVATE) != 0;
5026
5027 return ((is_public && is_protected) ||
5028 (is_public && is_private) ||
5029 (is_protected && is_private));
5030 }
5031
5032 // A legal major_version.minor_version must be one of the following:
5033 //
5034 // Major_version = 45, any minor_version.
5035 // Major_version >= 46 and major_version <= current_major_version and minor_version = 0.
5036 // Major_version = current_major_version and minor_version = 65535 and --enable-preview is present.
5139 const Symbol* name,
5140 TRAPS) const {
5141 if (!_need_verify) { return; }
5142
5143 const bool is_public = (flags & JVM_ACC_PUBLIC) != 0;
5144 const bool is_private = (flags & JVM_ACC_PRIVATE) != 0;
5145 const bool is_static = (flags & JVM_ACC_STATIC) != 0;
5146 const bool is_final = (flags & JVM_ACC_FINAL) != 0;
5147 const bool is_native = (flags & JVM_ACC_NATIVE) != 0;
5148 const bool is_abstract = (flags & JVM_ACC_ABSTRACT) != 0;
5149 const bool is_bridge = (flags & JVM_ACC_BRIDGE) != 0;
5150 const bool is_strict = (flags & JVM_ACC_STRICT) != 0;
5151 const bool is_synchronized = (flags & JVM_ACC_SYNCHRONIZED) != 0;
5152 const bool is_protected = (flags & JVM_ACC_PROTECTED) != 0;
5153 const bool major_gte_15 = _major_version >= JAVA_1_5_VERSION;
5154 const bool major_gte_8 = _major_version >= JAVA_8_VERSION;
5155 const bool is_initializer = (name == vmSymbols::object_initializer_name());
5156
5157 bool is_illegal = false;
5158
5159 if (is_interface) {
5160 if (major_gte_8) {
5161 // Class file version is JAVA_8_VERSION or later Methods of
5162 // interfaces may set any of the flags except ACC_PROTECTED,
5163 // ACC_FINAL, ACC_NATIVE, and ACC_SYNCHRONIZED; they must
5164 // have exactly one of the ACC_PUBLIC or ACC_PRIVATE flags set.
5165 if ((is_public == is_private) || /* Only one of private and public should be true - XNOR */
5166 (is_native || is_protected || is_final || is_synchronized) ||
5167 // If a specific method of a class or interface has its
5168 // ACC_ABSTRACT flag set, it must not have any of its
5169 // ACC_FINAL, ACC_NATIVE, ACC_PRIVATE, ACC_STATIC,
5170 // ACC_STRICT, or ACC_SYNCHRONIZED flags set. No need to
5171 // check for ACC_FINAL, ACC_NATIVE or ACC_SYNCHRONIZED as
5172 // those flags are illegal irrespective of ACC_ABSTRACT being set or not.
5173 (is_abstract && (is_private || is_static || is_strict))) {
5174 is_illegal = true;
5175 }
5176 } else if (major_gte_15) {
5177 // Class file version in the interval [JAVA_1_5_VERSION, JAVA_8_VERSION)
5178 if (!is_public || is_private || is_protected || is_static || is_final ||
5179 is_synchronized || is_native || !is_abstract || is_strict) {
5180 is_illegal = true;
5181 }
5182 } else {
5183 // Class file version is pre-JAVA_1_5_VERSION
5184 if (!is_public || is_static || is_final || is_native || !is_abstract) {
5185 is_illegal = true;
5186 }
5187 }
5188 } else { // not interface
5189 if (has_illegal_visibility(flags)) {
5190 is_illegal = true;
5191 } else {
5192 if (is_initializer) {
5193 if (is_static || is_final || is_synchronized || is_native ||
5194 is_abstract || (major_gte_15 && is_bridge)) {
5195 is_illegal = true;
5196 }
5197 } else { // not initializer
5198 if (is_value_type && is_synchronized && !is_static) {
5199 is_illegal = true;
5200 } else {
5201 if (is_abstract) {
5202 if ((is_final || is_native || is_private || is_static ||
5203 (major_gte_15 && (is_synchronized || is_strict)))) {
5204 is_illegal = true;
5205 }
5206 }
5207 }
5208 }
5209 }
5210 }
5211
5212 if (is_illegal) {
5213 ResourceMark rm(THREAD);
5214 Exceptions::fthrow(
5215 THREAD_AND_LOCATION,
5216 vmSymbols::java_lang_ClassFormatError(),
5217 "Method %s in class %s has illegal modifiers: 0x%X",
5218 name->as_C_string(), _class_name->as_C_string(), flags);
5219 return;
5220 }
5221 }
5222
5223 void ClassFileParser::verify_legal_utf8(const unsigned char* buffer,
5224 int length,
5225 TRAPS) const {
5226 assert(_need_verify, "only called when _need_verify is true");
5227 if (!UTF8::is_legal_utf8(buffer, length, _major_version <= 47)) {
5228 classfile_parse_error("Illegal UTF8 string in constant pool in class file %s", CHECK);
5229 }
5230 }
5231
5232 // Unqualified names may not contain the characters '.', ';', '[', or '/'.
5233 // In class names, '/' separates unqualified names. This is verified in this function also.
5234 // Method names also may not contain the characters '<' or '>', unless <init>
5235 // or <clinit>. Note that method names may not be <init> or <clinit> in this
5236 // method. Because these names have been checked as special cases before
5237 // calling this method in verify_legal_method_name.
5238 //
5581 const char* nextp;
5582
5583 // The first character must be a '('
5584 if ((length > 0) && (*p++ == JVM_SIGNATURE_FUNC)) {
5585 length--;
5586 // Skip over legal field signatures
5587 nextp = skip_over_field_signature(p, false, length, CHECK_0);
5588 while ((length > 0) && (nextp != NULL)) {
5589 args_size++;
5590 if (p[0] == 'J' || p[0] == 'D') {
5591 args_size++;
5592 }
5593 length -= nextp - p;
5594 p = nextp;
5595 nextp = skip_over_field_signature(p, false, length, CHECK_0);
5596 }
5597 // The first non-signature thing better be a ')'
5598 if ((length > 0) && (*p++ == JVM_SIGNATURE_ENDFUNC)) {
5599 length--;
5600 if (name->utf8_length() > 0 && name->char_at(0) == '<') {
5601 // All internal methods must return void
5602 if ((length == 1) && (p[0] == JVM_SIGNATURE_VOID)) {
5603 return args_size;
5604 }
5605 } else {
5606 // Now we better just have a return value
5607 nextp = skip_over_field_signature(p, true, length, CHECK_0);
5608 if (nextp && ((int)length == (nextp - p))) {
5609 return args_size;
5610 }
5611 }
5612 }
5613 }
5614 // Report error
5615 throwIllegalSignature("Method", name, signature, CHECK_0);
5616 return 0;
5617 }
5618
5619 int ClassFileParser::static_field_size() const {
5620 assert(_field_info != NULL, "invariant");
5621 return _field_info->static_field_size;
5622 }
5623
5624 int ClassFileParser::total_oop_map_count() const {
|
745 classfile_parse_error(
746 "Bad method name at constant pool index %u in class file %s",
747 name_ref_index, CHECK);
748 }
749 }
750 break;
751 }
752 case JVM_CONSTANT_MethodHandle: {
753 const int ref_index = cp->method_handle_index_at(index);
754 const int ref_kind = cp->method_handle_ref_kind_at(index);
755 switch (ref_kind) {
756 case JVM_REF_invokeVirtual:
757 case JVM_REF_invokeStatic:
758 case JVM_REF_invokeSpecial:
759 case JVM_REF_newInvokeSpecial: {
760 const int name_and_type_ref_index =
761 cp->name_and_type_ref_index_at(ref_index);
762 const int name_ref_index =
763 cp->name_ref_index_at(name_and_type_ref_index);
764 const Symbol* const name = cp->symbol_at(name_ref_index);
765 if (name != vmSymbols::object_initializer_name()) {
766 if (ref_kind == JVM_REF_newInvokeSpecial) {
767 classfile_parse_error(
768 "Bad constructor name at constant pool index %u in class file %s",
769 name_ref_index, CHECK);
770 }
771 } else {
772 // The allowed invocation mode of <init> depends on its signature.
773 // This test corresponds to verify_invoke_instructions in the verifier.
774 const int signature_ref_index =
775 cp->signature_ref_index_at(name_and_type_ref_index);
776 const Symbol* const signature = cp->symbol_at(signature_ref_index);
777 if (signature->is_void_method_signature()
778 && ref_kind == JVM_REF_newInvokeSpecial) {
779 // OK, could be a constructor call
780 } else if (!signature->is_void_method_signature()
781 && ref_kind == JVM_REF_invokeStatic) {
782 // also OK, could be a static factory call
783 } else {
784 classfile_parse_error(
785 "Bad method name at constant pool index %u in class file %s",
786 name_ref_index, CHECK);
787 }
788 }
789 break;
790 }
791 // Other ref_kinds are already fully checked in previous pass.
792 } // switch(ref_kind)
793 break;
794 }
795 case JVM_CONSTANT_MethodType: {
796 const Symbol* const no_name = vmSymbols::type_name(); // place holder
797 const Symbol* const signature = cp->method_type_signature_at(index);
798 verify_legal_method_signature(no_name, signature, CHECK);
799 break;
800 }
801 case JVM_CONSTANT_Utf8: {
802 assert(cp->symbol_at(index)->refcount() != 0, "count corrupted");
803 }
2087 "Exception name has bad type at constant pool %u in class file %s",
2088 checked_exception, CHECK_NULL);
2089 }
2090 }
2091 // check exceptions attribute length
2092 if (_need_verify) {
2093 guarantee_property(method_attribute_length == (sizeof(*checked_exceptions_length) +
2094 sizeof(u2) * size),
2095 "Exceptions attribute has wrong length in class file %s", CHECK_NULL);
2096 }
2097 return checked_exceptions_start;
2098 }
2099
2100 void ClassFileParser::throwIllegalSignature(const char* type,
2101 const Symbol* name,
2102 const Symbol* sig,
2103 TRAPS) const {
2104 assert(name != NULL, "invariant");
2105 assert(sig != NULL, "invariant");
2106
2107 const char* class_note = "";
2108 if (is_value_type() && name == vmSymbols::object_initializer_name()) {
2109 class_note = " (an inline class)";
2110 }
2111
2112 ResourceMark rm(THREAD);
2113 Exceptions::fthrow(THREAD_AND_LOCATION,
2114 vmSymbols::java_lang_ClassFormatError(),
2115 "%s \"%s\" in class %s%s has illegal signature \"%s\"", type,
2116 name->as_C_string(), _class_name->as_C_string(), class_note, sig->as_C_string());
2117 }
2118
2119 AnnotationCollector::ID
2120 AnnotationCollector::annotation_index(const ClassLoaderData* loader_data,
2121 const Symbol* name) {
2122 const vmSymbols::SID sid = vmSymbols::find_sid(name);
2123 // Privileged code can use all annotations. Other code silently drops some.
2124 const bool privileged = loader_data->is_the_null_class_loader_data() ||
2125 loader_data->is_platform_class_loader_data() ||
2126 loader_data->is_unsafe_anonymous();
2127 switch (sid) {
2128 case vmSymbols::VM_SYMBOL_ENUM_NAME(reflect_CallerSensitive_signature): {
2129 if (_location != _in_method) break; // only allow for methods
2130 if (!privileged) break; // only allow in privileged code
2131 return _method_CallerSensitive;
2132 }
2133 case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_ForceInline_signature): {
2134 if (_location != _in_method) break; // only allow for methods
2135 if (!privileged) break; // only allow in privileged code
2136 return _method_ForceInline;
2407 signature_index, CHECK_NULL);
2408 const Symbol* const signature = cp->symbol_at(signature_index);
2409
2410 if (name == vmSymbols::class_initializer_name()) {
2411 // We ignore the other access flags for a valid class initializer.
2412 // (JVM Spec 2nd ed., chapter 4.6)
2413 if (_major_version < 51) { // backward compatibility
2414 flags = JVM_ACC_STATIC;
2415 } else if ((flags & JVM_ACC_STATIC) == JVM_ACC_STATIC) {
2416 flags &= JVM_ACC_STATIC | JVM_ACC_STRICT;
2417 } else {
2418 classfile_parse_error("Method <clinit> is not static in class file %s", CHECK_NULL);
2419 }
2420 } else {
2421 verify_legal_method_modifiers(flags, is_interface, is_value_type, name, CHECK_NULL);
2422 }
2423
2424 if (name == vmSymbols::object_initializer_name()) {
2425 if (is_interface) {
2426 classfile_parse_error("Interface cannot have a method named <init>, class file %s", CHECK_NULL);
2427 } else if (!is_value_type && signature->is_void_method_signature()) {
2428 // OK, a constructor
2429 } else if (is_value_type && !signature->is_void_method_signature()) {
2430 // also OK, a static factory, as long as the return value is good
2431 bool ok = false;
2432 SignatureStream ss((Symbol*) signature, true);
2433 while (!ss.at_return_type()) ss.next();
2434 if (ss.is_object()) {
2435 TempNewSymbol ret = ss.as_symbol_or_null();
2436 const Symbol* required = class_name();
2437 if (is_unsafe_anonymous()) {
2438 // nobody can mention such a class name
2439 required = vmSymbols::java_lang_Object();
2440 }
2441 ok = (ret == required);
2442 }
2443 if (!ok) {
2444 throwIllegalSignature("Method", name, signature, CHECK_0);
2445 }
2446 } else {
2447 // not OK, so throw the same error as in verify_legal_method_signature.
2448 throwIllegalSignature("Method", name, signature, CHECK_0);
2449 }
2450 // A declared <init> method must always be either a non-static
2451 // object constructor, with a void return, or else it must be a
2452 // static factory method, with a non-void return. No other
2453 // definition of <init> is possible.
2454 //
2455 // The verifier (in verify_invoke_instructions) will inspect the
2456 // signature of any attempt to invoke <init>, and ensures that it
2457 // returns non-void if and only if it is being invoked by
2458 // invokestatic, and void if and only if it is being invoked by
2459 // invokespecial.
2460 //
2461 // When a symbolic reference to <init> is resolved for a
2462 // particular invocation mode (special or static), the mode is
2463 // matched to the JVM_ACC_STATIC modifier of the <init> method.
2464 // Thus, it is impossible to statically invoke a constructor, and
2465 // impossible to "new + invokespecial" a static factory, either
2466 // through bytecode or through reflection.
2467 }
2468
2469 int args_size = -1; // only used when _need_verify is true
2470 if (_need_verify) {
2471 args_size = ((flags & JVM_ACC_STATIC) ? 0 : 1) +
2472 verify_legal_method_signature(name, signature, CHECK_NULL);
2473 if (args_size > MAX_ARGS_SIZE) {
2474 classfile_parse_error("Too many arguments in method signature in class file %s", CHECK_NULL);
2475 }
2476 }
2477
2478 AccessFlags access_flags(flags & JVM_RECOGNIZED_METHOD_MODIFIERS);
2479
2480 // Default values for code and exceptions attribute elements
2481 u2 max_stack = 0;
2482 u2 max_locals = 0;
2483 u4 code_length = 0;
2484 const u1* code_start = 0;
2485 u2 exception_table_length = 0;
2486 const unsafe_u2* exception_table_start = NULL; // (potentially unaligned) pointer to array of u2 elements
5043 _class_name->as_C_string()
5044 );
5045 }
5046
5047 if (!_need_verify) { return; }
5048
5049 const bool is_interface = (flags & JVM_ACC_INTERFACE) != 0;
5050 const bool is_abstract = (flags & JVM_ACC_ABSTRACT) != 0;
5051 const bool is_final = (flags & JVM_ACC_FINAL) != 0;
5052 const bool is_super = (flags & JVM_ACC_SUPER) != 0;
5053 const bool is_enum = (flags & JVM_ACC_ENUM) != 0;
5054 const bool is_annotation = (flags & JVM_ACC_ANNOTATION) != 0;
5055 const bool major_gte_15 = _major_version >= JAVA_1_5_VERSION;
5056
5057 if ((is_abstract && is_final) ||
5058 (is_interface && !is_abstract) ||
5059 (is_interface && major_gte_15 && (is_super || is_enum)) ||
5060 (!is_interface && major_gte_15 && is_annotation) ||
5061 (is_value_type && (is_interface || is_abstract || is_enum || !is_final))) {
5062 ResourceMark rm(THREAD);
5063 const char* class_note = "";
5064 if (is_value_type) class_note = " (an inline class)";
5065 Exceptions::fthrow(
5066 THREAD_AND_LOCATION,
5067 vmSymbols::java_lang_ClassFormatError(),
5068 "Illegal class modifiers in class %s%s: 0x%X",
5069 _class_name->as_C_string(), class_note, flags
5070 );
5071 return;
5072 }
5073 }
5074
5075 static bool has_illegal_visibility(jint flags) {
5076 const bool is_public = (flags & JVM_ACC_PUBLIC) != 0;
5077 const bool is_protected = (flags & JVM_ACC_PROTECTED) != 0;
5078 const bool is_private = (flags & JVM_ACC_PRIVATE) != 0;
5079
5080 return ((is_public && is_protected) ||
5081 (is_public && is_private) ||
5082 (is_protected && is_private));
5083 }
5084
5085 // A legal major_version.minor_version must be one of the following:
5086 //
5087 // Major_version = 45, any minor_version.
5088 // Major_version >= 46 and major_version <= current_major_version and minor_version = 0.
5089 // Major_version = current_major_version and minor_version = 65535 and --enable-preview is present.
5192 const Symbol* name,
5193 TRAPS) const {
5194 if (!_need_verify) { return; }
5195
5196 const bool is_public = (flags & JVM_ACC_PUBLIC) != 0;
5197 const bool is_private = (flags & JVM_ACC_PRIVATE) != 0;
5198 const bool is_static = (flags & JVM_ACC_STATIC) != 0;
5199 const bool is_final = (flags & JVM_ACC_FINAL) != 0;
5200 const bool is_native = (flags & JVM_ACC_NATIVE) != 0;
5201 const bool is_abstract = (flags & JVM_ACC_ABSTRACT) != 0;
5202 const bool is_bridge = (flags & JVM_ACC_BRIDGE) != 0;
5203 const bool is_strict = (flags & JVM_ACC_STRICT) != 0;
5204 const bool is_synchronized = (flags & JVM_ACC_SYNCHRONIZED) != 0;
5205 const bool is_protected = (flags & JVM_ACC_PROTECTED) != 0;
5206 const bool major_gte_15 = _major_version >= JAVA_1_5_VERSION;
5207 const bool major_gte_8 = _major_version >= JAVA_8_VERSION;
5208 const bool is_initializer = (name == vmSymbols::object_initializer_name());
5209
5210 bool is_illegal = false;
5211
5212 const char* class_note = "";
5213
5214 if (is_interface) {
5215 if (major_gte_8) {
5216 // Class file version is JAVA_8_VERSION or later Methods of
5217 // interfaces may set any of the flags except ACC_PROTECTED,
5218 // ACC_FINAL, ACC_NATIVE, and ACC_SYNCHRONIZED; they must
5219 // have exactly one of the ACC_PUBLIC or ACC_PRIVATE flags set.
5220 if ((is_public == is_private) || /* Only one of private and public should be true - XNOR */
5221 (is_native || is_protected || is_final || is_synchronized) ||
5222 // If a specific method of a class or interface has its
5223 // ACC_ABSTRACT flag set, it must not have any of its
5224 // ACC_FINAL, ACC_NATIVE, ACC_PRIVATE, ACC_STATIC,
5225 // ACC_STRICT, or ACC_SYNCHRONIZED flags set. No need to
5226 // check for ACC_FINAL, ACC_NATIVE or ACC_SYNCHRONIZED as
5227 // those flags are illegal irrespective of ACC_ABSTRACT being set or not.
5228 (is_abstract && (is_private || is_static || is_strict))) {
5229 is_illegal = true;
5230 }
5231 } else if (major_gte_15) {
5232 // Class file version in the interval [JAVA_1_5_VERSION, JAVA_8_VERSION)
5233 if (!is_public || is_private || is_protected || is_static || is_final ||
5234 is_synchronized || is_native || !is_abstract || is_strict) {
5235 is_illegal = true;
5236 }
5237 } else {
5238 // Class file version is pre-JAVA_1_5_VERSION
5239 if (!is_public || is_static || is_final || is_native || !is_abstract) {
5240 is_illegal = true;
5241 }
5242 }
5243 } else { // not interface
5244 if (has_illegal_visibility(flags)) {
5245 is_illegal = true;
5246 } else {
5247 if (is_initializer) {
5248 if (is_final || is_synchronized || is_native ||
5249 is_abstract || (major_gte_15 && is_bridge)) {
5250 is_illegal = true;
5251 }
5252 if (!is_static && !is_value_type) {
5253 // OK, an object constructor in a regular class
5254 } else if (is_static && is_value_type) {
5255 // OK, a static init factory in an inline class
5256 } else {
5257 // but no other combinations are allowed
5258 is_illegal = true;
5259 class_note = (is_value_type ? " (an inline class)" : " (not an inline class)");
5260 }
5261 } else { // not initializer
5262 if (is_value_type && is_synchronized && !is_static) {
5263 is_illegal = true;
5264 class_note = " (an inline class)";
5265 } else {
5266 if (is_abstract) {
5267 if ((is_final || is_native || is_private || is_static ||
5268 (major_gte_15 && (is_synchronized || is_strict)))) {
5269 is_illegal = true;
5270 }
5271 }
5272 }
5273 }
5274 }
5275 }
5276
5277 if (is_illegal) {
5278 ResourceMark rm(THREAD);
5279 Exceptions::fthrow(
5280 THREAD_AND_LOCATION,
5281 vmSymbols::java_lang_ClassFormatError(),
5282 "Method %s in class %s%s has illegal modifiers: 0x%X",
5283 name->as_C_string(), _class_name->as_C_string(), class_note, flags);
5284 return;
5285 }
5286 }
5287
5288 void ClassFileParser::verify_legal_utf8(const unsigned char* buffer,
5289 int length,
5290 TRAPS) const {
5291 assert(_need_verify, "only called when _need_verify is true");
5292 if (!UTF8::is_legal_utf8(buffer, length, _major_version <= 47)) {
5293 classfile_parse_error("Illegal UTF8 string in constant pool in class file %s", CHECK);
5294 }
5295 }
5296
5297 // Unqualified names may not contain the characters '.', ';', '[', or '/'.
5298 // In class names, '/' separates unqualified names. This is verified in this function also.
5299 // Method names also may not contain the characters '<' or '>', unless <init>
5300 // or <clinit>. Note that method names may not be <init> or <clinit> in this
5301 // method. Because these names have been checked as special cases before
5302 // calling this method in verify_legal_method_name.
5303 //
5646 const char* nextp;
5647
5648 // The first character must be a '('
5649 if ((length > 0) && (*p++ == JVM_SIGNATURE_FUNC)) {
5650 length--;
5651 // Skip over legal field signatures
5652 nextp = skip_over_field_signature(p, false, length, CHECK_0);
5653 while ((length > 0) && (nextp != NULL)) {
5654 args_size++;
5655 if (p[0] == 'J' || p[0] == 'D') {
5656 args_size++;
5657 }
5658 length -= nextp - p;
5659 p = nextp;
5660 nextp = skip_over_field_signature(p, false, length, CHECK_0);
5661 }
5662 // The first non-signature thing better be a ')'
5663 if ((length > 0) && (*p++ == JVM_SIGNATURE_ENDFUNC)) {
5664 length--;
5665 if (name->utf8_length() > 0 && name->char_at(0) == '<') {
5666 // All constructor methods must return void
5667 if ((length == 1) && (p[0] == JVM_SIGNATURE_VOID)) {
5668 return args_size;
5669 }
5670 // All static init methods must return the current class
5671 if ((length >= 3) && (p[length-1] == JVM_SIGNATURE_ENDCLASS)
5672 && name == vmSymbols::object_initializer_name()) {
5673 nextp = skip_over_field_signature(p, true, length, CHECK_0);
5674 if (nextp && ((int)length == (nextp - p))) {
5675 // The actual class will be checked against current class
5676 // when the method is defined (see parse_method).
5677 // A reference to a static init with a bad return type
5678 // will load and verify OK, but will fail to link.
5679 return args_size;
5680 }
5681 }
5682 // The distinction between static factory methods and
5683 // constructors depends on the JVM_ACC_STATIC modifier.
5684 // This distinction must be reflected in a void or non-void
5685 // return. For declared methods, the check is in parse_method.
5686 } else {
5687 // Now we better just have a return value
5688 nextp = skip_over_field_signature(p, true, length, CHECK_0);
5689 if (nextp && ((int)length == (nextp - p))) {
5690 return args_size;
5691 }
5692 }
5693 }
5694 }
5695 // Report error
5696 throwIllegalSignature("Method", name, signature, CHECK_0);
5697 return 0;
5698 }
5699
5700 int ClassFileParser::static_field_size() const {
5701 assert(_field_info != NULL, "invariant");
5702 return _field_info->static_field_size;
5703 }
5704
5705 int ClassFileParser::total_oop_map_count() const {
|