8247938: Change various JVM enums like LinkInfo::AccessCheck and Klass::DefaultsLookupMode to enum class

Use C++11 scoped enumeration declarations for several different Klass and LinkInfo enumerations.

Reviewed-by: coleenp, hseigel, kbarrett
This commit is contained in:
Lois Foltan 2020-08-06 18:13:56 +00:00
parent 99c7b2b85b
commit deaadfad52
17 changed files with 66 additions and 60 deletions

@ -761,7 +761,7 @@ Method* ciEnv::lookup_method(ciInstanceKlass* accessor,
InstanceKlass* accessor_klass = accessor->get_instanceKlass();
Klass* holder_klass = holder->get_Klass();
Method* dest_method;
LinkInfo link_info(holder_klass, name, sig, accessor_klass, LinkInfo::needs_access_check, tag);
LinkInfo link_info(holder_klass, name, sig, accessor_klass, LinkInfo::AccessCheck::required, tag);
switch (bc) {
case Bytecodes::_invokestatic:
dest_method =

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -809,7 +809,7 @@ ciMethod* ciMethod::resolve_invoke(ciKlass* caller, ciKlass* exact_receiver, boo
Symbol* h_signature = signature()->get_symbol();
LinkInfo link_info(resolved, h_name, h_signature, caller_klass,
check_access ? LinkInfo::needs_access_check : LinkInfo::skip_access_check);
check_access ? LinkInfo::AccessCheck::required : LinkInfo::AccessCheck::skip);
Method* m = NULL;
// Only do exact lookup if receiver klass has been linked. Otherwise,
// the vtable has not been setup, and the LinkResolver will fail.

@ -3237,7 +3237,7 @@ oop java_lang_reflect_RecordComponent::create(InstanceKlass* holder, RecordCompo
char* sig = NEW_RESOURCE_ARRAY(char, sig_len);
jio_snprintf(sig, sig_len, "%c%c%s", JVM_SIGNATURE_FUNC, JVM_SIGNATURE_ENDFUNC, type->as_C_string());
TempNewSymbol full_sig = SymbolTable::new_symbol(sig);
accessor_method = holder->find_instance_method(name, full_sig, Klass::find_private);
accessor_method = holder->find_instance_method(name, full_sig, Klass::PrivateLookupMode::find);
}
if (accessor_method != NULL) {

@ -2116,7 +2116,7 @@ bool ClassVerifier::is_protected_access(InstanceKlass* this_class,
InstanceKlass* target_instance = InstanceKlass::cast(target_class);
fieldDescriptor fd;
if (is_method) {
Method* m = target_instance->uncached_lookup_method(field_name, field_sig, Klass::find_overpass);
Method* m = target_instance->uncached_lookup_method(field_name, field_sig, Klass::OverpassLookupMode::find);
if (m != NULL && m->is_protected()) {
if (!this_class->is_same_class_package(m->method_holder())) {
return true;
@ -2709,7 +2709,7 @@ void ClassVerifier::verify_invoke_init(
Method* m = InstanceKlass::cast(ref_klass)->uncached_lookup_method(
vmSymbols::object_initializer_name(),
cp->signature_ref_at(bcs->get_index_u2()),
Klass::find_overpass);
Klass::OverpassLookupMode::find);
// Do nothing if method is not found. Let resolution detect the error.
if (m != NULL) {
InstanceKlass* mh = m->method_holder();

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -1197,7 +1197,7 @@ class ClassHierarchyWalker {
} else {
// Search class hierarchy first, skipping private implementations
// as they never override any inherited methods
Method* m = InstanceKlass::cast(k)->find_instance_method(_name, _signature, Klass::skip_private);
Method* m = InstanceKlass::cast(k)->find_instance_method(_name, _signature, Klass::PrivateLookupMode::skip);
if (!Dependencies::is_concrete_method(m, k)) {
// Check for re-abstraction of method
if (!k->is_interface() && m != NULL && m->is_abstract()) {
@ -1207,7 +1207,7 @@ class ClassHierarchyWalker {
ClassHierarchyWalker wf(_participants, _num_participants);
Klass* w = wf.find_witness_subtype(k);
if (w != NULL) {
Method* wm = InstanceKlass::cast(w)->find_instance_method(_name, _signature, Klass::skip_private);
Method* wm = InstanceKlass::cast(w)->find_instance_method(_name, _signature, Klass::PrivateLookupMode::skip);
if (!Dependencies::is_concrete_method(wm, w)) {
// Found a concrete subtype 'w' which does not override abstract method 'm'.
// Bail out because 'm' could be called with 'w' as receiver (leading to an

@ -328,7 +328,7 @@ Method* LinkResolver::lookup_method_in_klasses(const LinkInfo& link_info,
Symbol* signature = link_info.signature();
// Ignore overpasses so statics can be found during resolution
Method* result = klass->uncached_lookup_method(name, signature, Klass::skip_overpass);
Method* result = klass->uncached_lookup_method(name, signature, Klass::OverpassLookupMode::skip);
if (klass->is_array_klass()) {
// Only consider klass and super klass for arrays
@ -377,11 +377,11 @@ Method* LinkResolver::lookup_instance_method_in_klasses(Klass* klass,
Symbol* name,
Symbol* signature,
Klass::PrivateLookupMode private_mode, TRAPS) {
Method* result = klass->uncached_lookup_method(name, signature, Klass::find_overpass, private_mode);
Method* result = klass->uncached_lookup_method(name, signature, Klass::OverpassLookupMode::find, private_mode);
while (result != NULL && result->is_static() && result->method_holder()->super() != NULL) {
Klass* super_klass = result->method_holder()->super();
result = super_klass->uncached_lookup_method(name, signature, Klass::find_overpass, private_mode);
result = super_klass->uncached_lookup_method(name, signature, Klass::OverpassLookupMode::find, private_mode);
}
if (klass->is_array_klass()) {
@ -410,8 +410,10 @@ int LinkResolver::vtable_index_of_interface_method(Klass* klass,
// First check in default method array
if (!resolved_method->is_abstract() && ik->default_methods() != NULL) {
int index = InstanceKlass::find_method_index(ik->default_methods(),
name, signature, Klass::find_overpass,
Klass::find_static, Klass::find_private);
name, signature,
Klass::OverpassLookupMode::find,
Klass::StaticLookupMode::find,
Klass::PrivateLookupMode::find);
if (index >= 0 ) {
vtable_index = ik->default_vtable_indices()->at(index);
}
@ -430,7 +432,7 @@ Method* LinkResolver::lookup_method_in_interfaces(const LinkInfo& cp_info) {
// Specify 'true' in order to skip default methods when searching the
// interfaces. Function lookup_method_in_klasses() already looked for
// the method in the default methods table.
return ik->lookup_method_in_all_interfaces(cp_info.name(), cp_info.signature(), Klass::skip_defaults);
return ik->lookup_method_in_all_interfaces(cp_info.name(), cp_info.signature(), Klass::DefaultsLookupMode::skip);
}
Method* LinkResolver::lookup_polymorphic_method(const LinkInfo& link_info,
@ -1087,7 +1089,7 @@ void LinkResolver::resolve_static_call(CallInfo& result,
// Use updated LinkInfo to reresolve with resolved method holder
LinkInfo new_info(resolved_klass, link_info.name(), link_info.signature(),
link_info.current_klass(),
link_info.check_access() ? LinkInfo::needs_access_check : LinkInfo::skip_access_check);
link_info.check_access() ? LinkInfo::AccessCheck::required : LinkInfo::AccessCheck::skip);
resolved_method = linktime_resolve_static_method(new_info, CHECK);
}
@ -1236,7 +1238,7 @@ void LinkResolver::runtime_resolve_special_method(CallInfo& result,
Method* instance_method = lookup_instance_method_in_klasses(super_klass,
resolved_method->name(),
resolved_method->signature(),
Klass::find_private, CHECK);
Klass::PrivateLookupMode::find, CHECK);
sel_method = methodHandle(THREAD, instance_method);
// check if found
@ -1478,7 +1480,7 @@ void LinkResolver::runtime_resolve_interface_method(CallInfo& result,
Method* method = lookup_instance_method_in_klasses(recv_klass,
resolved_method->name(),
resolved_method->signature(),
Klass::skip_private, CHECK);
Klass::PrivateLookupMode::skip, CHECK);
selected_method = methodHandle(THREAD, method);
if (selected_method.is_null() && !check_null_and_abstract) {

@ -144,28 +144,25 @@ class LinkInfo : public StackObj {
constantTag _tag;
public:
enum AccessCheck {
needs_access_check,
skip_access_check
};
enum class AccessCheck { required, skip };
LinkInfo(const constantPoolHandle& pool, int index, const methodHandle& current_method, TRAPS);
LinkInfo(const constantPoolHandle& pool, int index, TRAPS);
// Condensed information from other call sites within the vm.
LinkInfo(Klass* resolved_klass, Symbol* name, Symbol* signature, Klass* current_klass,
AccessCheck check_access = needs_access_check,
AccessCheck check_access = AccessCheck::required,
constantTag tag = JVM_CONSTANT_Invalid) :
_name(name),
_signature(signature), _resolved_klass(resolved_klass), _current_klass(current_klass), _current_method(methodHandle()),
_check_access(check_access == needs_access_check), _tag(tag) {}
_check_access(check_access == AccessCheck::required), _tag(tag) {}
LinkInfo(Klass* resolved_klass, Symbol* name, Symbol* signature, const methodHandle& current_method,
AccessCheck check_access = needs_access_check,
AccessCheck check_access = AccessCheck::required,
constantTag tag = JVM_CONSTANT_Invalid) :
_name(name),
_signature(signature), _resolved_klass(resolved_klass), _current_klass(current_method->method_holder()), _current_method(current_method),
_check_access(check_access == needs_access_check), _tag(tag) {}
_check_access(check_access == AccessCheck::required), _tag(tag) {}
// Case where we just find the method and don't check access against the current class
LinkInfo(Klass* resolved_klass, Symbol*name, Symbol* signature) :

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -89,7 +89,7 @@ void HotSpotJVMCI::compute_offset(int &dest_offset, Klass* klass, const char* na
#ifndef PRODUCT
static void check_resolve_method(const char* call_type, Klass* resolved_klass, Symbol* method_name, Symbol* method_signature, TRAPS) {
Method* method;
LinkInfo link_info(resolved_klass, method_name, method_signature, NULL, LinkInfo::skip_access_check);
LinkInfo link_info(resolved_klass, method_name, method_signature, NULL, LinkInfo::AccessCheck::skip);
if (strcmp(call_type, "call_static") == 0) {
method = LinkResolver::resolve_static_call_or_null(link_info);
} else if (strcmp(call_type, "call_virtual") == 0) {

@ -1322,7 +1322,7 @@ Method* JVMCIRuntime::lookup_method(InstanceKlass* accessor,
assert(check_klass_accessibility(accessor, holder), "holder not accessible");
Method* dest_method;
LinkInfo link_info(holder, name, sig, accessor, LinkInfo::needs_access_check, tag);
LinkInfo link_info(holder, name, sig, accessor, LinkInfo::AccessCheck::required, tag);
switch (bc) {
case Bytecodes::_invokestatic:
dest_method =

@ -79,7 +79,7 @@ Method* ArrayKlass::uncached_lookup_method(const Symbol* name,
// Always ignore overpass methods in superclasses, although technically the
// super klass of an array, (j.l.Object) should not have
// any overpass methods present.
return super()->uncached_lookup_method(name, signature, Klass::skip_overpass, private_mode);
return super()->uncached_lookup_method(name, signature, OverpassLookupMode::skip, private_mode);
}
ArrayKlass::ArrayKlass(Symbol* name, KlassID id) :

@ -85,7 +85,7 @@ class ArrayKlass: public Klass {
Method* uncached_lookup_method(const Symbol* name,
const Symbol* signature,
OverpassLookupMode overpass_mode,
PrivateLookupMode private_mode = find_private) const;
PrivateLookupMode private_mode = PrivateLookupMode::find) const;
static ArrayKlass* cast(Klass* k) {
return const_cast<ArrayKlass*>(cast(const_cast<const Klass*>(k)));

@ -1769,7 +1769,10 @@ inline int InstanceKlass::quick_search(const Array<Method*>* methods, const Symb
// find_method looks up the name/signature in the local methods array
Method* InstanceKlass::find_method(const Symbol* name,
const Symbol* signature) const {
return find_method_impl(name, signature, find_overpass, find_static, find_private);
return find_method_impl(name, signature,
OverpassLookupMode::find,
StaticLookupMode::find,
PrivateLookupMode::find);
}
Method* InstanceKlass::find_method_impl(const Symbol* name,
@ -1794,8 +1797,8 @@ Method* InstanceKlass::find_instance_method(const Array<Method*>* methods,
Method* const meth = InstanceKlass::find_method_impl(methods,
name,
signature,
find_overpass,
skip_static,
OverpassLookupMode::find,
StaticLookupMode::skip,
private_mode);
assert(((meth == NULL) || !meth->is_static()),
"find_instance_method should have skipped statics");
@ -1853,9 +1856,9 @@ Method* InstanceKlass::find_method(const Array<Method*>* methods,
return InstanceKlass::find_method_impl(methods,
name,
signature,
find_overpass,
find_static,
find_private);
OverpassLookupMode::find,
StaticLookupMode::find,
PrivateLookupMode::find);
}
Method* InstanceKlass::find_method_impl(const Array<Method*>* methods,
@ -1898,9 +1901,9 @@ int InstanceKlass::find_method_index(const Array<Method*>* methods,
OverpassLookupMode overpass_mode,
StaticLookupMode static_mode,
PrivateLookupMode private_mode) {
const bool skipping_overpass = (overpass_mode == skip_overpass);
const bool skipping_static = (static_mode == skip_static);
const bool skipping_private = (private_mode == skip_private);
const bool skipping_overpass = (overpass_mode == OverpassLookupMode::skip);
const bool skipping_static = (static_mode == StaticLookupMode::skip);
const bool skipping_private = (private_mode == PrivateLookupMode::skip);
const int hit = quick_search(methods, name);
if (hit != -1) {
const Method* const m = methods->at(hit);
@ -1976,13 +1979,13 @@ Method* InstanceKlass::uncached_lookup_method(const Symbol* name,
Method* const method = InstanceKlass::cast(klass)->find_method_impl(name,
signature,
overpass_local_mode,
find_static,
StaticLookupMode::find,
private_mode);
if (method != NULL) {
return method;
}
klass = klass->super();
overpass_local_mode = skip_overpass; // Always ignore overpass methods in superclasses
overpass_local_mode = OverpassLookupMode::skip; // Always ignore overpass methods in superclasses
}
return NULL;
}
@ -2012,7 +2015,7 @@ Method* InstanceKlass::lookup_method_in_ordered_interfaces(Symbol* name,
}
// Look up interfaces
if (m == NULL) {
m = lookup_method_in_all_interfaces(name, signature, find_defaults);
m = lookup_method_in_all_interfaces(name, signature, DefaultsLookupMode::find);
}
return m;
}
@ -2030,7 +2033,7 @@ Method* InstanceKlass::lookup_method_in_all_interfaces(Symbol* name,
ik = all_ifs->at(i);
Method* m = ik->lookup_method(name, signature);
if (m != NULL && m->is_public() && !m->is_static() &&
((defaults_mode != skip_defaults) || !m->is_default_method())) {
((defaults_mode != DefaultsLookupMode::skip) || !m->is_default_method())) {
return m;
}
}

@ -662,7 +662,7 @@ public:
Method* uncached_lookup_method(const Symbol* name,
const Symbol* signature,
OverpassLookupMode overpass_mode,
PrivateLookupMode private_mode = find_private) const;
PrivateLookupMode private_mode = PrivateLookupMode::find) const;
// lookup a method in all the interfaces that this class implements
// (returns NULL if not found)

@ -196,10 +196,10 @@ protected:
public:
int id() { return _id; }
enum DefaultsLookupMode { find_defaults, skip_defaults };
enum OverpassLookupMode { find_overpass, skip_overpass };
enum StaticLookupMode { find_static, skip_static };
enum PrivateLookupMode { find_private, skip_private };
enum class DefaultsLookupMode { find, skip };
enum class OverpassLookupMode { find, skip };
enum class StaticLookupMode { find, skip };
enum class PrivateLookupMode { find, skip };
virtual bool is_klass() const { return true; }
@ -482,10 +482,10 @@ protected:
virtual Klass* find_field(Symbol* name, Symbol* signature, fieldDescriptor* fd) const;
virtual Method* uncached_lookup_method(const Symbol* name, const Symbol* signature,
OverpassLookupMode overpass_mode,
PrivateLookupMode = find_private) const;
PrivateLookupMode = PrivateLookupMode::find) const;
public:
Method* lookup_method(const Symbol* name, const Symbol* signature) const {
return uncached_lookup_method(name, signature, find_overpass);
return uncached_lookup_method(name, signature, OverpassLookupMode::find);
}
// array class with specific rank

@ -692,7 +692,7 @@ bool klassVtable::needs_new_vtable_entry(const methodHandle& target_method,
// this check for all access permissions.
const InstanceKlass *sk = InstanceKlass::cast(super);
if (sk->has_miranda_methods()) {
if (sk->lookup_method_in_all_interfaces(name, signature, Klass::find_defaults) != NULL) {
if (sk->lookup_method_in_all_interfaces(name, signature, Klass::DefaultsLookupMode::find) != NULL) {
return false; // found a matching miranda; we do not need a new entry
}
}
@ -797,7 +797,9 @@ bool klassVtable::is_miranda(Method* m, Array<Method*>* class_methods,
// First look in local methods to see if already covered
if (InstanceKlass::find_local_method(class_methods, name, signature,
Klass::find_overpass, Klass::skip_static, Klass::skip_private) != NULL)
Klass::OverpassLookupMode::find,
Klass::StaticLookupMode::skip,
Klass::PrivateLookupMode::skip) != NULL)
{
return false;
}
@ -817,7 +819,9 @@ bool klassVtable::is_miranda(Method* m, Array<Method*>* class_methods,
for (const Klass* cursuper = super; cursuper != NULL; cursuper = cursuper->super())
{
Method* found_mth = InstanceKlass::cast(cursuper)->find_local_method(name, signature,
Klass::find_overpass, Klass::skip_static, Klass::skip_private);
Klass::OverpassLookupMode::find,
Klass::StaticLookupMode::skip,
Klass::PrivateLookupMode::skip);
// Ignore non-public methods in java.lang.Object if klass is an interface.
if (found_mth != NULL && (!is_interface ||
!SystemDictionary::is_nonpublic_Object_method(found_mth))) {
@ -861,7 +865,7 @@ void klassVtable::add_new_mirandas_to_lists(
if (is_miranda(im, class_methods, default_methods, super, is_interface)) { // is it a miranda at all?
const InstanceKlass *sk = InstanceKlass::cast(super);
// check if it is a duplicate of a super's miranda
if (sk->lookup_method_in_all_interfaces(im->name(), im->signature(), Klass::find_defaults) == NULL) {
if (sk->lookup_method_in_all_interfaces(im->name(), im->signature(), Klass::DefaultsLookupMode::find) == NULL) {
new_mirandas->append(im);
}
if (all_mirandas != NULL) {
@ -1213,7 +1217,7 @@ void klassItable::initialize_itable_for_interface(int method_table_offset, Insta
// Invokespecial does not perform selection based on the receiver, so it does not use
// the cached itable.
target = LinkResolver::lookup_instance_method_in_klasses(_klass, m->name(), m->signature(),
Klass::skip_private, CHECK);
Klass::PrivateLookupMode::skip, CHECK);
}
if (target == NULL || !target->is_public() || target->is_abstract() || target->is_overpass()) {
assert(target == NULL || !target->is_overpass() || target->is_public(),

@ -745,8 +745,8 @@ Handle MethodHandles::resolve_MemberName(Handle mname, Klass* caller,
if (type == NULL) return empty; // no such signature exists in the VM
LinkInfo::AccessCheck access_check = caller != NULL ?
LinkInfo::needs_access_check :
LinkInfo::skip_access_check;
LinkInfo::AccessCheck::required :
LinkInfo::AccessCheck::skip;
// Time to do the lookup.
switch (flags & ALL_KINDS) {
@ -819,7 +819,7 @@ Handle MethodHandles::resolve_MemberName(Handle mname, Klass* caller,
fieldDescriptor result; // find_field initializes fd if found
{
assert(!HAS_PENDING_EXCEPTION, "");
LinkInfo link_info(defc, name, type, caller, LinkInfo::skip_access_check);
LinkInfo link_info(defc, name, type, caller, LinkInfo::AccessCheck::skip);
LinkResolver::resolve_field(result, link_info, Bytecodes::_nop, false, THREAD);
if (HAS_PENDING_EXCEPTION) {
if (speculative_resolve) {

@ -438,7 +438,7 @@ address NativeLookup::base_library_lookup(const char* class_name, const char* me
// Find method and invoke standard lookup
methodHandle method (THREAD,
klass->uncached_lookup_method(m_name, s_name, Klass::find_overpass));
klass->uncached_lookup_method(m_name, s_name, Klass::OverpassLookupMode::find));
address result = lookup(method, in_base_library, CATCH);
assert(in_base_library, "must be in basic library");
guarantee(result != NULL, "must be non NULL");