464 // which only calls the superclass vanilla constructor and possibly does stores of
465 // zero constants to local fields:
466 //
467 // aload_0
468 // invokespecial
469 // indexbyte1
470 // indexbyte2
471 //
472 // followed by an (optional) sequence of:
473 //
474 // aload_0
475 // aconst_null / iconst_0 / fconst_0 / dconst_0
476 // putfield
477 // indexbyte1
478 // indexbyte2
479 //
480 // followed by:
481 //
482 // return
483
484 assert(name() == vmSymbols::object_initializer_name(), "Should only be called for default constructors");
485 assert(signature() == vmSymbols::void_method_signature(), "Should only be called for default constructors");
486 int size = code_size();
487 // Check if size match
488 if (size == 0 || size % 5 != 0) return false;
489 address cb = code_base();
490 int last = size - 1;
491 if (cb[0] != Bytecodes::_aload_0 || cb[1] != Bytecodes::_invokespecial || cb[last] != Bytecodes::_return) {
492 // Does not call superclass default constructor
493 return false;
494 }
495 // Check optional sequence
496 for (int i = 4; i < last; i += 5) {
497 if (cb[i] != Bytecodes::_aload_0) return false;
498 if (!Bytecodes::is_zero_const(Bytecodes::cast(cb[i+1]))) return false;
499 if (cb[i+2] != Bytecodes::_putfield) return false;
500 }
501 return true;
502 }
503
504
505 bool Method::compute_has_loops_flag() {
582 if (code_size() != 5) return false;
583 if (size_of_parameters() != 1) return false;
584 if (java_code_at(0) != Bytecodes::_aload_0 ) return false;
585 if (java_code_at(1) != Bytecodes::_getfield) return false;
586 if (java_code_at(4) != Bytecodes::_areturn &&
587 java_code_at(4) != Bytecodes::_ireturn ) return false;
588 return true;
589 }
590
591 bool Method::is_constant_getter() const {
592 int last_index = code_size() - 1;
593 // Check if the first 1-3 bytecodes are a constant push
594 // and the last bytecode is a return.
595 return (2 <= code_size() && code_size() <= 4 &&
596 Bytecodes::is_const(java_code_at(0)) &&
597 Bytecodes::length_for(java_code_at(0)) == last_index &&
598 Bytecodes::is_return(java_code_at(last_index)));
599 }
600
601 bool Method::is_initializer() const {
602 return name() == vmSymbols::object_initializer_name() || is_static_initializer();
603 }
604
605 bool Method::has_valid_initializer_flags() const {
606 return (is_static() ||
607 method_holder()->major_version() < 51);
608 }
609
610 bool Method::is_static_initializer() const {
611 // For classfiles version 51 or greater, ensure that the clinit method is
612 // static. Non-static methods with the name "<clinit>" are not static
613 // initializers. (older classfiles exempted for backward compatibility)
614 return name() == vmSymbols::class_initializer_name() &&
615 has_valid_initializer_flags();
616 }
617
618
619 objArrayHandle Method::resolved_checked_exceptions_impl(Method* method, TRAPS) {
620 int length = method->checked_exceptions_length();
621 if (length == 0) { // common case
622 return objArrayHandle(THREAD, Universe::the_empty_class_klass_array());
623 } else {
624 methodHandle h_this(THREAD, method);
625 objArrayOop m_oop = oopFactory::new_objArray(SystemDictionary::Class_klass(), length, CHECK_(objArrayHandle()));
626 objArrayHandle mirrors (THREAD, m_oop);
627 for (int i = 0; i < length; i++) {
628 CheckedExceptionElement* table = h_this->checked_exceptions_start(); // recompute on each iteration, not gc safe
629 Klass* k = h_this->constants()->klass_at(table[i].class_cp_index, CHECK_(objArrayHandle()));
630 assert(k->is_subclass_of(SystemDictionary::Throwable_klass()), "invalid exception class");
631 mirrors->obj_at_put(i, k->java_mirror());
632 }
633 return mirrors;
634 }
1131 cp->set_has_preresolution();
1132
1133 // decide on access bits: public or not?
1134 int flags_bits = (JVM_ACC_NATIVE | JVM_ACC_SYNTHETIC | JVM_ACC_FINAL);
1135 bool must_be_static = MethodHandles::is_signature_polymorphic_static(iid);
1136 if (must_be_static) flags_bits |= JVM_ACC_STATIC;
1137 assert((flags_bits & JVM_ACC_PUBLIC) == 0, "do not expose these methods");
1138
1139 methodHandle m;
1140 {
1141 InlineTableSizes sizes;
1142 Method* m_oop = Method::allocate(loader_data, 0,
1143 accessFlags_from(flags_bits), &sizes,
1144 ConstMethod::NORMAL, CHECK_(empty));
1145 m = methodHandle(THREAD, m_oop);
1146 }
1147 m->set_constants(cp());
1148 m->set_name_index(_imcp_invoke_name);
1149 m->set_signature_index(_imcp_invoke_signature);
1150 assert(MethodHandles::is_signature_polymorphic_name(m->name()), "");
1151 assert(m->signature() == signature, "");
1152 #ifdef CC_INTERP
1153 ResultTypeFinder rtf(signature);
1154 m->set_result_index(rtf.type());
1155 #endif
1156 m->compute_size_of_parameters(THREAD);
1157 m->init_intrinsic_id();
1158 assert(m->is_method_handle_intrinsic(), "");
1159 #ifdef ASSERT
1160 if (!MethodHandles::is_signature_polymorphic(m->intrinsic_id())) m->print();
1161 assert(MethodHandles::is_signature_polymorphic(m->intrinsic_id()), "must be an invoker");
1162 assert(m->intrinsic_id() == iid, "correctly predicted iid");
1163 #endif //ASSERT
1164
1165 // Finally, set up its entry points.
1166 assert(m->can_be_statically_bound(), "");
1167 m->set_vtable_index(Method::nonvirtual_vtable_index);
1168 m->link_method(m, CHECK_(empty));
1169
1170 if (TraceMethodHandles && (Verbose || WizardMode))
1171 m->print_on(tty);
|
464 // which only calls the superclass vanilla constructor and possibly does stores of
465 // zero constants to local fields:
466 //
467 // aload_0
468 // invokespecial
469 // indexbyte1
470 // indexbyte2
471 //
472 // followed by an (optional) sequence of:
473 //
474 // aload_0
475 // aconst_null / iconst_0 / fconst_0 / dconst_0
476 // putfield
477 // indexbyte1
478 // indexbyte2
479 //
480 // followed by:
481 //
482 // return
483
484 assert(name()->equals(vmSymbols::object_initializer_name()), "Should only be called for default constructors");
485 assert(signature()->equals(vmSymbols::void_method_signature()), "Should only be called for default constructors");
486 int size = code_size();
487 // Check if size match
488 if (size == 0 || size % 5 != 0) return false;
489 address cb = code_base();
490 int last = size - 1;
491 if (cb[0] != Bytecodes::_aload_0 || cb[1] != Bytecodes::_invokespecial || cb[last] != Bytecodes::_return) {
492 // Does not call superclass default constructor
493 return false;
494 }
495 // Check optional sequence
496 for (int i = 4; i < last; i += 5) {
497 if (cb[i] != Bytecodes::_aload_0) return false;
498 if (!Bytecodes::is_zero_const(Bytecodes::cast(cb[i+1]))) return false;
499 if (cb[i+2] != Bytecodes::_putfield) return false;
500 }
501 return true;
502 }
503
504
505 bool Method::compute_has_loops_flag() {
582 if (code_size() != 5) return false;
583 if (size_of_parameters() != 1) return false;
584 if (java_code_at(0) != Bytecodes::_aload_0 ) return false;
585 if (java_code_at(1) != Bytecodes::_getfield) return false;
586 if (java_code_at(4) != Bytecodes::_areturn &&
587 java_code_at(4) != Bytecodes::_ireturn ) return false;
588 return true;
589 }
590
591 bool Method::is_constant_getter() const {
592 int last_index = code_size() - 1;
593 // Check if the first 1-3 bytecodes are a constant push
594 // and the last bytecode is a return.
595 return (2 <= code_size() && code_size() <= 4 &&
596 Bytecodes::is_const(java_code_at(0)) &&
597 Bytecodes::length_for(java_code_at(0)) == last_index &&
598 Bytecodes::is_return(java_code_at(last_index)));
599 }
600
601 bool Method::is_initializer() const {
602 return name()->equals(vmSymbols::object_initializer_name()) || is_static_initializer();
603 }
604
605 bool Method::has_valid_initializer_flags() const {
606 return (is_static() ||
607 method_holder()->major_version() < 51);
608 }
609
610 bool Method::is_static_initializer() const {
611 // For classfiles version 51 or greater, ensure that the clinit method is
612 // static. Non-static methods with the name "<clinit>" are not static
613 // initializers. (older classfiles exempted for backward compatibility)
614 return name()->equals(vmSymbols::class_initializer_name()) &&
615 has_valid_initializer_flags();
616 }
617
618
619 objArrayHandle Method::resolved_checked_exceptions_impl(Method* method, TRAPS) {
620 int length = method->checked_exceptions_length();
621 if (length == 0) { // common case
622 return objArrayHandle(THREAD, Universe::the_empty_class_klass_array());
623 } else {
624 methodHandle h_this(THREAD, method);
625 objArrayOop m_oop = oopFactory::new_objArray(SystemDictionary::Class_klass(), length, CHECK_(objArrayHandle()));
626 objArrayHandle mirrors (THREAD, m_oop);
627 for (int i = 0; i < length; i++) {
628 CheckedExceptionElement* table = h_this->checked_exceptions_start(); // recompute on each iteration, not gc safe
629 Klass* k = h_this->constants()->klass_at(table[i].class_cp_index, CHECK_(objArrayHandle()));
630 assert(k->is_subclass_of(SystemDictionary::Throwable_klass()), "invalid exception class");
631 mirrors->obj_at_put(i, k->java_mirror());
632 }
633 return mirrors;
634 }
1131 cp->set_has_preresolution();
1132
1133 // decide on access bits: public or not?
1134 int flags_bits = (JVM_ACC_NATIVE | JVM_ACC_SYNTHETIC | JVM_ACC_FINAL);
1135 bool must_be_static = MethodHandles::is_signature_polymorphic_static(iid);
1136 if (must_be_static) flags_bits |= JVM_ACC_STATIC;
1137 assert((flags_bits & JVM_ACC_PUBLIC) == 0, "do not expose these methods");
1138
1139 methodHandle m;
1140 {
1141 InlineTableSizes sizes;
1142 Method* m_oop = Method::allocate(loader_data, 0,
1143 accessFlags_from(flags_bits), &sizes,
1144 ConstMethod::NORMAL, CHECK_(empty));
1145 m = methodHandle(THREAD, m_oop);
1146 }
1147 m->set_constants(cp());
1148 m->set_name_index(_imcp_invoke_name);
1149 m->set_signature_index(_imcp_invoke_signature);
1150 assert(MethodHandles::is_signature_polymorphic_name(m->name()), "");
1151 assert(m->signature()->equals(signature), "");
1152 #ifdef CC_INTERP
1153 ResultTypeFinder rtf(signature);
1154 m->set_result_index(rtf.type());
1155 #endif
1156 m->compute_size_of_parameters(THREAD);
1157 m->init_intrinsic_id();
1158 assert(m->is_method_handle_intrinsic(), "");
1159 #ifdef ASSERT
1160 if (!MethodHandles::is_signature_polymorphic(m->intrinsic_id())) m->print();
1161 assert(MethodHandles::is_signature_polymorphic(m->intrinsic_id()), "must be an invoker");
1162 assert(m->intrinsic_id() == iid, "correctly predicted iid");
1163 #endif //ASSERT
1164
1165 // Finally, set up its entry points.
1166 assert(m->can_be_statically_bound(), "");
1167 m->set_vtable_index(Method::nonvirtual_vtable_index);
1168 m->link_method(m, CHECK_(empty));
1169
1170 if (TraceMethodHandles && (Verbose || WizardMode))
1171 m->print_on(tty);
|