< prev index next >
src/share/vm/jvmci/jvmciEnv.cpp
Print this page
*** 63,94 ****
}
// ------------------------------------------------------------------
// Note: the logic of this method should mirror the logic of
// constantPoolOopDesc::verify_constant_pool_resolve.
! bool JVMCIEnv::check_klass_accessibility(KlassHandle accessing_klass, KlassHandle resolved_klass) {
if (accessing_klass->is_objArray_klass()) {
! accessing_klass = ObjArrayKlass::cast(accessing_klass())->bottom_klass();
}
if (!accessing_klass->is_instance_klass()) {
return true;
}
if (resolved_klass->is_objArray_klass()) {
// Find the element klass, if this is an array.
! resolved_klass = ObjArrayKlass::cast(resolved_klass())->bottom_klass();
}
if (resolved_klass->is_instance_klass()) {
Reflection::VerifyClassAccessResults result =
! Reflection::verify_class_access(accessing_klass(), InstanceKlass::cast(resolved_klass()), true);
return result == Reflection::ACCESS_OK;
}
return true;
}
// ------------------------------------------------------------------
! KlassHandle JVMCIEnv::get_klass_by_name_impl(KlassHandle& accessing_klass,
const constantPoolHandle& cpool,
Symbol* sym,
bool require_local) {
JVMCI_EXCEPTION_CONTEXT;
--- 63,94 ----
}
// ------------------------------------------------------------------
// Note: the logic of this method should mirror the logic of
// constantPoolOopDesc::verify_constant_pool_resolve.
! bool JVMCIEnv::check_klass_accessibility(Klass* accessing_klass, Klass* resolved_klass) {
if (accessing_klass->is_objArray_klass()) {
! accessing_klass = ObjArrayKlass::cast(accessing_klass)->bottom_klass();
}
if (!accessing_klass->is_instance_klass()) {
return true;
}
if (resolved_klass->is_objArray_klass()) {
// Find the element klass, if this is an array.
! resolved_klass = ObjArrayKlass::cast(resolved_klass)->bottom_klass();
}
if (resolved_klass->is_instance_klass()) {
Reflection::VerifyClassAccessResults result =
! Reflection::verify_class_access(accessing_klass, InstanceKlass::cast(resolved_klass), true);
return result == Reflection::ACCESS_OK;
}
return true;
}
// ------------------------------------------------------------------
! Klass* JVMCIEnv::get_klass_by_name_impl(Klass* accessing_klass,
const constantPoolHandle& cpool,
Symbol* sym,
bool require_local) {
JVMCI_EXCEPTION_CONTEXT;
*** 97,128 ****
sym->byte_at(sym->utf8_length()-1) == ';') {
// This is a name from a signature. Strip off the trimmings.
// Call recursive to keep scope of strippedsym.
TempNewSymbol strippedsym = SymbolTable::new_symbol(sym->as_utf8()+1,
sym->utf8_length()-2,
! CHECK_(KlassHandle()));
return get_klass_by_name_impl(accessing_klass, cpool, strippedsym, require_local);
}
Handle loader(THREAD, (oop)NULL);
Handle domain(THREAD, (oop)NULL);
! if (!accessing_klass.is_null()) {
loader = Handle(THREAD, accessing_klass->class_loader());
domain = Handle(THREAD, accessing_klass->protection_domain());
}
! KlassHandle found_klass;
{
ttyUnlocker ttyul; // release tty lock to avoid ordering problems
MutexLocker ml(Compile_lock);
- Klass* kls;
if (!require_local) {
! kls = SystemDictionary::find_constrained_instance_or_array_klass(sym, loader, CHECK_(KlassHandle()));
} else {
! kls = SystemDictionary::find_instance_or_array_klass(sym, loader, domain, CHECK_(KlassHandle()));
}
- found_klass = KlassHandle(THREAD, kls);
}
// If we fail to find an array klass, look again for its element type.
// The element type may be available either locally or via constraints.
// In either case, if we can find the element type in the system dictionary,
--- 97,126 ----
sym->byte_at(sym->utf8_length()-1) == ';') {
// This is a name from a signature. Strip off the trimmings.
// Call recursive to keep scope of strippedsym.
TempNewSymbol strippedsym = SymbolTable::new_symbol(sym->as_utf8()+1,
sym->utf8_length()-2,
! CHECK_NULL);
return get_klass_by_name_impl(accessing_klass, cpool, strippedsym, require_local);
}
Handle loader(THREAD, (oop)NULL);
Handle domain(THREAD, (oop)NULL);
! if (accessing_klass != NULL) {
loader = Handle(THREAD, accessing_klass->class_loader());
domain = Handle(THREAD, accessing_klass->protection_domain());
}
! Klass* found_klass = NULL;
{
ttyUnlocker ttyul; // release tty lock to avoid ordering problems
MutexLocker ml(Compile_lock);
if (!require_local) {
! found_klass = SystemDictionary::find_constrained_instance_or_array_klass(sym, loader, CHECK_NULL);
} else {
! found_klass = SystemDictionary::find_instance_or_array_klass(sym, loader, domain, CHECK_NULL);
}
}
// If we fail to find an array klass, look again for its element type.
// The element type may be available either locally or via constraints.
// In either case, if we can find the element type in the system dictionary,
*** 133,157 ****
(sym->byte_at(1) == '[' || sym->byte_at(1) == 'L')) {
// We have an unloaded array.
// Build it on the fly if the element class exists.
TempNewSymbol elem_sym = SymbolTable::new_symbol(sym->as_utf8()+1,
sym->utf8_length()-1,
! CHECK_(KlassHandle()));
// Get element Klass recursively.
! KlassHandle elem_klass =
get_klass_by_name_impl(accessing_klass,
cpool,
elem_sym,
require_local);
! if (!elem_klass.is_null()) {
// Now make an array for it
! return elem_klass->array_klass(CHECK_(KlassHandle()));
}
}
! if (found_klass.is_null() && !cpool.is_null() && cpool->has_preresolution()) {
// Look inside the constant pool for pre-resolved class entries.
for (int i = cpool->length() - 1; i >= 1; i--) {
if (cpool->tag_at(i).is_klass()) {
Klass* kls = cpool->resolved_klass_at(i);
if (kls->name() == sym) {
--- 131,155 ----
(sym->byte_at(1) == '[' || sym->byte_at(1) == 'L')) {
// We have an unloaded array.
// Build it on the fly if the element class exists.
TempNewSymbol elem_sym = SymbolTable::new_symbol(sym->as_utf8()+1,
sym->utf8_length()-1,
! CHECK_NULL);
// Get element Klass recursively.
! Klass* elem_klass =
get_klass_by_name_impl(accessing_klass,
cpool,
elem_sym,
require_local);
! if (elem_klass != NULL) {
// Now make an array for it
! return elem_klass->array_klass(CHECK_NULL);
}
}
! if (found_klass == NULL && !cpool.is_null() && cpool->has_preresolution()) {
// Look inside the constant pool for pre-resolved class entries.
for (int i = cpool->length() - 1; i >= 1; i--) {
if (cpool->tag_at(i).is_klass()) {
Klass* kls = cpool->resolved_klass_at(i);
if (kls->name() == sym) {
*** 159,173 ****
}
}
}
}
! return found_klass();
}
// ------------------------------------------------------------------
! KlassHandle JVMCIEnv::get_klass_by_name(KlassHandle accessing_klass,
Symbol* klass_name,
bool require_local) {
ResourceMark rm;
constantPoolHandle cpool;
return get_klass_by_name_impl(accessing_klass,
--- 157,171 ----
}
}
}
}
! return found_klass;
}
// ------------------------------------------------------------------
! Klass* JVMCIEnv::get_klass_by_name(Klass* accessing_klass,
Symbol* klass_name,
bool require_local) {
ResourceMark rm;
constantPoolHandle cpool;
return get_klass_by_name_impl(accessing_klass,
*** 176,215 ****
require_local);
}
// ------------------------------------------------------------------
// Implementation of get_klass_by_index.
! KlassHandle JVMCIEnv::get_klass_by_index_impl(const constantPoolHandle& cpool,
int index,
bool& is_accessible,
! KlassHandle accessor) {
JVMCI_EXCEPTION_CONTEXT;
! KlassHandle klass (THREAD, ConstantPool::klass_at_if_loaded(cpool, index));
Symbol* klass_name = NULL;
! if (klass.is_null()) {
klass_name = cpool->klass_name_at(index);
}
! if (klass.is_null()) {
// Not found in constant pool. Use the name to do the lookup.
! KlassHandle k = get_klass_by_name_impl(accessor,
cpool,
klass_name,
false);
// Calculate accessibility the hard way.
! if (k.is_null()) {
is_accessible = false;
} else if (k->class_loader() != accessor->class_loader() &&
! get_klass_by_name_impl(accessor, cpool, k->name(), true).is_null()) {
// Loaded only remotely. Not linked yet.
is_accessible = false;
} else {
// Linked locally, and we must also check public/private, etc.
is_accessible = check_klass_accessibility(accessor, k);
}
if (!is_accessible) {
! return KlassHandle();
}
return k;
}
// It is known to be accessible, since it was found in the constant pool.
--- 174,213 ----
require_local);
}
// ------------------------------------------------------------------
// Implementation of get_klass_by_index.
! Klass* JVMCIEnv::get_klass_by_index_impl(const constantPoolHandle& cpool,
int index,
bool& is_accessible,
! Klass* accessor) {
JVMCI_EXCEPTION_CONTEXT;
! Klass* klass = ConstantPool::klass_at_if_loaded(cpool, index);
Symbol* klass_name = NULL;
! if (klass == NULL) {
klass_name = cpool->klass_name_at(index);
}
! if (klass == NULL) {
// Not found in constant pool. Use the name to do the lookup.
! Klass* k = get_klass_by_name_impl(accessor,
cpool,
klass_name,
false);
// Calculate accessibility the hard way.
! if (k == NULL) {
is_accessible = false;
} else if (k->class_loader() != accessor->class_loader() &&
! get_klass_by_name_impl(accessor, cpool, k->name(), true) == NULL) {
// Loaded only remotely. Not linked yet.
is_accessible = false;
} else {
// Linked locally, and we must also check public/private, etc.
is_accessible = check_klass_accessibility(accessor, k);
}
if (!is_accessible) {
! return NULL;
}
return k;
}
// It is known to be accessible, since it was found in the constant pool.
*** 217,241 ****
return klass;
}
// ------------------------------------------------------------------
// Get a klass from the constant pool.
! KlassHandle JVMCIEnv::get_klass_by_index(const constantPoolHandle& cpool,
int index,
bool& is_accessible,
! KlassHandle accessor) {
ResourceMark rm;
! KlassHandle result = get_klass_by_index_impl(cpool, index, is_accessible, accessor);
! return result;
}
// ------------------------------------------------------------------
// Implementation of get_field_by_index.
//
// Implementation note: the results of field lookups are cached
// in the accessor klass.
! void JVMCIEnv::get_field_by_index_impl(instanceKlassHandle klass, fieldDescriptor& field_desc,
int index) {
JVMCI_EXCEPTION_CONTEXT;
assert(klass->is_linked(), "must be linked before using its constant-pool");
--- 215,238 ----
return klass;
}
// ------------------------------------------------------------------
// Get a klass from the constant pool.
! Klass* JVMCIEnv::get_klass_by_index(const constantPoolHandle& cpool,
int index,
bool& is_accessible,
! Klass* accessor) {
ResourceMark rm;
! return get_klass_by_index_impl(cpool, index, is_accessible, accessor);
}
// ------------------------------------------------------------------
// Implementation of get_field_by_index.
//
// Implementation note: the results of field lookups are cached
// in the accessor klass.
! void JVMCIEnv::get_field_by_index_impl(InstanceKlass* klass, fieldDescriptor& field_desc,
int index) {
JVMCI_EXCEPTION_CONTEXT;
assert(klass->is_linked(), "must be linked before using its constant-pool");
*** 249,259 ****
Symbol* signature = cpool->symbol_at(sig_index);
// Get the field's declared holder.
int holder_index = cpool->klass_ref_index_at(index);
bool holder_is_accessible;
! KlassHandle declared_holder = get_klass_by_index(cpool, holder_index,
holder_is_accessible,
klass);
// The declared holder of this field may not have been loaded.
// Bail out with partial field information.
--- 246,256 ----
Symbol* signature = cpool->symbol_at(sig_index);
// Get the field's declared holder.
int holder_index = cpool->klass_ref_index_at(index);
bool holder_is_accessible;
! Klass* declared_holder = get_klass_by_index(cpool, holder_index,
holder_is_accessible,
klass);
// The declared holder of this field may not have been loaded.
// Bail out with partial field information.
*** 262,291 ****
}
// Perform the field lookup.
Klass* canonical_holder =
! InstanceKlass::cast(declared_holder())->find_field(name, signature, &field_desc);
if (canonical_holder == NULL) {
return;
}
assert(canonical_holder == field_desc.field_holder(), "just checking");
}
// ------------------------------------------------------------------
// Get a field by index from a klass's constant pool.
! void JVMCIEnv::get_field_by_index(instanceKlassHandle accessor, fieldDescriptor& fd, int index) {
ResourceMark rm;
return get_field_by_index_impl(accessor, fd, index);
}
// ------------------------------------------------------------------
// Perform an appropriate method lookup based on accessor, holder,
// name, signature, and bytecode.
! methodHandle JVMCIEnv::lookup_method(instanceKlassHandle h_accessor,
! instanceKlassHandle h_holder,
Symbol* name,
Symbol* sig,
Bytecodes::Code bc,
constantTag tag) {
JVMCI_EXCEPTION_CONTEXT;
--- 259,288 ----
}
// Perform the field lookup.
Klass* canonical_holder =
! InstanceKlass::cast(declared_holder)->find_field(name, signature, &field_desc);
if (canonical_holder == NULL) {
return;
}
assert(canonical_holder == field_desc.field_holder(), "just checking");
}
// ------------------------------------------------------------------
// Get a field by index from a klass's constant pool.
! void JVMCIEnv::get_field_by_index(InstanceKlass* accessor, fieldDescriptor& fd, int index) {
ResourceMark rm;
return get_field_by_index_impl(accessor, fd, index);
}
// ------------------------------------------------------------------
// Perform an appropriate method lookup based on accessor, holder,
// name, signature, and bytecode.
! methodHandle JVMCIEnv::lookup_method(InstanceKlass* h_accessor,
! InstanceKlass* h_holder,
Symbol* name,
Symbol* sig,
Bytecodes::Code bc,
constantTag tag) {
JVMCI_EXCEPTION_CONTEXT;
*** 317,327 ****
// ------------------------------------------------------------------
methodHandle JVMCIEnv::get_method_by_index_impl(const constantPoolHandle& cpool,
int index, Bytecodes::Code bc,
! instanceKlassHandle accessor) {
if (bc == Bytecodes::_invokedynamic) {
ConstantPoolCacheEntry* cpce = cpool->invokedynamic_cp_cache_entry_at(index);
bool is_resolved = !cpce->is_f1_null();
if (is_resolved) {
// Get the invoker Method* from the constant pool.
--- 314,324 ----
// ------------------------------------------------------------------
methodHandle JVMCIEnv::get_method_by_index_impl(const constantPoolHandle& cpool,
int index, Bytecodes::Code bc,
! InstanceKlass* accessor) {
if (bc == Bytecodes::_invokedynamic) {
ConstantPoolCacheEntry* cpce = cpool->invokedynamic_cp_cache_entry_at(index);
bool is_resolved = !cpce->is_f1_null();
if (is_resolved) {
// Get the invoker Method* from the constant pool.
*** 333,351 ****
return NULL;
}
int holder_index = cpool->klass_ref_index_at(index);
bool holder_is_accessible;
! KlassHandle holder = get_klass_by_index_impl(cpool, holder_index, holder_is_accessible, accessor);
// Get the method's name and signature.
Symbol* name_sym = cpool->name_ref_at(index);
Symbol* sig_sym = cpool->signature_ref_at(index);
if (cpool->has_preresolution()
! || ((holder() == SystemDictionary::MethodHandle_klass() || holder() == SystemDictionary::VarHandle_klass()) &&
! MethodHandles::is_signature_polymorphic_name(holder(), name_sym))) {
// Short-circuit lookups for JSR 292-related call sites.
// That is, do not rely only on name-based lookups, because they may fail
// if the names are not resolvable in the boot class loader (7056328).
switch (bc) {
case Bytecodes::_invokevirtual:
--- 330,348 ----
return NULL;
}
int holder_index = cpool->klass_ref_index_at(index);
bool holder_is_accessible;
! Klass* holder = get_klass_by_index_impl(cpool, holder_index, holder_is_accessible, accessor);
// Get the method's name and signature.
Symbol* name_sym = cpool->name_ref_at(index);
Symbol* sig_sym = cpool->signature_ref_at(index);
if (cpool->has_preresolution()
! || ((holder == SystemDictionary::MethodHandle_klass() || holder == SystemDictionary::VarHandle_klass()) &&
! MethodHandles::is_signature_polymorphic_name(holder, name_sym))) {
// Short-circuit lookups for JSR 292-related call sites.
// That is, do not rely only on name-based lookups, because they may fail
// if the names are not resolvable in the boot class loader (7056328).
switch (bc) {
case Bytecodes::_invokevirtual:
*** 361,371 ****
break;
}
}
if (holder_is_accessible) { // Our declared holder is loaded.
! instanceKlassHandle lookup = get_instance_klass_for_declared_method_holder(holder);
constantTag tag = cpool->tag_ref_at(index);
methodHandle m = lookup_method(accessor, lookup, name_sym, sig_sym, bc, tag);
if (!m.is_null() &&
(bc == Bytecodes::_invokestatic
? InstanceKlass::cast(m->method_holder())->is_not_initialized()
--- 358,368 ----
break;
}
}
if (holder_is_accessible) { // Our declared holder is loaded.
! InstanceKlass* lookup = get_instance_klass_for_declared_method_holder(holder);
constantTag tag = cpool->tag_ref_at(index);
methodHandle m = lookup_method(accessor, lookup, name_sym, sig_sym, bc, tag);
if (!m.is_null() &&
(bc == Bytecodes::_invokestatic
? InstanceKlass::cast(m->method_holder())->is_not_initialized()
*** 383,411 ****
return NULL;
}
// ------------------------------------------------------------------
! instanceKlassHandle JVMCIEnv::get_instance_klass_for_declared_method_holder(KlassHandle method_holder) {
// For the case of <array>.clone(), the method holder can be an ArrayKlass*
// instead of an InstanceKlass*. For that case simply pretend that the
// declared holder is Object.clone since that's where the call will bottom out.
if (method_holder->is_instance_klass()) {
! return instanceKlassHandle(method_holder());
} else if (method_holder->is_array_klass()) {
! return instanceKlassHandle(SystemDictionary::Object_klass());
} else {
ShouldNotReachHere();
}
return NULL;
}
// ------------------------------------------------------------------
methodHandle JVMCIEnv::get_method_by_index(const constantPoolHandle& cpool,
int index, Bytecodes::Code bc,
! instanceKlassHandle accessor) {
ResourceMark rm;
return get_method_by_index_impl(cpool, index, bc, accessor);
}
// ------------------------------------------------------------------
--- 380,408 ----
return NULL;
}
// ------------------------------------------------------------------
! InstanceKlass* JVMCIEnv::get_instance_klass_for_declared_method_holder(Klass* method_holder) {
// For the case of <array>.clone(), the method holder can be an ArrayKlass*
// instead of an InstanceKlass*. For that case simply pretend that the
// declared holder is Object.clone since that's where the call will bottom out.
if (method_holder->is_instance_klass()) {
! return InstanceKlass::cast(method_holder);
} else if (method_holder->is_array_klass()) {
! return SystemDictionary::Object_klass();
} else {
ShouldNotReachHere();
}
return NULL;
}
// ------------------------------------------------------------------
methodHandle JVMCIEnv::get_method_by_index(const constantPoolHandle& cpool,
int index, Bytecodes::Code bc,
! InstanceKlass* accessor) {
ResourceMark rm;
return get_method_by_index_impl(cpool, index, bc, accessor);
}
// ------------------------------------------------------------------
< prev index next >