396 }
397 if (resolved_klass->is_instance_klass()) {
398 return (Reflection::verify_class_access(accessing_klass->get_Klass(),
399 InstanceKlass::cast(resolved_klass),
400 true) == Reflection::ACCESS_OK);
401 }
402 return true;
403 }
404
405 // ------------------------------------------------------------------
406 // ciEnv::get_klass_by_name_impl
407 ciKlass* ciEnv::get_klass_by_name_impl(ciKlass* accessing_klass,
408 const constantPoolHandle& cpool,
409 ciSymbol* name,
410 bool require_local) {
411 ASSERT_IN_VM;
412 EXCEPTION_CONTEXT;
413
414 // Now we need to check the SystemDictionary
415 Symbol* sym = name->get_symbol();
416 if (sym->char_at(0) == JVM_SIGNATURE_CLASS &&
417 sym->char_at(sym->utf8_length()-1) == JVM_SIGNATURE_ENDCLASS) {
418 // This is a name from a signature. Strip off the trimmings.
419 // Call recursive to keep scope of strippedsym.
420 TempNewSymbol strippedsym = SymbolTable::new_symbol(sym->as_utf8()+1,
421 sym->utf8_length()-2);
422 ciSymbol* strippedname = get_symbol(strippedsym);
423 return get_klass_by_name_impl(accessing_klass, cpool, strippedname, require_local);
424 }
425
426 // Check for prior unloaded klass. The SystemDictionary's answers
427 // can vary over time but the compiler needs consistency.
428 ciKlass* unloaded_klass = check_get_unloaded_klass(accessing_klass, name);
429 if (unloaded_klass != NULL) {
430 if (require_local) return NULL;
431 return unloaded_klass;
432 }
433
434 Handle loader(THREAD, (oop)NULL);
435 Handle domain(THREAD, (oop)NULL);
436 if (accessing_klass != NULL) {
437 loader = Handle(THREAD, accessing_klass->loader());
438 domain = Handle(THREAD, accessing_klass->protection_domain());
439 }
440
441 // setup up the proper type to return on OOM
449 {
450 ttyUnlocker ttyul; // release tty lock to avoid ordering problems
451 MutexLocker ml(Compile_lock);
452 Klass* kls;
453 if (!require_local) {
454 kls = SystemDictionary::find_constrained_instance_or_array_klass(sym, loader,
455 KILL_COMPILE_ON_FATAL_(fail_type));
456 } else {
457 kls = SystemDictionary::find_instance_or_array_klass(sym, loader, domain,
458 KILL_COMPILE_ON_FATAL_(fail_type));
459 }
460 found_klass = kls;
461 }
462
463 // If we fail to find an array klass, look again for its element type.
464 // The element type may be available either locally or via constraints.
465 // In either case, if we can find the element type in the system dictionary,
466 // we must build an array type around it. The CI requires array klasses
467 // to be loaded if their element klasses are loaded, except when memory
468 // is exhausted.
469 if (sym->char_at(0) == JVM_SIGNATURE_ARRAY &&
470 (sym->char_at(1) == JVM_SIGNATURE_ARRAY || sym->char_at(1) == JVM_SIGNATURE_CLASS)) {
471 // We have an unloaded array.
472 // Build it on the fly if the element class exists.
473 TempNewSymbol elem_sym = SymbolTable::new_symbol(sym->as_utf8()+1,
474 sym->utf8_length()-1);
475
476 // Get element ciKlass recursively.
477 ciKlass* elem_klass =
478 get_klass_by_name_impl(accessing_klass,
479 cpool,
480 get_symbol(elem_sym),
481 require_local);
482 if (elem_klass != NULL && elem_klass->is_loaded()) {
483 // Now make an array for it
484 return ciObjArrayKlass::make_impl(elem_klass);
485 }
486 }
487
488 if (found_klass == NULL && !cpool.is_null() && cpool->has_preresolution()) {
489 // Look inside the constant pool for pre-resolved class entries.
490 for (int i = cpool->length() - 1; i >= 1; i--) {
491 if (cpool->tag_at(i).is_klass()) {
492 Klass* kls = cpool->resolved_klass_at(i);
493 if (kls->name() == sym) {
494 found_klass = kls;
495 break;
496 }
497 }
498 }
499 }
500
592 // ------------------------------------------------------------------
593 // ciEnv::get_constant_by_index_impl
594 //
595 // Implementation of get_constant_by_index().
596 ciConstant ciEnv::get_constant_by_index_impl(const constantPoolHandle& cpool,
597 int pool_index, int cache_index,
598 ciInstanceKlass* accessor) {
599 bool ignore_will_link;
600 EXCEPTION_CONTEXT;
601 int index = pool_index;
602 if (cache_index >= 0) {
603 assert(index < 0, "only one kind of index at a time");
604 index = cpool->object_to_cp_index(cache_index);
605 oop obj = cpool->resolved_references()->obj_at(cache_index);
606 if (obj != NULL) {
607 if (obj == Universe::the_null_sentinel()) {
608 return ciConstant(T_OBJECT, get_object(NULL));
609 }
610 BasicType bt = T_OBJECT;
611 if (cpool->tag_at(index).is_dynamic_constant())
612 bt = FieldType::basic_type(cpool->uncached_signature_ref_at(index));
613 if (is_reference_type(bt)) {
614 } else {
615 // we have to unbox the primitive value
616 if (!is_java_primitive(bt)) return ciConstant();
617 jvalue value;
618 BasicType bt2 = java_lang_boxing_object::get_value(obj, &value);
619 assert(bt2 == bt, "");
620 switch (bt2) {
621 case T_DOUBLE: return ciConstant(value.d);
622 case T_FLOAT: return ciConstant(value.f);
623 case T_LONG: return ciConstant(value.j);
624 case T_INT: return ciConstant(bt2, value.i);
625 case T_SHORT: return ciConstant(bt2, value.s);
626 case T_BYTE: return ciConstant(bt2, value.b);
627 case T_CHAR: return ciConstant(bt2, value.c);
628 case T_BOOLEAN: return ciConstant(bt2, value.z);
629 default: return ciConstant();
630 }
631 }
632 ciObject* ciobj = get_object(obj);
774 case Bytecodes::_invokeinterface:
775 dest_method =
776 LinkResolver::linktime_resolve_interface_method_or_null(link_info);
777 break;
778 case Bytecodes::_invokevirtual:
779 dest_method =
780 LinkResolver::linktime_resolve_virtual_method_or_null(link_info);
781 break;
782 default: ShouldNotReachHere();
783 }
784
785 return dest_method;
786 }
787
788
789 // ------------------------------------------------------------------
790 // ciEnv::get_method_by_index_impl
791 ciMethod* ciEnv::get_method_by_index_impl(const constantPoolHandle& cpool,
792 int index, Bytecodes::Code bc,
793 ciInstanceKlass* accessor) {
794 if (bc == Bytecodes::_invokedynamic) {
795 ConstantPoolCacheEntry* cpce = cpool->invokedynamic_cp_cache_entry_at(index);
796 bool is_resolved = !cpce->is_f1_null();
797 // FIXME: code generation could allow for null (unlinked) call site
798 // The call site could be made patchable as follows:
799 // Load the appendix argument from the constant pool.
800 // Test the appendix argument and jump to a known deopt routine if it is null.
801 // Jump through a patchable call site, which is initially a deopt routine.
802 // Patch the call site to the nmethod entry point of the static compiled lambda form.
803 // As with other two-component call sites, both values must be independently verified.
804
805 if (is_resolved) {
806 // Get the invoker Method* from the constant pool.
807 // (The appendix argument, if any, will be noted in the method's signature.)
808 Method* adapter = cpce->f1_as_method();
809 return get_method(adapter);
810 }
811
812 // Fake a method that is equivalent to a declared method.
813 ciInstanceKlass* holder = get_instance_klass(SystemDictionary::MethodHandle_klass());
|
396 }
397 if (resolved_klass->is_instance_klass()) {
398 return (Reflection::verify_class_access(accessing_klass->get_Klass(),
399 InstanceKlass::cast(resolved_klass),
400 true) == Reflection::ACCESS_OK);
401 }
402 return true;
403 }
404
405 // ------------------------------------------------------------------
406 // ciEnv::get_klass_by_name_impl
407 ciKlass* ciEnv::get_klass_by_name_impl(ciKlass* accessing_klass,
408 const constantPoolHandle& cpool,
409 ciSymbol* name,
410 bool require_local) {
411 ASSERT_IN_VM;
412 EXCEPTION_CONTEXT;
413
414 // Now we need to check the SystemDictionary
415 Symbol* sym = name->get_symbol();
416 if (Signature::has_envelope(sym)) {
417 // This is a name from a signature. Strip off the trimmings.
418 // Call recursive to keep scope of strippedsym.
419 TempNewSymbol strippedsym = Signature::strip_envelope(sym);
420 ciSymbol* strippedname = get_symbol(strippedsym);
421 return get_klass_by_name_impl(accessing_klass, cpool, strippedname, require_local);
422 }
423
424 // Check for prior unloaded klass. The SystemDictionary's answers
425 // can vary over time but the compiler needs consistency.
426 ciKlass* unloaded_klass = check_get_unloaded_klass(accessing_klass, name);
427 if (unloaded_klass != NULL) {
428 if (require_local) return NULL;
429 return unloaded_klass;
430 }
431
432 Handle loader(THREAD, (oop)NULL);
433 Handle domain(THREAD, (oop)NULL);
434 if (accessing_klass != NULL) {
435 loader = Handle(THREAD, accessing_klass->loader());
436 domain = Handle(THREAD, accessing_klass->protection_domain());
437 }
438
439 // setup up the proper type to return on OOM
447 {
448 ttyUnlocker ttyul; // release tty lock to avoid ordering problems
449 MutexLocker ml(Compile_lock);
450 Klass* kls;
451 if (!require_local) {
452 kls = SystemDictionary::find_constrained_instance_or_array_klass(sym, loader,
453 KILL_COMPILE_ON_FATAL_(fail_type));
454 } else {
455 kls = SystemDictionary::find_instance_or_array_klass(sym, loader, domain,
456 KILL_COMPILE_ON_FATAL_(fail_type));
457 }
458 found_klass = kls;
459 }
460
461 // If we fail to find an array klass, look again for its element type.
462 // The element type may be available either locally or via constraints.
463 // In either case, if we can find the element type in the system dictionary,
464 // we must build an array type around it. The CI requires array klasses
465 // to be loaded if their element klasses are loaded, except when memory
466 // is exhausted.
467 if (Signature::is_array(sym) &&
468 (sym->char_at(1) == JVM_SIGNATURE_ARRAY || sym->char_at(1) == JVM_SIGNATURE_CLASS)) {
469 // We have an unloaded array.
470 // Build it on the fly if the element class exists.
471 SignatureStream ss(sym, false);
472 ss.skip_array_prefix(1);
473 // Get element ciKlass recursively.
474 ciKlass* elem_klass =
475 get_klass_by_name_impl(accessing_klass,
476 cpool,
477 get_symbol(ss.as_symbol()),
478 require_local);
479 if (elem_klass != NULL && elem_klass->is_loaded()) {
480 // Now make an array for it
481 return ciObjArrayKlass::make_impl(elem_klass);
482 }
483 }
484
485 if (found_klass == NULL && !cpool.is_null() && cpool->has_preresolution()) {
486 // Look inside the constant pool for pre-resolved class entries.
487 for (int i = cpool->length() - 1; i >= 1; i--) {
488 if (cpool->tag_at(i).is_klass()) {
489 Klass* kls = cpool->resolved_klass_at(i);
490 if (kls->name() == sym) {
491 found_klass = kls;
492 break;
493 }
494 }
495 }
496 }
497
589 // ------------------------------------------------------------------
590 // ciEnv::get_constant_by_index_impl
591 //
592 // Implementation of get_constant_by_index().
593 ciConstant ciEnv::get_constant_by_index_impl(const constantPoolHandle& cpool,
594 int pool_index, int cache_index,
595 ciInstanceKlass* accessor) {
596 bool ignore_will_link;
597 EXCEPTION_CONTEXT;
598 int index = pool_index;
599 if (cache_index >= 0) {
600 assert(index < 0, "only one kind of index at a time");
601 index = cpool->object_to_cp_index(cache_index);
602 oop obj = cpool->resolved_references()->obj_at(cache_index);
603 if (obj != NULL) {
604 if (obj == Universe::the_null_sentinel()) {
605 return ciConstant(T_OBJECT, get_object(NULL));
606 }
607 BasicType bt = T_OBJECT;
608 if (cpool->tag_at(index).is_dynamic_constant())
609 bt = Signature::basic_type(cpool->uncached_signature_ref_at(index));
610 if (is_reference_type(bt)) {
611 } else {
612 // we have to unbox the primitive value
613 if (!is_java_primitive(bt)) return ciConstant();
614 jvalue value;
615 BasicType bt2 = java_lang_boxing_object::get_value(obj, &value);
616 assert(bt2 == bt, "");
617 switch (bt2) {
618 case T_DOUBLE: return ciConstant(value.d);
619 case T_FLOAT: return ciConstant(value.f);
620 case T_LONG: return ciConstant(value.j);
621 case T_INT: return ciConstant(bt2, value.i);
622 case T_SHORT: return ciConstant(bt2, value.s);
623 case T_BYTE: return ciConstant(bt2, value.b);
624 case T_CHAR: return ciConstant(bt2, value.c);
625 case T_BOOLEAN: return ciConstant(bt2, value.z);
626 default: return ciConstant();
627 }
628 }
629 ciObject* ciobj = get_object(obj);
771 case Bytecodes::_invokeinterface:
772 dest_method =
773 LinkResolver::linktime_resolve_interface_method_or_null(link_info);
774 break;
775 case Bytecodes::_invokevirtual:
776 dest_method =
777 LinkResolver::linktime_resolve_virtual_method_or_null(link_info);
778 break;
779 default: ShouldNotReachHere();
780 }
781
782 return dest_method;
783 }
784
785
786 // ------------------------------------------------------------------
787 // ciEnv::get_method_by_index_impl
788 ciMethod* ciEnv::get_method_by_index_impl(const constantPoolHandle& cpool,
789 int index, Bytecodes::Code bc,
790 ciInstanceKlass* accessor) {
791 assert(cpool.not_null(), "need constant pool");
792 assert(accessor != NULL, "need origin of access");
793 if (bc == Bytecodes::_invokedynamic) {
794 ConstantPoolCacheEntry* cpce = cpool->invokedynamic_cp_cache_entry_at(index);
795 bool is_resolved = !cpce->is_f1_null();
796 // FIXME: code generation could allow for null (unlinked) call site
797 // The call site could be made patchable as follows:
798 // Load the appendix argument from the constant pool.
799 // Test the appendix argument and jump to a known deopt routine if it is null.
800 // Jump through a patchable call site, which is initially a deopt routine.
801 // Patch the call site to the nmethod entry point of the static compiled lambda form.
802 // As with other two-component call sites, both values must be independently verified.
803
804 if (is_resolved) {
805 // Get the invoker Method* from the constant pool.
806 // (The appendix argument, if any, will be noted in the method's signature.)
807 Method* adapter = cpce->f1_as_method();
808 return get_method(adapter);
809 }
810
811 // Fake a method that is equivalent to a declared method.
812 ciInstanceKlass* holder = get_instance_klass(SystemDictionary::MethodHandle_klass());
|