class SymbolTable : public RehashableHashtable<Symbol*, mtSymbol> {
friend class VMStructs;
friend class ClassFileParser;
private:
static SymbolTable* _the_table;
static bool _needs_rehashing;
static int _symbols_removed;
static int _symbols_counted;
Symbol* allocate_symbol(const u1* name, int len, bool c_heap, TRAPS); // Assumes no characters larger than 0x7F
Symbol* basic_add(int index, u1* name, int len, unsigned int hashValue,
bool c_heap, TRAPS);
bool basic_add(ClassLoaderData* loader_data,
constantPoolHandle cp, int names_count,
const char** names, int* lengths, int* cp_indices,
unsigned int* hashValues, TRAPS);
static void new_symbols(ClassLoaderData* loader_data,
constantPoolHandle cp, int names_count,
const char** name, int* lengths,
int* cp_indices, unsigned int* hashValues,
TRAPS) {
add(loader_data, cp, names_count, name, lengths, cp_indices, hashValues, THREAD);
}
Symbol* lookup(int index, const char* name, int len, unsigned int hash);
SymbolTable()
: RehashableHashtable<Symbol*, mtSymbol>(SymbolTableSize, sizeof (HashtableEntry<Symbol*, mtSymbol>)) {}
SymbolTable(HashtableBucket<mtSymbol>* t, int number_of_entries)
: RehashableHashtable<Symbol*, mtSymbol>(SymbolTableSize, sizeof (HashtableEntry<Symbol*, mtSymbol>), t,
number_of_entries) {}
static Arena* _arena;
static Arena* arena() { return _arena; } // called for statistics
static void initialize_symbols(int arena_alloc_size = 0);
static volatile int _parallel_claimed_idx;
typedef SymbolTable::BucketUnlinkContext BucketUnlinkContext;
static void buckets_unlink(int start_idx, int end_idx, BucketUnlinkContext* context, size_t* memory_total);
public:
enum {
symbol_alloc_batch_size = 8,
symbol_alloc_arena_size = 360*K
};
static SymbolTable* the_table() { return _the_table; }
static uint bucket_size() { return sizeof(HashtableBucket<mtSymbol>); }
static void create_table() {
assert(_the_table == NULL, "One symbol table allowed.");
_the_table = new SymbolTable();
initialize_symbols(symbol_alloc_arena_size);
}
static void create_table(HashtableBucket<mtSymbol>* t, int length,
int number_of_entries) {
assert(_the_table == NULL, "One symbol table allowed.");
SymbolTableSize = length/bucket_size();
_the_table = new SymbolTable(t, number_of_entries);
initialize_symbols();
}
static unsigned int hash_symbol(const char* s, int len);
static Symbol* lookup(const char* name, int len, TRAPS);
static Symbol* lookup_only(const char* name, int len, unsigned int& hash);
static Symbol* lookup(const Symbol* sym, int begin, int end, TRAPS);
static void release(Symbol* sym);
static Symbol** lookup_symbol_addr(Symbol* sym);
static Symbol* lookup_unicode(const jchar* name, int len, TRAPS);
static Symbol* lookup_only_unicode(const jchar* name, int len, unsigned int& hash);
static void add(ClassLoaderData* loader_data,
constantPoolHandle cp, int names_count,
const char** names, int* lengths, int* cp_indices,
unsigned int* hashValues, TRAPS);
static void unlink() {
int processed = 0;
int removed = 0;
unlink(&processed, &removed);
}
static void unlink(int* processed, int* removed);
static void possibly_parallel_unlink(int* processed, int* removed);
static void symbols_do(SymbolClosure *cl);
static Symbol* new_symbol(const char* utf8_buffer, int length, TRAPS) {
assert(utf8_buffer != NULL, "just checking");
return lookup(utf8_buffer, length, THREAD);
}
static Symbol* new_symbol(const char* name, TRAPS) {
return new_symbol(name, (int)strlen(name), THREAD);
}
static Symbol* new_symbol(const Symbol* sym, int begin, int end, TRAPS) {
assert(begin <= end && end <= sym->utf8_length(), "just checking");
return lookup(sym, begin, end, THREAD);
}
static Symbol* new_permanent_symbol(const char* name, TRAPS);
static Symbol* lookup(int index, const char* name, int len, TRAPS);
static Symbol* probe(const char* name, int len) {
unsigned int ignore_hash;
return lookup_only(name, len, ignore_hash);
}
static Symbol* probe_unicode(const jchar* name, int len) {
unsigned int ignore_hash;
return lookup_only_unicode(name, len, ignore_hash);
}
static void print_histogram() PRODUCT_RETURN;
static void print() PRODUCT_RETURN;
static void verify();
static void dump(outputStream* st);
static void copy_buckets(char** top, char*end) {
the_table()->Hashtable<Symbol*, mtSymbol>::copy_buckets(top, end);
}
static void copy_table(char** top, char*end) {
the_table()->Hashtable<Symbol*, mtSymbol>::copy_table(top, end);
}
static void reverse(void* boundary = NULL) {
the_table()->Hashtable<Symbol*, mtSymbol>::reverse(boundary);
}
static void rehash_table();
static bool needs_rehashing() { return _needs_rehashing; }
static void clear_parallel_claimed_index() { _parallel_claimed_idx = 0; }
static int parallel_claimed_index() { return _parallel_claimed_idx; }
};
class StringTable : public RehashableHashtable<oop, mtSymbol> {
friend class VMStructs;
private:
static StringTable* _the_table;
static bool _needs_rehashing;
static volatile int _parallel_claimed_idx;
static oop intern(Handle string_or_null, jchar* chars, int length, TRAPS);
oop basic_add(int index, Handle string_or_null, jchar* name, int len,
unsigned int hashValue, TRAPS);
oop lookup(int index, jchar* chars, int length, unsigned int hashValue);
static void buckets_oops_do(OopClosure* f, int start_idx, int end_idx);
typedef StringTable::BucketUnlinkContext BucketUnlinkContext;
static void buckets_unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f, int start_idx, int end_idx, BucketUnlinkContext* context);
StringTable() : RehashableHashtable<oop, mtSymbol>((int)StringTableSize,
sizeof (HashtableEntry<oop, mtSymbol>)) {}
StringTable(HashtableBucket<mtSymbol>* t, int number_of_entries)
: RehashableHashtable<oop, mtSymbol>((int)StringTableSize, sizeof (HashtableEntry<oop, mtSymbol>), t,
number_of_entries) {}
public:
static StringTable* the_table() { return _the_table; }
static uint bucket_size() { return sizeof(HashtableBucket<mtSymbol>); }
static void create_table() {
assert(_the_table == NULL, "One string table allowed.");
_the_table = new StringTable();
}
static void unlink_or_oops_do(BoolObjectClosure* cl, OopClosure* f) {
int processed = 0;
int removed = 0;
unlink_or_oops_do(cl, f, &processed, &removed);
}
static void unlink(BoolObjectClosure* cl) {
int processed = 0;
int removed = 0;
unlink_or_oops_do(cl, NULL, &processed, &removed);
}
static void unlink_or_oops_do(BoolObjectClosure* cl, OopClosure* f, int* processed, int* removed);
static void unlink(BoolObjectClosure* cl, int* processed, int* removed) {
unlink_or_oops_do(cl, NULL, processed, removed);
}
static void oops_do(OopClosure* f);
static void possibly_parallel_unlink_or_oops_do(BoolObjectClosure* cl, OopClosure* f, int* processed, int* removed);
static void possibly_parallel_unlink(BoolObjectClosure* cl, int* processed, int* removed) {
possibly_parallel_unlink_or_oops_do(cl, NULL, processed, removed);
}
static void possibly_parallel_oops_do(OopClosure* f);
static unsigned int hash_string(const jchar* s, int len);
static void test_alt_hash() PRODUCT_RETURN;
static oop lookup(Symbol* symbol);
static oop lookup(jchar* chars, int length);
static oop intern(Symbol* symbol, TRAPS);
static oop intern(oop string, TRAPS);
static oop intern(const char *utf8_string, TRAPS);
static void verify();
static void dump(outputStream* st);
enum VerifyMesgModes {
_verify_quietly = 0,
_verify_with_mesgs = 1
};
enum VerifyRetTypes {
_verify_pass = 0,
_verify_fail_continue = 1,
_verify_fail_done = 2
};
static VerifyRetTypes compare_entries(int bkt1, int e_cnt1,
HashtableEntry<oop, mtSymbol>* e_ptr1,
int bkt2, int e_cnt2,
HashtableEntry<oop, mtSymbol>* e_ptr2);
static VerifyRetTypes verify_entry(int bkt, int e_cnt,
HashtableEntry<oop, mtSymbol>* e_ptr,
VerifyMesgModes mesg_mode);
static int verify_and_compare_entries();
static void copy_buckets(char** top, char*end) {
the_table()->Hashtable<oop, mtSymbol>::copy_buckets(top, end);
}
static void copy_table(char** top, char*end) {
the_table()->Hashtable<oop, mtSymbol>::copy_table(top, end);
}
static void reverse() {
the_table()->Hashtable<oop, mtSymbol>::reverse();
}
static void rehash_table();
static bool needs_rehashing() { return _needs_rehashing; }
static void clear_parallel_claimed_index() { _parallel_claimed_idx = 0; }
static int parallel_claimed_index() { return _parallel_claimed_idx; }
};
#endif // SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP
C:\hotspot-69087d08d473\src\share\vm/classfile/systemDictionary.cpp
#include "precompiled.hpp"
#include "classfile/classLoaderData.inline.hpp"
#include "classfile/dictionary.hpp"
#include "classfile/javaClasses.hpp"
#include "classfile/loaderConstraints.hpp"
#include "classfile/placeholders.hpp"
#include "classfile/resolutionErrors.hpp"
#include "classfile/systemDictionary.hpp"
#if INCLUDE_CDS
#include "classfile/sharedClassUtil.hpp"
#include "classfile/systemDictionaryShared.hpp"
#endif
#include "classfile/vmSymbols.hpp"
#include "compiler/compileBroker.hpp"
#include "interpreter/bytecodeStream.hpp"
#include "interpreter/interpreter.hpp"
#include "jfr/jfrEvents.hpp"
#include "jfr/jni/jfrUpcalls.hpp"
#include "memory/filemap.hpp"
#include "memory/gcLocker.hpp"
#include "memory/oopFactory.hpp"
#include "oops/instanceKlass.hpp"
#include "oops/instanceRefKlass.hpp"
#include "oops/klass.inline.hpp"
#include "oops/methodData.hpp"
#include "oops/objArrayKlass.hpp"
#include "oops/oop.inline.hpp"
#include "oops/oop.inline2.hpp"
#include "oops/typeArrayKlass.hpp"
#include "prims/jvmtiEnvBase.hpp"
#include "prims/methodHandles.hpp"
#include "runtime/arguments.hpp"
#include "runtime/biasedLocking.hpp"
#include "runtime/fieldType.hpp"
#include "runtime/handles.inline.hpp"
#include "runtime/java.hpp"
#include "runtime/javaCalls.hpp"
#include "runtime/mutexLocker.hpp"
#include "runtime/orderAccess.inline.hpp"
#include "runtime/signature.hpp"
#include "services/classLoadingService.hpp"
#include "services/threadService.hpp"
#include "utilities/macros.hpp"
#include "utilities/ticks.hpp"
Dictionary* SystemDictionary::_dictionary = NULL;
PlaceholderTable* SystemDictionary::_placeholders = NULL;
Dictionary* SystemDictionary::_shared_dictionary = NULL;
LoaderConstraintTable* SystemDictionary::_loader_constraints = NULL;
ResolutionErrorTable* SystemDictionary::_resolution_errors = NULL;
SymbolPropertyTable* SystemDictionary::_invoke_method_table = NULL;
int SystemDictionary::_number_of_modifications = 0;
int SystemDictionary::_sdgeneration = 0;
const int SystemDictionary::_primelist[_prime_array_size] = {1009,2017,4049,5051,10103,
20201,40423,99991};
oop SystemDictionary::_system_loader_lock_obj = NULL;
Klass* SystemDictionary::_well_known_klasses[SystemDictionary::WKID_LIMIT]
= { NULL /*, NULL...*/ };
Klass* SystemDictionary::_box_klasses[T_VOID+1] = { NULL /*, NULL...*/ };
oop SystemDictionary::_java_system_loader = NULL;
bool SystemDictionary::_has_loadClassInternal = false;
bool SystemDictionary::_has_checkPackageAccess = false;
Klass* volatile SystemDictionary::_abstract_ownable_synchronizer_klass = NULL;
#if INCLUDE_JFR
static const Symbol* jfr_event_handler_proxy = NULL;
#endif // INCLUDE_JFR
oop SystemDictionary::java_system_loader() {
return _java_system_loader;
}
void SystemDictionary::compute_java_system_loader(TRAPS) {
KlassHandle system_klass(THREAD, WK_KLASS(ClassLoader_klass));
JavaValue result(T_OBJECT);
JavaCalls::call_static(&result,
KlassHandle(THREAD, WK_KLASS(ClassLoader_klass)),
vmSymbols::getSystemClassLoader_name(),
vmSymbols::void_classloader_signature(),
CHECK);
_java_system_loader = (oop)result.get_jobject();
CDS_ONLY(SystemDictionaryShared::initialize(CHECK);)
}
ClassLoaderData* SystemDictionary::register_loader(Handle class_loader, TRAPS) {
if (class_loader() == NULL) return ClassLoaderData::the_null_class_loader_data();
return ClassLoaderDataGraph::find_or_create(class_loader, THREAD);
}
#ifdef ASSERT
bool SystemDictionary::is_internal_format(Symbol* class_name) {
if (class_name != NULL) {
ResourceMark rm;
char* name = class_name->as_C_string();
return strchr(name, '.') == NULL;
} else {
return true;
}
}
#endif
#if INCLUDE_JFR
#include "jfr/jfr.hpp"
#endif
bool SystemDictionary::is_parallelCapable(Handle class_loader) {
if (UnsyncloadClass || class_loader.is_null()) return true;
if (AlwaysLockClassLoader) return false;
return java_lang_ClassLoader::parallelCapable(class_loader());
}
bool SystemDictionary::is_parallelDefine(Handle class_loader) {
if (class_loader.is_null()) return false;
if (AllowParallelDefineClass && java_lang_ClassLoader::parallelCapable(class_loader())) {
return true;
}
return false;
}
bool SystemDictionary::is_ext_class_loader(Handle class_loader) {
if (class_loader.is_null()) {
return false;
}
return (class_loader->klass()->name() == vmSymbols::sun_misc_Launcher_ExtClassLoader());
}
Klass* SystemDictionary::resolve_or_fail(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS) {
Klass* klass = resolve_or_null(class_name, class_loader, protection_domain, THREAD);
if (HAS_PENDING_EXCEPTION || klass == NULL) {
KlassHandle k_h(THREAD, klass);
klass = handle_resolution_exception(class_name, throw_error, k_h, THREAD);
}
return klass;
}
Klass* SystemDictionary::handle_resolution_exception(Symbol* class_name,
bool throw_error,
KlassHandle klass_h, TRAPS) {
if (HAS_PENDING_EXCEPTION) {
if (throw_error && PENDING_EXCEPTION->is_a(SystemDictionary::ClassNotFoundException_klass())) {
ResourceMark rm(THREAD);
assert(klass_h() == NULL, "Should not have result with exception pending");
Handle e(THREAD, PENDING_EXCEPTION);
CLEAR_PENDING_EXCEPTION;
THROW_MSG_CAUSE_NULL(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string(), e);
} else {
return NULL;
}
}
if (klass_h() == NULL) {
ResourceMark rm(THREAD);
if (throw_error) {
THROW_MSG_NULL(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string());
} else {
THROW_MSG_NULL(vmSymbols::java_lang_ClassNotFoundException(), class_name->as_C_string());
}
}
return (Klass*)klass_h();
}
Klass* SystemDictionary::resolve_or_fail(Symbol* class_name,
bool throw_error, TRAPS)
{
return resolve_or_fail(class_name, Handle(), Handle(), throw_error, THREAD);
}
Klass* SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
assert(!THREAD->is_Compiler_thread(),
err_msg("can not load classes with compiler thread: class=%s, classloader=%s",
class_name->as_C_string(),
class_loader.is_null() ? "null" : class_loader->klass()->name()->as_C_string()));
if (FieldType::is_array(class_name)) {
return resolve_array_class_or_null(class_name, class_loader, protection_domain, THREAD);
} else if (FieldType::is_obj(class_name)) {
ResourceMark rm(THREAD);
TempNewSymbol name = SymbolTable::new_symbol(class_name->as_C_string() + 1,
class_name->utf8_length() - 2, CHECK_NULL);
return resolve_instance_class_or_null(name, class_loader, protection_domain, THREAD);
} else {
return resolve_instance_class_or_null(class_name, class_loader, protection_domain, THREAD);
}
}
Klass* SystemDictionary::resolve_or_null(Symbol* class_name, TRAPS) {
return resolve_or_null(class_name, Handle(), Handle(), THREAD);
}
Klass* SystemDictionary::resolve_array_class_or_null(Symbol* class_name,
Handle class_loader,
Handle protection_domain,
TRAPS) {
assert(FieldType::is_array(class_name), "must be array");
Klass* k = NULL;
FieldArrayInfo fd;
BasicType t = FieldType::get_array_info(class_name, fd, CHECK_NULL);
if (t == T_OBJECT) {
k = SystemDictionary::resolve_instance_class_or_null(fd.object_key(),
class_loader,
protection_domain,
CHECK_NULL);
if (k != NULL) {
k = k->array_klass(fd.dimension(), CHECK_NULL);
}
} else {
k = Universe::typeArrayKlassObj(t);
k = TypeArrayKlass::cast(k)->array_klass(fd.dimension(), CHECK_NULL);
}
return k;
}
Klass* SystemDictionary::resolve_super_or_fail(Symbol* child_name,
Symbol* class_name,
Handle class_loader,
Handle protection_domain,
bool is_superclass,
TRAPS) {
ClassLoaderData* loader_data = class_loader_data(class_loader);
unsigned int d_hash = dictionary()->compute_hash(child_name, loader_data);
int d_index = dictionary()->hash_to_index(d_hash);
unsigned int p_hash = placeholders()->compute_hash(child_name, loader_data);
int p_index = placeholders()->hash_to_index(p_hash);
bool child_already_loaded = false;
bool throw_circularity_error = false;
{
MutexLocker mu(SystemDictionary_lock, THREAD);
Klass* childk = find_class(d_index, d_hash, child_name, loader_data);
Klass* quicksuperk;
if ((childk != NULL ) && (is_superclass) &&
((quicksuperk = InstanceKlass::cast(childk)->super()) != NULL) &&
((quicksuperk->name() == class_name) &&
(quicksuperk->class_loader() == class_loader()))) {
return quicksuperk;
} else {
PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, child_name, loader_data);
if (probe && probe->check_seen_thread(THREAD, PlaceholderTable::LOAD_SUPER)) {
throw_circularity_error = true;
}
}
if (!throw_circularity_error) {
PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, child_name, loader_data, PlaceholderTable::LOAD_SUPER, class_name, THREAD);
}
}
if (throw_circularity_error) {
ResourceMark rm(THREAD);
THROW_MSG_NULL(vmSymbols::java_lang_ClassCircularityError(), child_name->as_C_string());
}
assert(class_name != NULL, "null super class for resolving");
Klass* superk = SystemDictionary::resolve_or_null(class_name,
class_loader,
protection_domain,
THREAD);
KlassHandle superk_h(THREAD, superk);
{
MutexLocker mu(SystemDictionary_lock, THREAD);
placeholders()->find_and_remove(p_index, p_hash, child_name, loader_data, PlaceholderTable::LOAD_SUPER, THREAD);
SystemDictionary_lock->notify_all();
}
if (HAS_PENDING_EXCEPTION || superk_h() == NULL) {
superk_h = KlassHandle(THREAD, handle_resolution_exception(class_name, true, superk_h, THREAD));
}
return superk_h();
}
void SystemDictionary::validate_protection_domain(instanceKlassHandle klass,
Handle class_loader,
Handle protection_domain,
TRAPS) {
if(!has_checkPackageAccess()) return;
JavaValue result(T_VOID);
if (TraceProtectionDomainVerification) {
tty->print_cr("Checking package access");
tty->print(" - class loader: "); class_loader()->print_value_on(tty); tty->cr();
tty->print(" - protection domain: "); protection_domain()->print_value_on(tty); tty->cr();
tty->print(" - loading: "); klass()->print_value_on(tty); tty->cr();
}
KlassHandle system_loader(THREAD, SystemDictionary::ClassLoader_klass());
JavaCalls::call_special(&result,
class_loader,
system_loader,
vmSymbols::checkPackageAccess_name(),
vmSymbols::class_protectiondomain_signature(),
Handle(THREAD, klass->java_mirror()),
protection_domain,
THREAD);
if (TraceProtectionDomainVerification) {
if (HAS_PENDING_EXCEPTION) {
tty->print_cr(" -> DENIED !!!!!!!!!!!!!!!!!!!!!");
} else {
tty->print_cr(" -> granted");
}
tty->cr();
}
if (HAS_PENDING_EXCEPTION) return;
{
ClassLoaderData* loader_data = class_loader_data(class_loader);
Symbol* kn = klass->name();
unsigned int d_hash = dictionary()->compute_hash(kn, loader_data);
int d_index = dictionary()->hash_to_index(d_hash);
MutexLocker mu(SystemDictionary_lock, THREAD);
{
No_Safepoint_Verifier nosafepoint;
dictionary()->add_protection_domain(d_index, d_hash, klass, loader_data,
protection_domain, THREAD);
}
}
}
void SystemDictionary::double_lock_wait(Handle lockObject, TRAPS) {
assert_lock_strong(SystemDictionary_lock);
bool calledholdinglock
= ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, lockObject);
assert(calledholdinglock,"must hold lock for notify");
assert((!(lockObject() == _system_loader_lock_obj) && !is_parallelCapable(lockObject)), "unexpected double_lock_wait");
ObjectSynchronizer::notifyall(lockObject, THREAD);
intptr_t recursions = ObjectSynchronizer::complete_exit(lockObject, THREAD);
SystemDictionary_lock->wait();
SystemDictionary_lock->unlock();
ObjectSynchronizer::reenter(lockObject, recursions, THREAD);
SystemDictionary_lock->lock();
}
instanceKlassHandle SystemDictionary::handle_parallel_super_load(
Symbol* name, Symbol* superclassname, Handle class_loader,
Handle protection_domain, Handle lockObject, TRAPS) {
instanceKlassHandle nh = instanceKlassHandle(); // null Handle
ClassLoaderData* loader_data = class_loader_data(class_loader);
unsigned int d_hash = dictionary()->compute_hash(name, loader_data);
int d_index = dictionary()->hash_to_index(d_hash);
unsigned int p_hash = placeholders()->compute_hash(name, loader_data);
int p_index = placeholders()->hash_to_index(p_hash);
Klass* superk = SystemDictionary::resolve_super_or_fail(name,
superclassname,
class_loader,
protection_domain,
true,
CHECK_(nh));
if (!class_loader.is_null() && is_parallelCapable(class_loader)) {
MutexLocker mu(SystemDictionary_lock, THREAD);
Klass* check = find_class(d_index, d_hash, name, loader_data);
if (check != NULL) {
return(instanceKlassHandle(THREAD, check));
} else {
return nh;
}
}
bool super_load_in_progress = true;
PlaceholderEntry* placeholder;
while (super_load_in_progress) {
MutexLocker mu(SystemDictionary_lock, THREAD);
Klass* check = find_class(d_index, d_hash, name, loader_data);
if (check != NULL) {
return(instanceKlassHandle(THREAD, check));
} else {
placeholder = placeholders()->get_entry(p_index, p_hash, name, loader_data);
if (placeholder && placeholder->super_load_in_progress() ){
if (class_loader.is_null()) {
SystemDictionary_lock->wait();
} else {
double_lock_wait(lockObject, THREAD);
}
} else {
super_load_in_progress = false;
}
}
}
return (nh);
}
static void post_class_load_event(EventClassLoad &event,
instanceKlassHandle k,
Handle initiating_loader) {
#if INCLUDE_JFR
if (event.should_commit()) {
event.set_loadedClass(k());
event.set_definingClassLoader(k->class_loader_data());
oop class_loader = initiating_loader.is_null() ? (oop)NULL : initiating_loader();
event.set_initiatingClassLoader(class_loader != NULL ?
ClassLoaderData::class_loader_data_or_null(class_loader) :
(ClassLoaderData*)NULL);
event.commit();
}
#endif
}
Klass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
Handle class_loader,
Handle protection_domain,
TRAPS) {
assert(name != NULL && !FieldType::is_array(name) &&
!FieldType::is_obj(name), "invalid class name");
EventClassLoad class_load_start_event;
class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
ClassLoaderData *loader_data = register_loader(class_loader, CHECK_NULL);
unsigned int d_hash = dictionary()->compute_hash(name, loader_data);
int d_index = dictionary()->hash_to_index(d_hash);
Klass* probe = dictionary()->find(d_index, d_hash, name, loader_data,
protection_domain, THREAD);
if (probe != NULL) return probe;
bool DoObjectLock = true;
if (is_parallelCapable(class_loader)) {
DoObjectLock = false;
}
unsigned int p_hash = placeholders()->compute_hash(name, loader_data);
int p_index = placeholders()->hash_to_index(p_hash);
Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
check_loader_lock_contention(lockObject, THREAD);
ObjectLocker ol(lockObject, THREAD, DoObjectLock);
bool class_has_been_loaded = false;
bool super_load_in_progress = false;
bool havesupername = false;
instanceKlassHandle k;
PlaceholderEntry* placeholder;
Symbol* superclassname = NULL;
{
MutexLocker mu(SystemDictionary_lock, THREAD);
Klass* check = find_class(d_index, d_hash, name, loader_data);
if (check != NULL) {
class_has_been_loaded = true;
k = instanceKlassHandle(THREAD, check);
} else {
placeholder = placeholders()->get_entry(p_index, p_hash, name, loader_data);
if (placeholder && placeholder->super_load_in_progress()) {
super_load_in_progress = true;
if (placeholder->havesupername() == true) {
superclassname = placeholder->supername();
havesupername = true;
}
}
}
}
if (super_load_in_progress && havesupername==true) {
k = SystemDictionary::handle_parallel_super_load(name, superclassname,
class_loader, protection_domain, lockObject, THREAD);
if (HAS_PENDING_EXCEPTION) {
return NULL;
}
if (!k.is_null()) {
class_has_been_loaded = true;
}
}
bool throw_circularity_error = false;
if (!class_has_been_loaded) {
bool load_instance_added = false;
{
MutexLocker mu(SystemDictionary_lock, THREAD);
if (class_loader.is_null() || !is_parallelCapable(class_loader)) {
PlaceholderEntry* oldprobe = placeholders()->get_entry(p_index, p_hash, name, loader_data);
if (oldprobe) {
if (oldprobe->check_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE)) {
throw_circularity_error = true;
} else {
while (!class_has_been_loaded && oldprobe && oldprobe->instance_load_in_progress()) {
if (class_loader.is_null()) {
SystemDictionary_lock->wait();
} else {
double_lock_wait(lockObject, THREAD);
}
Klass* check = find_class(d_index, d_hash, name, loader_data);
if (check != NULL) {
k = instanceKlassHandle(THREAD, check);
class_has_been_loaded = true;
}
oldprobe = placeholders()->get_entry(p_index, p_hash, name, loader_data);
}
}
}
}
if (!throw_circularity_error && !class_has_been_loaded) {
PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, name, loader_data, PlaceholderTable::LOAD_INSTANCE, NULL, THREAD);
load_instance_added = true;
Klass* check = find_class(d_index, d_hash, name, loader_data);
if (check != NULL) {
k = instanceKlassHandle(THREAD, check);
class_has_been_loaded = true;
}
}
}
if (throw_circularity_error) {
assert(!HAS_PENDING_EXCEPTION && load_instance_added == false,"circularity error cleanup");
ResourceMark rm(THREAD);
THROW_MSG_NULL(vmSymbols::java_lang_ClassCircularityError(), name->as_C_string());
}
if (!class_has_been_loaded) {
k = load_instance_class(name, class_loader, THREAD);
if (UnsyncloadClass || (class_loader.is_null())) {
if (k.is_null() && HAS_PENDING_EXCEPTION
&& PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) {
MutexLocker mu(SystemDictionary_lock, THREAD);
Klass* check = find_class(d_index, d_hash, name, loader_data);
if (check != NULL) {
k = instanceKlassHandle(THREAD, check);
CLEAR_PENDING_EXCEPTION;
guarantee((!class_loader.is_null()), "dup definition for bootstrap loader?");
}
}
}
if (!HAS_PENDING_EXCEPTION && !k.is_null() &&
k->class_loader() != class_loader()) {
check_constraints(d_index, d_hash, k, class_loader, false, THREAD);
if (!HAS_PENDING_EXCEPTION) {
loader_data->record_dependency(k(), THREAD);
}
if (!HAS_PENDING_EXCEPTION) {
{ // Grabbing the Compile_lock prevents systemDictionary updates
MutexLocker mu(Compile_lock, THREAD);
update_dictionary(d_index, d_hash, p_index, p_hash,
k, class_loader, THREAD);
}
if (JvmtiExport::should_post_class_load()) {
Thread *thread = THREAD;
assert(thread->is_Java_thread(), "thread->is_Java_thread()");
JvmtiExport::post_class_load((JavaThread *) thread, k());
}
}
}
} // load_instance_class loop
if (load_instance_added == true) {
MutexLocker mu(SystemDictionary_lock, THREAD);
placeholders()->find_and_remove(p_index, p_hash, name, loader_data, PlaceholderTable::LOAD_INSTANCE, THREAD);
SystemDictionary_lock->notify_all();
}
}
if (HAS_PENDING_EXCEPTION || k.is_null()) {
return NULL;
}
post_class_load_event(class_load_start_event, k, class_loader);
#ifdef ASSERT
{
ClassLoaderData* loader_data = k->class_loader_data();
MutexLocker mu(SystemDictionary_lock, THREAD);
Klass* kk = find_class(name, loader_data);
assert(kk == k(), "should be present in dictionary");
}
#endif
if (protection_domain() == NULL) return k();
{
MutexLocker mu(SystemDictionary_lock, THREAD);
No_Safepoint_Verifier nosafepoint;
if (dictionary()->is_valid_protection_domain(d_index, d_hash, name,
loader_data,
protection_domain)) {
return k();
}
}
validate_protection_domain(k, class_loader, protection_domain, CHECK_NULL);
return k();
}
Klass* SystemDictionary::find(Symbol* class_name,
Handle class_loader,
Handle protection_domain,
TRAPS) {
class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
ClassLoaderData* loader_data = ClassLoaderData::class_loader_data_or_null(class_loader());
if (loader_data == NULL) {
return NULL;
}
unsigned int d_hash = dictionary()->compute_hash(class_name, loader_data);
int d_index = dictionary()->hash_to_index(d_hash);
{
No_Safepoint_Verifier nosafepoint;
return dictionary()->find(d_index, d_hash, class_name, loader_data,
protection_domain, THREAD);
}
}
Klass* SystemDictionary::find_instance_or_array_klass(Symbol* class_name,
Handle class_loader,
Handle protection_domain,
TRAPS) {
Klass* k = NULL;
assert(class_name != NULL, "class name must be non NULL");
if (FieldType::is_array(class_name)) {
FieldArrayInfo fd;
BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(NULL));
if (t != T_OBJECT) {
k = Universe::typeArrayKlassObj(t);
} else {
k = SystemDictionary::find(fd.object_key(), class_loader, protection_domain, THREAD);
}
if (k != NULL) {
k = k->array_klass_or_null(fd.dimension());
}
} else {
k = find(class_name, class_loader, protection_domain, THREAD);
}
return k;
}
Klass* SystemDictionary::parse_stream(Symbol* class_name,
Handle class_loader,
Handle protection_domain,
ClassFileStream* st,
KlassHandle host_klass,
GrowableArray<Handle>* cp_patches,
TRAPS) {
TempNewSymbol parsed_name = NULL;
EventClassLoad class_load_start_event;
ClassLoaderData* loader_data;
if (host_klass.not_null()) {
assert(EnableInvokeDynamic, "");
guarantee(host_klass->class_loader() == class_loader(), "should be the same");
guarantee(!DumpSharedSpaces, "must not create anonymous classes when dumping");
loader_data = ClassLoaderData::anonymous_class_loader_data(class_loader(), CHECK_NULL);
loader_data->record_dependency(host_klass(), CHECK_NULL);
} else {
loader_data = ClassLoaderData::class_loader_data(class_loader());
}
instanceKlassHandle k;
{
ResourceMark rm(THREAD);
k = ClassFileParser(st).parseClassFile(class_name,
loader_data,
protection_domain,
host_klass,
cp_patches,
parsed_name,
true,
THREAD);
}
if (host_klass.not_null() && k.not_null()) {
assert(EnableInvokeDynamic, "");
{
MutexLocker mu_r(Compile_lock, THREAD);
add_to_hierarchy(k, CHECK_NULL); // No exception, but can block
notice_modification();
}
k->link_class(CHECK_NULL);
if (cp_patches != NULL) {
k->constants()->patch_resolved_references(cp_patches);
}
k->eager_initialize(CHECK_NULL);
if (JvmtiExport::should_post_class_load()) {
assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
JvmtiExport::post_class_load((JavaThread *) THREAD, k());
}
post_class_load_event(class_load_start_event, k, class_loader);
}
assert(host_klass.not_null() || cp_patches == NULL,
"cp_patches only found with host_klass");
return k();
}
static bool is_prohibited_package_slow(Symbol* class_name) {
int length;
jchar* unicode = class_name->as_unicode(length);
return (length >= 5 &&
unicode[0] == 'j' &&
unicode[1] == 'a' &&
unicode[2] == 'v' &&
unicode[3] == 'a' &&
unicode[4] == '/');
}
Klass* SystemDictionary::resolve_from_stream(Symbol* class_name,
Handle class_loader,
Handle protection_domain,
ClassFileStream* st,
bool verify,
TRAPS) {
bool DoObjectLock = true;
if (is_parallelCapable(class_loader)) {
DoObjectLock = false;
}
ClassLoaderData* loader_data = register_loader(class_loader, CHECK_NULL);
Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
check_loader_lock_contention(lockObject, THREAD);
ObjectLocker ol(lockObject, THREAD, DoObjectLock);
TempNewSymbol parsed_name = NULL;
ResourceMark rm(THREAD);
ClassFileParser parser(st);
instanceKlassHandle k = parser.parseClassFile(class_name,
loader_data,
protection_domain,
parsed_name,
verify,
THREAD);
const char* pkg = "java/";
size_t pkglen = strlen(pkg);
if (!HAS_PENDING_EXCEPTION &&
!class_loader.is_null() &&
parsed_name != NULL &&
parsed_name->utf8_length() >= (int)pkglen) {
ResourceMark rm(THREAD);
bool prohibited;
const jbyte* base = parsed_name->base();
if ((base[0] | base[1] | base[2] | base[3] | base[4]) & 0x80) {
prohibited = is_prohibited_package_slow(parsed_name);
} else {
char* name = parsed_name->as_C_string();
prohibited = (strncmp(name, pkg, pkglen) == 0);
}
if (prohibited) {
char* name = parsed_name->as_C_string();
char* index = strrchr(name, '/');
assert(index != NULL, "must be");
while ((index = strchr(name, '/')) != NULL) {
}
const char* fmt = "Prohibited package name: %s";
size_t len = strlen(fmt) + strlen(name);
char* message = NEW_RESOURCE_ARRAY(char, len);
jio_snprintf(message, len, fmt, name);
Exceptions::_throw_msg(THREAD_AND_LOCATION,
vmSymbols::java_lang_SecurityException(), message);
}
}
if (!HAS_PENDING_EXCEPTION) {
assert(parsed_name != NULL, "Sanity");
assert(class_name == NULL || class_name == parsed_name, "name mismatch");
assert(is_internal_format(parsed_name),
"external class name format used internally");
#if INCLUDE_JFR
{
InstanceKlass* ik = k();
ON_KLASS_CREATION(ik, parser, THREAD);
k = instanceKlassHandle(ik);
}
#endif
if (is_parallelCapable(class_loader)) {
k = find_or_define_instance_class(class_name, class_loader, k, THREAD);
} else {
define_instance_class(k, THREAD);
}
}
debug_only( {
if (!HAS_PENDING_EXCEPTION) {
assert(parsed_name != NULL, "parsed_name is still null?");
Symbol* h_name = k->name();
ClassLoaderData *defining_loader_data = k->class_loader_data();
MutexLocker mu(SystemDictionary_lock, THREAD);
Klass* check = find_class(parsed_name, loader_data);
assert(check == k(), "should be present in the dictionary");
Klass* check2 = find_class(h_name, defining_loader_data);
assert(check == check2, "name inconsistancy in SystemDictionary");
}
} );
return k();
}
#if INCLUDE_CDS
void SystemDictionary::set_shared_dictionary(HashtableBucket<mtClass>* t, int length,
int number_of_entries) {
assert(length == _nof_buckets * sizeof(HashtableBucket<mtClass>),
"bad shared dictionary size.");
_shared_dictionary = new Dictionary(_nof_buckets, t, number_of_entries);
}
Klass* SystemDictionary::find_shared_class(Symbol* class_name) {
if (shared_dictionary() != NULL) {
unsigned int d_hash = shared_dictionary()->compute_hash(class_name, NULL);
int d_index = shared_dictionary()->hash_to_index(d_hash);
return shared_dictionary()->find_shared_class(d_index, d_hash, class_name);
} else {
return NULL;
}
}
instanceKlassHandle SystemDictionary::load_shared_class(
Symbol* class_name, Handle class_loader, TRAPS) {
instanceKlassHandle ik (THREAD, find_shared_class(class_name));
if (ik.not_null() &&
SharedClassUtil::is_shared_boot_class(ik()) && class_loader.is_null()) {
Handle protection_domain;
return load_shared_class(ik, class_loader, protection_domain, THREAD);
}
return instanceKlassHandle();
}
instanceKlassHandle SystemDictionary::load_shared_class(instanceKlassHandle ik,
Handle class_loader,
Handle protection_domain, TRAPS) {
if (ik.not_null()) {
instanceKlassHandle nh = instanceKlassHandle(); // null Handle
Symbol* class_name = ik->name();
if (ik->super() != NULL) {
Symbol* cn = ik->super()->name();
Klass *s = resolve_super_or_fail(class_name, cn,
class_loader, protection_domain, true, CHECK_(nh));
if (s != ik->super()) {
return nh;
}
}
Array<Klass*>* interfaces = ik->local_interfaces();
int num_interfaces = interfaces->length();
for (int index = 0; index < num_interfaces; index++) {
Klass* k = interfaces->at(index);
Symbol* name = k->name();
Klass* i = resolve_super_or_fail(class_name, name, class_loader, protection_domain, false, CHECK_(nh));
if (k != i) {
return nh;
}
}
ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());
{
Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
check_loader_lock_contention(lockObject, THREAD);
ObjectLocker ol(lockObject, THREAD, true);
ik->restore_unshareable_info(loader_data, protection_domain, CHECK_(nh));
}
if (TraceClassLoading) {
ResourceMark rm;
tty->print("[Loaded %s", ik->external_name());
tty->print(" from shared objects file");
if (class_loader.not_null()) {
tty->print(" by %s", loader_data->loader_name());
}
tty->print_cr("]");
}
if (DumpLoadedClassList != NULL && classlist_file->is_open()) {
if (SystemDictionaryShared::is_sharing_possible(loader_data)) {
ResourceMark rm(THREAD);
classlist_file->print_cr("%s", ik->name()->as_C_string());
classlist_file->flush();
}
}
ClassLoadingService::notify_class_loaded(InstanceKlass::cast(ik()),
true /* shared class */);
}
return ik;
}
#endif // INCLUDE_CDS
instanceKlassHandle SystemDictionary::load_instance_class(Symbol* class_name, Handle class_loader, TRAPS) {
instanceKlassHandle nh = instanceKlassHandle(); // null Handle
if (class_loader.is_null()) {
instanceKlassHandle k;
{
#if INCLUDE_CDS
PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time());
k = load_shared_class(class_name, class_loader, THREAD);
#endif
}
if (k.is_null()) {
PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time());
k = ClassLoader::load_classfile(class_name, CHECK_(nh));
}
if (!k.is_null()) {
k = find_or_define_instance_class(class_name, class_loader, k, CHECK_(nh));
}
#if INCLUDE_JFR
if (k.is_null() && (class_name == jfr_event_handler_proxy)) {
assert(jfr_event_handler_proxy != NULL, "invariant");
CLEAR_PENDING_EXCEPTION;
k = JfrUpcalls::load_event_handler_proxy_class(THREAD);
assert(!k.is_null(), "invariant");
}
#endif
return k;
} else {
ResourceMark rm(THREAD);
assert(THREAD->is_Java_thread(), "must be a JavaThread");
JavaThread* jt = (JavaThread*) THREAD;
PerfClassTraceTime vmtimer(ClassLoader::perf_app_classload_time(),
ClassLoader::perf_app_classload_selftime(),
ClassLoader::perf_app_classload_count(),
jt->get_thread_stat()->perf_recursion_counts_addr(),
jt->get_thread_stat()->perf_timers_addr(),
PerfClassTraceTime::CLASS_LOAD);
Handle s = java_lang_String::create_from_symbol(class_name, CHECK_(nh));
Handle string = java_lang_String::externalize_classname(s, CHECK_(nh));
JavaValue result(T_OBJECT);
KlassHandle spec_klass (THREAD, SystemDictionary::ClassLoader_klass());
if (MustCallLoadClassInternal && has_loadClassInternal()) {
JavaCalls::call_special(&result,
class_loader,
spec_klass,
vmSymbols::loadClassInternal_name(),
vmSymbols::string_class_signature(),
string,
CHECK_(nh));
} else {
JavaCalls::call_virtual(&result,
class_loader,
spec_klass,
vmSymbols::loadClass_name(),
vmSymbols::string_class_signature(),
string,
CHECK_(nh));
}
assert(result.get_type() == T_OBJECT, "just checking");
oop obj = (oop) result.get_jobject();
if ((obj != NULL) && !(java_lang_Class::is_primitive(obj))) {
instanceKlassHandle k =
instanceKlassHandle(THREAD, java_lang_Class::as_Klass(obj));
if (class_name == k->name()) {
return k;
}
}
return nh;
}
}
static void post_class_define_event(InstanceKlass* k, const ClassLoaderData* def_cld) {
EventClassDefine event;
if (event.should_commit()) {
event.set_definedClass(k);
event.set_definingClassLoader(def_cld);
event.commit();
}
}
void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
ClassLoaderData* loader_data = k->class_loader_data();
Handle class_loader_h(THREAD, loader_data->class_loader());
for (uintx it = 0; it < GCExpandToAllocateDelayMillis; it++){}
if (!class_loader_h.is_null() && !is_parallelCapable(class_loader_h)) {
assert(ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD,
compute_loader_lock_object(class_loader_h, THREAD)),
"define called without lock");
}
Symbol* name_h = k->name();
unsigned int d_hash = dictionary()->compute_hash(name_h, loader_data);
int d_index = dictionary()->hash_to_index(d_hash);
check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK);
if (k->class_loader() != NULL) {
methodHandle m(THREAD, Universe::loader_addClass_method());
JavaValue result(T_VOID);
JavaCallArguments args(class_loader_h);
args.push_oop(Handle(THREAD, k->java_mirror()));
JavaCalls::call(&result, m, &args, CHECK);
}
{
unsigned int p_hash = placeholders()->compute_hash(name_h, loader_data);
int p_index = placeholders()->hash_to_index(p_hash);
MutexLocker mu_r(Compile_lock, THREAD);
add_to_hierarchy(k, CHECK); // No exception, but can block
update_dictionary(d_index, d_hash, p_index, p_hash,
k, class_loader_h, THREAD);
}
k->eager_initialize(THREAD);
if (JvmtiExport::should_post_class_load()) {
assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
JvmtiExport::post_class_load((JavaThread *) THREAD, k());
}
post_class_define_event(k(), loader_data);
}
instanceKlassHandle SystemDictionary::find_or_define_instance_class(Symbol* class_name, Handle class_loader, instanceKlassHandle k, TRAPS) {
instanceKlassHandle nh = instanceKlassHandle(); // null Handle
Symbol* name_h = k->name(); // passed in class_name may be null
ClassLoaderData* loader_data = class_loader_data(class_loader);
unsigned int d_hash = dictionary()->compute_hash(name_h, loader_data);
int d_index = dictionary()->hash_to_index(d_hash);
unsigned int p_hash = placeholders()->compute_hash(name_h, loader_data);
int p_index = placeholders()->hash_to_index(p_hash);
PlaceholderEntry* probe;
{
MutexLocker mu(SystemDictionary_lock, THREAD);
if (UnsyncloadClass || (is_parallelDefine(class_loader))) {
Klass* check = find_class(d_index, d_hash, name_h, loader_data);
if (check != NULL) {
return(instanceKlassHandle(THREAD, check));
}
}
probe = placeholders()->find_and_add(p_index, p_hash, name_h, loader_data, PlaceholderTable::DEFINE_CLASS, NULL, THREAD);
while (probe->definer() != NULL) {
SystemDictionary_lock->wait();
}
if ((UnsyncloadClass || is_parallelDefine(class_loader)) && (probe->instance_klass() != NULL)) {
placeholders()->find_and_remove(p_index, p_hash, name_h, loader_data, PlaceholderTable::DEFINE_CLASS, THREAD);
SystemDictionary_lock->notify_all();
#ifdef ASSERT
Klass* check = find_class(d_index, d_hash, name_h, loader_data);
assert(check != NULL, "definer missed recording success");
#endif
return(instanceKlassHandle(THREAD, probe->instance_klass()));
} else {
probe->set_definer(THREAD);
}
}
define_instance_class(k, THREAD);
Handle linkage_exception = Handle(); // null handle
{
MutexLocker mu(SystemDictionary_lock, THREAD);
PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, name_h, loader_data);
assert(probe != NULL, "DEFINE_CLASS placeholder lost?");
if (probe != NULL) {
if (HAS_PENDING_EXCEPTION) {
linkage_exception = Handle(THREAD,PENDING_EXCEPTION);
CLEAR_PENDING_EXCEPTION;
} else {
probe->set_instance_klass(k());
}
probe->set_definer(NULL);
placeholders()->find_and_remove(p_index, p_hash, name_h, loader_data, PlaceholderTable::DEFINE_CLASS, THREAD);
SystemDictionary_lock->notify_all();
}
}
if (linkage_exception() != NULL) {
THROW_OOP_(linkage_exception(), nh); // throws exception and returns
}
return k;
}
Handle SystemDictionary::compute_loader_lock_object(Handle class_loader, TRAPS) {
if (class_loader.is_null()) {
return Handle(THREAD, _system_loader_lock_obj);
} else {
return class_loader;
}
}
void SystemDictionary::check_loader_lock_contention(Handle loader_lock, TRAPS) {
if (!UsePerfData) {
return;
}
assert(!loader_lock.is_null(), "NULL lock object");
if (ObjectSynchronizer::query_lock_ownership((JavaThread*)THREAD, loader_lock)
== ObjectSynchronizer::owner_other) {
if (loader_lock() == _system_loader_lock_obj) {
ClassLoader::sync_systemLoaderLockContentionRate()->inc();
} else {
ClassLoader::sync_nonSystemLoaderLockContentionRate()->inc();
}
}
}
Klass* SystemDictionary::find_class(int index, unsigned int hash,
Symbol* class_name,
ClassLoaderData* loader_data) {
assert_locked_or_safepoint(SystemDictionary_lock);
assert (index == dictionary()->index_for(class_name, loader_data),
"incorrect index?");
Klass* k = dictionary()->find_class(index, hash, class_name, loader_data);
return k;
}
Symbol* SystemDictionary::find_placeholder(Symbol* class_name,
ClassLoaderData* loader_data) {
assert_locked_or_safepoint(SystemDictionary_lock);
unsigned int p_hash = placeholders()->compute_hash(class_name, loader_data);
int p_index = placeholders()->hash_to_index(p_hash);
return placeholders()->find_entry(p_index, p_hash, class_name, loader_data);
}
Klass* SystemDictionary::find_class(Symbol* class_name, ClassLoaderData* loader_data) {
#ifndef ASSERT
guarantee(VerifyBeforeGC ||
VerifyDuringGC ||
VerifyBeforeExit ||
VerifyDuringStartup ||
VerifyAfterGC, "too expensive");
#endif
assert_locked_or_safepoint(SystemDictionary_lock);
unsigned int d_hash = dictionary()->compute_hash(class_name, loader_data);
int d_index = dictionary()->hash_to_index(d_hash);
return find_class(d_index, d_hash, class_name, loader_data);
}
Klass* SystemDictionary::try_get_next_class() {
return dictionary()->try_get_next_class();
}
void SystemDictionary::add_to_hierarchy(instanceKlassHandle k, TRAPS) {
assert(k.not_null(), "just checking");
assert_locked_or_safepoint(Compile_lock);
k->append_to_sibling_list(); // add to superklass/sibling list
k->process_interfaces(THREAD); // handle all "implements" declarations
k->set_init_state(InstanceKlass::loaded);
Universe::flush_dependents_on(k);
}
void SystemDictionary::always_strong_oops_do(OopClosure* blk) {
roots_oops_do(blk, NULL);
}
void SystemDictionary::always_strong_classes_do(KlassClosure* closure) {
dictionary()->always_strong_classes_do(closure);
placeholders()->classes_do(closure);
}
int SystemDictionary::calculate_systemdictionary_size(int classcount) {
int newsize = _old_default_sdsize;
if ((classcount > 0) && !DumpSharedSpaces) {
int desiredsize = classcount/_average_depth_goal;
for (newsize = _primelist[_sdgeneration]; _sdgeneration < _prime_array_size -1;
newsize = _primelist[++_sdgeneration]) {
if (desiredsize <= newsize) {
break;
}
}
}
return newsize;
}
#ifdef ASSERT
class VerifySDReachableAndLiveClosure : public OopClosure {
private:
BoolObjectClosure* _is_alive;
template <class T> void do_oop_work(T* p) {
oop obj = oopDesc::load_decode_heap_oop(p);
guarantee(_is_alive->do_object_b(obj), "Oop in system dictionary must be live");
}
public:
VerifySDReachableAndLiveClosure(BoolObjectClosure* is_alive) : OopClosure(), _is_alive(is_alive) { }
virtual void do_oop(oop* p) { do_oop_work(p); }
virtual void do_oop(narrowOop* p) { do_oop_work(p); }
};
#endif
bool SystemDictionary::do_unloading(BoolObjectClosure* is_alive, bool clean_alive) {
bool unloading_occurred = ClassLoaderDataGraph::do_unloading(is_alive, clean_alive);
if (unloading_occurred) {
JFR_ONLY(Jfr::on_unloading_classes();)
dictionary()->do_unloading();
constraints()->purge_loader_constraints();
resolution_errors()->purge_resolution_errors();
}
dictionary()->unlink(is_alive);
#ifdef ASSERT
VerifySDReachableAndLiveClosure cl(is_alive);
dictionary()->oops_do(&cl);
#endif
return unloading_occurred;
}
void SystemDictionary::roots_oops_do(OopClosure* strong, OopClosure* weak) {
strong->do_oop(&_java_system_loader);
strong->do_oop(&_system_loader_lock_obj);
CDS_ONLY(SystemDictionaryShared::roots_oops_do(strong);)
dictionary()->roots_oops_do(strong, weak);
invoke_method_table()->oops_do(strong);
}
void SystemDictionary::oops_do(OopClosure* f) {
f->do_oop(&_java_system_loader);
f->do_oop(&_system_loader_lock_obj);
CDS_ONLY(SystemDictionaryShared::oops_do(f);)
dictionary()->oops_do(f);
invoke_method_table()->oops_do(f);
}
void SystemDictionary::preloaded_classes_do(KlassClosure* f) {
for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
f->do_klass(_well_known_klasses[k]);
}
{
for (int i = 0; i < T_VOID+1; i++) {
if (_box_klasses[i] != NULL) {
assert(i >= T_BOOLEAN, "checking");
f->do_klass(_box_klasses[i]);
}
}
}
FilteredFieldsMap::classes_do(f);
}
void SystemDictionary::lazily_loaded_classes_do(KlassClosure* f) {
f->do_klass(_abstract_ownable_synchronizer_klass);
}
void SystemDictionary::classes_do(void f(Klass*)) {
dictionary()->classes_do(f);
}
void SystemDictionary::classes_do(void f(Klass*, TRAPS), TRAPS) {
dictionary()->classes_do(f, CHECK);
}
void SystemDictionary::classes_do(void f(Klass*, ClassLoaderData*)) {
dictionary()->classes_do(f);
}
void SystemDictionary::placeholders_do(void f(Symbol*)) {
placeholders()->entries_do(f);
}
void SystemDictionary::methods_do(void f(Method*)) {
dictionary()->methods_do(f);
invoke_method_table()->methods_do(f);
}
void SystemDictionary::remove_classes_in_error_state() {
dictionary()->remove_classes_in_error_state();
}
void SystemDictionary::load_abstract_ownable_synchronizer_klass(TRAPS) {
assert(JDK_Version::is_gte_jdk16x_version(), "Must be JDK 1.6 or later");
Klass* aos = _abstract_ownable_synchronizer_klass;
if (aos == NULL) {
Klass* k = resolve_or_fail(vmSymbols::java_util_concurrent_locks_AbstractOwnableSynchronizer(), true, CHECK);
OrderAccess::fence();
_abstract_ownable_synchronizer_klass = k;
}
}
void SystemDictionary::initialize(TRAPS) {
assert(dictionary() == NULL,
"SystemDictionary should only be initialized once");
_sdgeneration = 0;
_dictionary = new Dictionary(calculate_systemdictionary_size(PredictedLoadedClassCount));
_placeholders = new PlaceholderTable(_nof_buckets);
_number_of_modifications = 0;
_loader_constraints = new LoaderConstraintTable(_loader_constraint_size);
_resolution_errors = new ResolutionErrorTable(_resolution_error_size);
_invoke_method_table = new SymbolPropertyTable(_invoke_method_size);
_system_loader_lock_obj = oopFactory::new_intArray(0, CHECK);
initialize_preloaded_classes(CHECK);
#if INCLUDE_JFR
jfr_event_handler_proxy = SymbolTable::new_permanent_symbol("jdk/jfr/proxy/internal/EventHandlerProxy", CHECK);
#endif // INCLUDE_JFR
}
static const short wk_init_info[] = {
#define WK_KLASS_INIT_INFO(name, symbol, option) \
( ((int)vmSymbols::VM_SYMBOL_ENUM_NAME(symbol) \
<< SystemDictionary::CEIL_LG_OPTION_LIMIT) \
| (int)SystemDictionary::option ),
WK_KLASSES_DO(WK_KLASS_INIT_INFO)
#undef WK_KLASS_INIT_INFO
0
};
bool SystemDictionary::initialize_wk_klass(WKID id, int init_opt, TRAPS) {
assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob");
int info = wk_init_info[id - FIRST_WKID];
int sid = (info >> CEIL_LG_OPTION_LIMIT);
Symbol* symbol = vmSymbols::symbol_at((vmSymbols::SID)sid);
Klass** klassp = &_well_known_klasses[id];
bool must_load = (init_opt < SystemDictionary::Opt);
if ((*klassp) == NULL) {
if (must_load) {
(*klassp) = resolve_or_fail(symbol, true, CHECK_0); // load required class
} else {
(*klassp) = resolve_or_null(symbol, CHECK_0); // load optional klass
}
}
return ((*klassp) != NULL);
}
void SystemDictionary::initialize_wk_klasses_until(WKID limit_id, WKID &start_id, TRAPS) {
assert((int)start_id <= (int)limit_id, "IDs are out of order!");
for (int id = (int)start_id; id < (int)limit_id; id++) {
assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob");
int info = wk_init_info[id - FIRST_WKID];
int sid = (info >> CEIL_LG_OPTION_LIMIT);
int opt = (info & right_n_bits(CEIL_LG_OPTION_LIMIT));
initialize_wk_klass((WKID)id, opt, CHECK);
}
start_id = limit_id;
}
void SystemDictionary::initialize_preloaded_classes(TRAPS) {
assert(WK_KLASS(Object_klass) == NULL, "preloaded classes should only be initialized once");
WKID scan = FIRST_WKID;
if (UseSharedSpaces) {
initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Object_klass), scan, CHECK);
InstanceKlass* ik = InstanceKlass::cast(Object_klass());
ik->constants()->restore_unshareable_info(CHECK);
initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Class_klass), scan, CHECK);
} else {
initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Class_klass), scan, CHECK);
}
java_lang_String::compute_offsets();
java_lang_Class::compute_offsets();
Universe::initialize_basic_type_mirrors(CHECK);
Universe::fixup_mirrors(CHECK);
initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Reference_klass), scan, CHECK);
InstanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER);
InstanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Cleaner_klass), scan, CHECK);
InstanceKlass::cast(WK_KLASS(SoftReference_klass))->set_reference_type(REF_SOFT);
InstanceKlass::cast(WK_KLASS(WeakReference_klass))->set_reference_type(REF_WEAK);
InstanceKlass::cast(WK_KLASS(FinalReference_klass))->set_reference_type(REF_FINAL);
InstanceKlass::cast(WK_KLASS(PhantomReference_klass))->set_reference_type(REF_PHANTOM);
InstanceKlass::cast(WK_KLASS(Cleaner_klass))->set_reference_type(REF_CLEANER);
initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(ReferenceQueue_klass), scan, CHECK);
WKID jsr292_group_start = WK_KLASS_ENUM_NAME(MethodHandle_klass);
WKID jsr292_group_end = WK_KLASS_ENUM_NAME(VolatileCallSite_klass);
initialize_wk_klasses_until(jsr292_group_start, scan, CHECK);
if (EnableInvokeDynamic) {
initialize_wk_klasses_through(jsr292_group_end, scan, CHECK);
} else {
scan = WKID(jsr292_group_end + 1);
}
initialize_wk_klasses_until(WKID_LIMIT, scan, CHECK);
_box_klasses[T_BOOLEAN] = WK_KLASS(Boolean_klass);
_box_klasses[T_CHAR] = WK_KLASS(Character_klass);
_box_klasses[T_FLOAT] = WK_KLASS(Float_klass);
_box_klasses[T_DOUBLE] = WK_KLASS(Double_klass);
_box_klasses[T_BYTE] = WK_KLASS(Byte_klass);
_box_klasses[T_SHORT] = WK_KLASS(Short_klass);
_box_klasses[T_INT] = WK_KLASS(Integer_klass);
_box_klasses[T_LONG] = WK_KLASS(Long_klass);
{ // Compute whether we should use loadClass or loadClassInternal when loading classes.
Method* method = InstanceKlass::cast(ClassLoader_klass())->find_method(vmSymbols::loadClassInternal_name(), vmSymbols::string_class_signature());
_has_loadClassInternal = (method != NULL);
}
{ // Compute whether we should use checkPackageAccess or NOT
Method* method = InstanceKlass::cast(ClassLoader_klass())->find_method(vmSymbols::checkPackageAccess_name(), vmSymbols::class_protectiondomain_signature());
_has_checkPackageAccess = (method != NULL);
}
}
BasicType SystemDictionary::box_klass_type(Klass* k) {
assert(k != NULL, "");
for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
if (_box_klasses[i] == k)
return (BasicType)i;
}
return T_OBJECT;
}
void SystemDictionary::check_constraints(int d_index, unsigned int d_hash,
instanceKlassHandle k,
Handle class_loader, bool defining,
TRAPS) {
const char *linkage_error = NULL;
{
Symbol* name = k->name();
ClassLoaderData *loader_data = class_loader_data(class_loader);
MutexLocker mu(SystemDictionary_lock, THREAD);
Klass* check = find_class(d_index, d_hash, name, loader_data);
if (check != (Klass*)NULL) {
assert(check->oop_is_instance(), "noninstance in systemdictionary");
if ((defining == true) || (k() != check)) {
linkage_error = "loader (instance of %s): attempted duplicate class "
"definition for name: \"%s\"";
} else {
return;
}
}
#ifdef ASSERT
Symbol* ph_check = find_placeholder(name, loader_data);
assert(ph_check == NULL || ph_check == name, "invalid symbol");
#endif
if (linkage_error == NULL) {
if (constraints()->check_or_update(k, class_loader, name) == false) {
linkage_error = "loader constraint violation: loader (instance of %s)"
" previously initiated loading for a different type with name \"%s\"";
}
}
}
if (linkage_error) {
ResourceMark rm(THREAD);
const char* class_loader_name = loader_name(class_loader());
char* type_name = k->name()->as_C_string();
size_t buflen = strlen(linkage_error) + strlen(class_loader_name) +
strlen(type_name);
char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen);
jio_snprintf(buf, buflen, linkage_error, class_loader_name, type_name);
THROW_MSG(vmSymbols::java_lang_LinkageError(), buf);
}
}
void SystemDictionary::update_dictionary(int d_index, unsigned int d_hash,
int p_index, unsigned int p_hash,
instanceKlassHandle k,
Handle class_loader,
TRAPS) {
assert_locked_or_safepoint(Compile_lock);
Symbol* name = k->name();
ClassLoaderData *loader_data = class_loader_data(class_loader);
{
MutexLocker mu1(SystemDictionary_lock, THREAD);
if (UseBiasedLocking && BiasedLocking::enabled()) {
if (k->class_loader() == class_loader()) {
k->set_prototype_header(markOopDesc::biased_locking_prototype());
}
}
Klass* sd_check = find_class(d_index, d_hash, name, loader_data);
if (sd_check == NULL) {
dictionary()->add_klass(name, loader_data, k);
notice_modification();
}
#ifdef ASSERT
sd_check = find_class(d_index, d_hash, name, loader_data);
assert (sd_check != NULL, "should have entry in system dictionary");
#endif
SystemDictionary_lock->notify_all();
}
}
Klass* SystemDictionary::find_constrained_instance_or_array_klass(
Symbol* class_name, Handle class_loader, TRAPS) {
Handle no_protection_domain;
Klass* klass = find_instance_or_array_klass(class_name, class_loader,
no_protection_domain, CHECK_NULL);
if (klass != NULL)
return klass;
if (FieldType::is_array(class_name)) {
FieldArrayInfo fd;
BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(NULL));
if (t != T_OBJECT) {
klass = Universe::typeArrayKlassObj(t);
} else {
MutexLocker mu(SystemDictionary_lock, THREAD);
klass = constraints()->find_constrained_klass(fd.object_key(), class_loader);
}
if (klass != NULL) {
klass = klass->array_klass_or_null(fd.dimension());
}
} else {
MutexLocker mu(SystemDictionary_lock, THREAD);
klass = constraints()->find_constrained_klass(class_name, class_loader);
}
return klass;
}
bool SystemDictionary::add_loader_constraint(Symbol* class_name,
Handle class_loader1,
Handle class_loader2,
Thread* THREAD) {
ClassLoaderData* loader_data1 = class_loader_data(class_loader1);
ClassLoaderData* loader_data2 = class_loader_data(class_loader2);
Symbol* constraint_name = NULL;
if (!FieldType::is_array(class_name)) {
constraint_name = class_name;
} else {
FieldArrayInfo fd;
BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(false));
if (t != T_OBJECT) {
return true;
} else {
constraint_name = fd.object_key();
}
}
unsigned int d_hash1 = dictionary()->compute_hash(constraint_name, loader_data1);
int d_index1 = dictionary()->hash_to_index(d_hash1);
unsigned int d_hash2 = dictionary()->compute_hash(constraint_name, loader_data2);
int d_index2 = dictionary()->hash_to_index(d_hash2);
{
MutexLocker mu_s(SystemDictionary_lock, THREAD);
No_Safepoint_Verifier nosafepoint;
Klass* klass1 = find_class(d_index1, d_hash1, constraint_name, loader_data1);
Klass* klass2 = find_class(d_index2, d_hash2, constraint_name, loader_data2);
return constraints()->add_entry(constraint_name, klass1, class_loader1,
klass2, class_loader2);
}
}
void SystemDictionary::add_resolution_error(constantPoolHandle pool, int which,
Symbol* error, Symbol* message) {
unsigned int hash = resolution_errors()->compute_hash(pool, which);
int index = resolution_errors()->hash_to_index(hash);
{
MutexLocker ml(SystemDictionary_lock, Thread::current());
resolution_errors()->add_entry(index, hash, pool, which, error, message);
}
}
void SystemDictionary::delete_resolution_error(ConstantPool* pool) {
resolution_errors()->delete_entry(pool);
}
Symbol* SystemDictionary::find_resolution_error(constantPoolHandle pool, int which,
Symbol** message) {
unsigned int hash = resolution_errors()->compute_hash(pool, which);
int index = resolution_errors()->hash_to_index(hash);
{
MutexLocker ml(SystemDictionary_lock, Thread::current());
ResolutionErrorEntry* entry = resolution_errors()->find_entry(index, hash, pool, which);
if (entry != NULL) {
return entry->error();
} else {
return NULL;
}
}
}
Symbol* SystemDictionary::check_signature_loaders(Symbol* signature,
Handle loader1, Handle loader2,
bool is_method, TRAPS) {
if (loader1() == loader2()) {
return NULL;
}
SignatureStream sig_strm(signature, is_method);
while (!sig_strm.is_done()) {
if (sig_strm.is_object()) {
Symbol* sig = sig_strm.as_symbol(CHECK_NULL);
if (!add_loader_constraint(sig, loader1, loader2, THREAD)) {
return sig;
}
}
sig_strm.next();
}
return NULL;
}
methodHandle SystemDictionary::find_method_handle_intrinsic(vmIntrinsics::ID iid,
Symbol* signature,
TRAPS) {
methodHandle empty;
assert(EnableInvokeDynamic, "");
assert(MethodHandles::is_signature_polymorphic(iid) &&
MethodHandles::is_signature_polymorphic_intrinsic(iid) &&
iid != vmIntrinsics::_invokeGeneric,
err_msg("must be a known MH intrinsic iid=%d: %s", iid, vmIntrinsics::name_at(iid)));
unsigned int hash = invoke_method_table()->compute_hash(signature, iid);
int index = invoke_method_table()->hash_to_index(hash);
SymbolPropertyEntry* spe = invoke_method_table()->find_entry(index, hash, signature, iid);
methodHandle m;
if (spe == NULL || spe->method() == NULL) {
spe = NULL;
m = Method::make_method_handle_intrinsic(iid, signature, CHECK_(empty));
if (!Arguments::is_interpreter_only()) {
AdapterHandlerLibrary::create_native_wrapper(m);
if (!m->has_compiled_code()) {
THROW_MSG_(vmSymbols::java_lang_VirtualMachineError(),
"out of space in CodeCache for method handle intrinsic", empty);
}
}
{
MutexLocker ml(SystemDictionary_lock, THREAD);
spe = invoke_method_table()->find_entry(index, hash, signature, iid);
if (spe == NULL)
spe = invoke_method_table()->add_entry(index, hash, signature, iid);
if (spe->method() == NULL)
spe->set_method(m());
}
}
assert(spe != NULL && spe->method() != NULL, "");
assert(Arguments::is_interpreter_only() || (spe->method()->has_compiled_code() &&
spe->method()->code()->entry_point() == spe->method()->from_compiled_entry()),
"MH intrinsic invariant");
return spe->method();
}
static methodHandle unpack_method_and_appendix(Handle mname,
KlassHandle accessing_klass,
objArrayHandle appendix_box,
Handle* appendix_result,
TRAPS) {
methodHandle empty;
if (mname.not_null()) {
Metadata* vmtarget = java_lang_invoke_MemberName::vmtarget(mname());
if (vmtarget != NULL && vmtarget->is_method()) {
Method* m = (Method*)vmtarget;
oop appendix = appendix_box->obj_at(0);
if (TraceMethodHandles) {
#ifndef PRODUCT
tty->print("Linked method=" INTPTR_FORMAT ": ", p2i(m));
m->print();
if (appendix != NULL) { tty->print("appendix = "); appendix->print(); }
tty->cr();
#endif //PRODUCT
}
(*appendix_result) = Handle(THREAD, appendix);
ClassLoaderData* this_key = InstanceKlass::cast(accessing_klass())->class_loader_data();
this_key->record_dependency(m->method_holder(), CHECK_NULL); // Can throw OOM
return methodHandle(THREAD, m);
}
}
THROW_MSG_(vmSymbols::java_lang_LinkageError(), "bad value from MethodHandleNatives", empty);
return empty;
}
methodHandle SystemDictionary::find_method_handle_invoker(Symbol* name,
Symbol* signature,
KlassHandle accessing_klass,
Handle *appendix_result,
Handle *method_type_result,
TRAPS) {
methodHandle empty;
assert(EnableInvokeDynamic, "");
assert(!THREAD->is_Compiler_thread(), "");
Handle method_type =
SystemDictionary::find_method_handle_type(signature, accessing_klass, CHECK_(empty));
KlassHandle mh_klass = SystemDictionary::MethodHandle_klass();
int ref_kind = JVM_REF_invokeVirtual;
Handle name_str = StringTable::intern(name, CHECK_(empty));
objArrayHandle appendix_box = oopFactory::new_objArray(SystemDictionary::Object_klass(), 1, CHECK_(empty));
assert(appendix_box->obj_at(0) == NULL, "");
if (accessing_klass.is_null() || method_type.is_null()) {
THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad invokehandle", empty);
}
JavaCallArguments args;
args.push_oop(accessing_klass()->java_mirror());
args.push_int(ref_kind);
args.push_oop(mh_klass()->java_mirror());
args.push_oop(name_str());
args.push_oop(method_type());
args.push_oop(appendix_box());
JavaValue result(T_OBJECT);
JavaCalls::call_static(&result,
SystemDictionary::MethodHandleNatives_klass(),
vmSymbols::linkMethod_name(),
vmSymbols::linkMethod_signature(),
&args, CHECK_(empty));
Handle mname(THREAD, (oop) result.get_jobject());
(*method_type_result) = method_type;
return unpack_method_and_appendix(mname, accessing_klass, appendix_box, appendix_result, THREAD);
}
static bool is_always_visible_class(oop mirror) {
Klass* klass = java_lang_Class::as_Klass(mirror);
if (klass->oop_is_objArray()) {
klass = ObjArrayKlass::cast(klass)->bottom_klass(); // check element type
}
if (klass->oop_is_typeArray()) {
return true; // primitive array
}
assert(klass->oop_is_instance(), klass->external_name());
return klass->is_public() &&
(InstanceKlass::cast(klass)->is_same_class_package(SystemDictionary::Object_klass()) || // java.lang
InstanceKlass::cast(klass)->is_same_class_package(SystemDictionary::MethodHandle_klass())); // java.lang.invoke
}
Handle SystemDictionary::find_method_handle_type(Symbol* signature,
KlassHandle accessing_klass,
TRAPS) {
Handle empty;
vmIntrinsics::ID null_iid = vmIntrinsics::_none; // distinct from all method handle invoker intrinsics
unsigned int hash = invoke_method_table()->compute_hash(signature, null_iid);
int index = invoke_method_table()->hash_to_index(hash);
SymbolPropertyEntry* spe = invoke_method_table()->find_entry(index, hash, signature, null_iid);
if (spe != NULL && spe->method_type() != NULL) {
assert(java_lang_invoke_MethodType::is_instance(spe->method_type()), "");
return Handle(THREAD, spe->method_type());
} else if (THREAD->is_Compiler_thread()) {
warning("SystemDictionary::find_method_handle_type called from compiler thread"); // FIXME
return Handle(); // do not attempt from within compiler, unless it was cached
}
Handle class_loader, protection_domain;
if (accessing_klass.not_null()) {
class_loader = Handle(THREAD, InstanceKlass::cast(accessing_klass())->class_loader());
protection_domain = Handle(THREAD, InstanceKlass::cast(accessing_klass())->protection_domain());
}
bool can_be_cached = true;
int npts = ArgumentCount(signature).size();
objArrayHandle pts = oopFactory::new_objArray(SystemDictionary::Class_klass(), npts, CHECK_(empty));
int arg = 0;
Handle rt; // the return type from the signature
ResourceMark rm(THREAD);
for (SignatureStream ss(signature); !ss.is_done(); ss.next()) {
oop mirror = NULL;
if (can_be_cached) {
mirror = ss.as_java_mirror(Handle(), Handle(),
SignatureStream::ReturnNull, CHECK_(empty));
if (mirror == NULL || (ss.is_object() && !is_always_visible_class(mirror))) {
can_be_cached = false;
}
}
if (!can_be_cached) {
mirror = ss.as_java_mirror(class_loader, protection_domain,
SignatureStream::NCDFError, CHECK_(empty));
}
assert(!oopDesc::is_null(mirror), ss.as_symbol(THREAD)->as_C_string());
if (ss.at_return_type())
rt = Handle(THREAD, mirror);
else
pts->obj_at_put(arg++, mirror);
if (ss.is_object() && accessing_klass.not_null()) {
Klass* sel_klass = java_lang_Class::as_Klass(mirror);
mirror = NULL; // safety
if (sel_klass->oop_is_objArray())
sel_klass = ObjArrayKlass::cast(sel_klass)->bottom_klass();
if (sel_klass->oop_is_instance()) {
KlassHandle sel_kh(THREAD, sel_klass);
LinkResolver::check_klass_accessability(accessing_klass, sel_kh, CHECK_(empty));
}
}
}
assert(arg == npts, "");
JavaCallArguments args(Handle(THREAD, rt()));
args.push_oop(pts());
JavaValue result(T_OBJECT);
JavaCalls::call_static(&result,
SystemDictionary::MethodHandleNatives_klass(),
vmSymbols::findMethodHandleType_name(),
vmSymbols::findMethodHandleType_signature(),
&args, CHECK_(empty));
Handle method_type(THREAD, (oop) result.get_jobject());
if (can_be_cached) {
MutexLocker ml(SystemDictionary_lock, THREAD);
spe = invoke_method_table()->find_entry(index, hash, signature, null_iid);
if (spe == NULL)
spe = invoke_method_table()->add_entry(index, hash, signature, null_iid);
if (spe->method_type() == NULL) {
spe->set_method_type(method_type());
}
}
return method_type;
}
Handle SystemDictionary::link_method_handle_constant(KlassHandle caller,
int ref_kind, //e.g., JVM_REF_invokeVirtual
KlassHandle callee,
Symbol* name_sym,
Symbol* signature,
TRAPS) {
Handle empty;
Handle name = java_lang_String::create_from_symbol(name_sym, CHECK_(empty));
Handle type;
if (signature->utf8_length() > 0 && signature->byte_at(0) == '(') {
type = find_method_handle_type(signature, caller, CHECK_(empty));
} else if (caller.is_null()) {
THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad MH constant", empty);
} else {
ResourceMark rm(THREAD);
SignatureStream ss(signature, false);
if (!ss.is_done()) {
oop mirror = ss.as_java_mirror(caller->class_loader(), caller->protection_domain(),
SignatureStream::NCDFError, CHECK_(empty));
type = Handle(THREAD, mirror);
ss.next();
if (!ss.is_done()) type = Handle(); // error!
}
}
if (type.is_null()) {
THROW_MSG_(vmSymbols::java_lang_LinkageError(), "bad signature", empty);
}
JavaCallArguments args;
args.push_oop(caller->java_mirror()); // the referring class
args.push_int(ref_kind);
args.push_oop(callee->java_mirror()); // the target class
args.push_oop(name());
args.push_oop(type());
JavaValue result(T_OBJECT);
JavaCalls::call_static(&result,
SystemDictionary::MethodHandleNatives_klass(),
vmSymbols::linkMethodHandleConstant_name(),
vmSymbols::linkMethodHandleConstant_signature(),
&args, CHECK_(empty));
return Handle(THREAD, (oop) result.get_jobject());
}
methodHandle SystemDictionary::find_dynamic_call_site_invoker(KlassHandle caller,
Handle bootstrap_specifier,
Symbol* name,
Symbol* type,
Handle *appendix_result,
Handle *method_type_result,
TRAPS) {
methodHandle empty;
Handle bsm, info;
if (java_lang_invoke_MethodHandle::is_instance(bootstrap_specifier())) {
bsm = bootstrap_specifier;
} else {
assert(bootstrap_specifier->is_objArray(), "");
objArrayHandle args(THREAD, (objArrayOop) bootstrap_specifier());
int len = args->length();
assert(len >= 1, "");
bsm = Handle(THREAD, args->obj_at(0));
if (len > 1) {
objArrayOop args1 = oopFactory::new_objArray(SystemDictionary::Object_klass(), len-1, CHECK_(empty));
for (int i = 1; i < len; i++)
args1->obj_at_put(i-1, args->obj_at(i));
info = Handle(THREAD, args1);
}
}
guarantee(java_lang_invoke_MethodHandle::is_instance(bsm()),
"caller must supply a valid BSM");
Handle method_name = java_lang_String::create_from_symbol(name, CHECK_(empty));
Handle method_type = find_method_handle_type(type, caller, CHECK_(empty));
if (caller.is_null() || method_type.is_null()) {
THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad invokedynamic", empty);
}
objArrayHandle appendix_box = oopFactory::new_objArray(SystemDictionary::Object_klass(), 1, CHECK_(empty));
assert(appendix_box->obj_at(0) == NULL, "");
JavaCallArguments args;
args.push_oop(caller->java_mirror());
args.push_oop(bsm());
args.push_oop(method_name());
args.push_oop(method_type());
args.push_oop(info());
args.push_oop(appendix_box);
JavaValue result(T_OBJECT);
JavaCalls::call_static(&result,
SystemDictionary::MethodHandleNatives_klass(),
vmSymbols::linkCallSite_name(),
vmSymbols::linkCallSite_signature(),
&args, CHECK_(empty));
Handle mname(THREAD, (oop) result.get_jobject());
(*method_type_result) = method_type;
return unpack_method_and_appendix(mname, caller, appendix_box, appendix_result, THREAD);
}
void SystemDictionary::reorder_dictionary() {
dictionary()->reorder_dictionary();
}
void SystemDictionary::copy_buckets(char** top, char* end) {
dictionary()->copy_buckets(top, end);
}
void SystemDictionary::copy_table(char** top, char* end) {
dictionary()->copy_table(top, end);
}
void SystemDictionary::reverse() {
dictionary()->reverse();
}
int SystemDictionary::number_of_classes() {
return dictionary()->number_of_entries();
}
void SystemDictionary::print_shared(bool details) {
shared_dictionary()->print(details);
}
void SystemDictionary::print(bool details) {
dictionary()->print(details);
GCMutexLocker mu(SystemDictionary_lock);
placeholders()->print();
constraints()->print();
}
void SystemDictionary::verify() {
guarantee(dictionary() != NULL, "Verify of system dictionary failed");
guarantee(constraints() != NULL,
"Verify of loader constraints failed");
guarantee(dictionary()->number_of_entries() >= 0 &&
placeholders()->number_of_entries() >= 0,
"Verify of system dictionary failed");
dictionary()->verify();
GCMutexLocker mu(SystemDictionary_lock);
placeholders()->verify();
guarantee(constraints() != NULL, "Verify of loader constraints failed");
constraints()->verify(dictionary(), placeholders());
}
#ifndef PRODUCT
class ClassStatistics: AllStatic {
private:
static int nclasses; // number of classes
static int nmethods; // number of methods
static int nmethoddata; // number of methodData
static int class_size; // size of class objects in words
static int method_size; // size of method objects in words
static int debug_size; // size of debug info in methods
static int methoddata_size; // size of methodData objects in words
static void do_class(Klass* k) {
nclasses++;
class_size += k->size();
if (k->oop_is_instance()) {
InstanceKlass* ik = (InstanceKlass*)k;
class_size += ik->methods()->size();
class_size += ik->constants()->size();
class_size += ik->local_interfaces()->size();
class_size += ik->transitive_interfaces()->size();
}
}
static void do_method(Method* m) {
nmethods++;
method_size += m->size();
if (m->has_stackmap_table()) {
method_size += m->stackmap_data()->size();
}
MethodData* mdo = m->method_data();
if (mdo != NULL) {
nmethoddata++;
methoddata_size += mdo->size();
}
}
public:
static void print() {
SystemDictionary::classes_do(do_class);
SystemDictionary::methods_do(do_method);
tty->print_cr("Class statistics:");
tty->print_cr("%d classes (%d bytes)", nclasses, class_size * oopSize);
tty->print_cr("%d methods (%d bytes = %d base + %d debug info)", nmethods,
(method_size + debug_size) * oopSize, method_size * oopSize, debug_size * oopSize);
tty->print_cr("%d methoddata (%d bytes)", nmethoddata, methoddata_size * oopSize);
}
};
int ClassStatistics::nclasses = 0;
int ClassStatistics::nmethods = 0;
int ClassStatistics::nmethoddata = 0;
int ClassStatistics::class_size = 0;
int ClassStatistics::method_size = 0;
int ClassStatistics::debug_size = 0;
int ClassStatistics::methoddata_size = 0;
void SystemDictionary::print_class_statistics() {
ResourceMark rm;
ClassStatistics::print();
}
class MethodStatistics: AllStatic {
public:
enum {
max_parameter_size = 10
};
private:
static int _number_of_methods;
static int _number_of_final_methods;
static int _number_of_static_methods;
static int _number_of_native_methods;
static int _number_of_synchronized_methods;
static int _number_of_profiled_methods;
static int _number_of_bytecodes;
static int _parameter_size_profile[max_parameter_size];
static int _bytecodes_profile[Bytecodes::number_of_java_codes];
static void initialize() {
_number_of_methods = 0;
_number_of_final_methods = 0;
_number_of_static_methods = 0;
_number_of_native_methods = 0;
_number_of_synchronized_methods = 0;
_number_of_profiled_methods = 0;
_number_of_bytecodes = 0;
for (int i = 0; i < max_parameter_size ; i++) _parameter_size_profile[i] = 0;
for (int j = 0; j < Bytecodes::number_of_java_codes; j++) _bytecodes_profile [j] = 0;
};
static void do_method(Method* m) {
_number_of_methods++;
if (m->is_final() ) _number_of_final_methods++;
if (m->is_static() ) _number_of_static_methods++;
if (m->is_native() ) _number_of_native_methods++;
if (m->is_synchronized()) _number_of_synchronized_methods++;
if (m->method_data() != NULL) _number_of_profiled_methods++;
_parameter_size_profile[MIN2(m->size_of_parameters() + (m->is_static() ? 0 : 1), max_parameter_size - 1)]++;
{
Thread *thread = Thread::current();
HandleMark hm(thread);
BytecodeStream s(methodHandle(thread, m));
Bytecodes::Code c;
while ((c = s.next()) >= 0) {
_number_of_bytecodes++;
_bytecodes_profile[c]++;
}
}
}
public:
static void print() {
initialize();
SystemDictionary::methods_do(do_method);
tty->cr();
tty->print_cr("Method statistics (static):");
tty->cr();
tty->print_cr("%6d final methods %6.1f%%", _number_of_final_methods , _number_of_final_methods * 100.0F / _number_of_methods);
tty->print_cr("%6d static methods %6.1f%%", _number_of_static_methods , _number_of_static_methods * 100.0F / _number_of_methods);
tty->print_cr("%6d native methods %6.1f%%", _number_of_native_methods , _number_of_native_methods * 100.0F / _number_of_methods);
tty->print_cr("%6d synchronized methods %6.1f%%", _number_of_synchronized_methods, _number_of_synchronized_methods * 100.0F / _number_of_methods);
tty->print_cr("%6d profiled methods %6.1f%%", _number_of_profiled_methods, _number_of_profiled_methods * 100.0F / _number_of_methods);
tty->cr();
{ int tot = 0;
int avg = 0;
for (int i = 0; i < max_parameter_size; i++) {
int n = _parameter_size_profile[i];
tot += n;
avg += n*i;
tty->print_cr("parameter size = %1d: %6d methods %5.1f%%", i, n, n * 100.0F / _number_of_methods);
}
assert(tot == _number_of_methods, "should be the same");
tty->print_cr(" %6d methods 100.0%%", _number_of_methods);
tty->print_cr("(average parameter size = %3.1f including receiver, if any)", (float)avg / _number_of_methods);
}
tty->cr();
{ int tot = 0;
for (int i = 0; i < Bytecodes::number_of_java_codes; i++) {
if (Bytecodes::is_defined(i)) {
Bytecodes::Code c = Bytecodes::cast(i);
int n = _bytecodes_profile[c];
tot += n;
tty->print_cr("%9d %7.3f%% %s", n, n * 100.0F / _number_of_bytecodes, Bytecodes::name(c));
}
}
assert(tot == _number_of_bytecodes, "should be the same");
tty->print_cr("%9d 100.000%%", _number_of_bytecodes);
}
tty->cr();
}
};
int MethodStatistics::_number_of_methods;
int MethodStatistics::_number_of_final_methods;
int MethodStatistics::_number_of_static_methods;
int MethodStatistics::_number_of_native_methods;
int MethodStatistics::_number_of_synchronized_methods;
int MethodStatistics::_number_of_profiled_methods;
int MethodStatistics::_number_of_bytecodes;
int MethodStatistics::_parameter_size_profile[MethodStatistics::max_parameter_size];
int MethodStatistics::_bytecodes_profile[Bytecodes::number_of_java_codes];
void SystemDictionary::print_method_statistics() {
MethodStatistics::print();
}
#endif // PRODUCT
C:\hotspot-69087d08d473\src\share\vm/classfile/systemDictionary.hpp
#ifndef SHARE_VM_CLASSFILE_SYSTEMDICTIONARY_HPP
#define SHARE_VM_CLASSFILE_SYSTEMDICTIONARY_HPP
#include "classfile/classFileStream.hpp"
#include "classfile/classLoader.hpp"
#include "oops/objArrayOop.hpp"
#include "oops/symbol.hpp"
#include "runtime/java.hpp"
#include "runtime/reflectionUtils.hpp"
#include "utilities/hashtable.hpp"
#include "utilities/hashtable.inline.hpp"
class Dictionary;
class PlaceholderTable;
class LoaderConstraintTable;
template <MEMFLAGS F> class HashtableBucket;
class ResolutionErrorTable;
class SymbolPropertyTable;
#define WK_KLASS_ENUM_NAME(kname) kname##_knum
#define WK_KLASSES_DO(do_klass) \
do_klass(Object_klass, java_lang_Object, Pre ) \
do_klass(String_klass, java_lang_String, Pre ) \
do_klass(Class_klass, java_lang_Class, Pre ) \
do_klass(Cloneable_klass, java_lang_Cloneable, Pre ) \
do_klass(ClassLoader_klass, java_lang_ClassLoader, Pre ) \
do_klass(Serializable_klass, java_io_Serializable, Pre ) \
do_klass(System_klass, java_lang_System, Pre ) \
do_klass(Throwable_klass, java_lang_Throwable, Pre ) \
do_klass(Error_klass, java_lang_Error, Pre ) \
do_klass(ThreadDeath_klass, java_lang_ThreadDeath, Pre ) \
do_klass(Exception_klass, java_lang_Exception, Pre ) \
do_klass(RuntimeException_klass, java_lang_RuntimeException, Pre ) \
do_klass(SecurityManager_klass, java_lang_SecurityManager, Pre ) \
do_klass(ProtectionDomain_klass, java_security_ProtectionDomain, Pre ) \
do_klass(AccessControlContext_klass, java_security_AccessControlContext, Pre ) \
do_klass(SecureClassLoader_klass, java_security_SecureClassLoader, Pre ) \
do_klass(ClassNotFoundException_klass, java_lang_ClassNotFoundException, Pre ) \
do_klass(NoClassDefFoundError_klass, java_lang_NoClassDefFoundError, Pre ) \
do_klass(LinkageError_klass, java_lang_LinkageError, Pre ) \
do_klass(ClassCastException_klass, java_lang_ClassCastException, Pre ) \
do_klass(ArrayStoreException_klass, java_lang_ArrayStoreException, Pre ) \
do_klass(VirtualMachineError_klass, java_lang_VirtualMachineError, Pre ) \
do_klass(OutOfMemoryError_klass, java_lang_OutOfMemoryError, Pre ) \
do_klass(StackOverflowError_klass, java_lang_StackOverflowError, Pre ) \
do_klass(IllegalMonitorStateException_klass, java_lang_IllegalMonitorStateException, Pre ) \
do_klass(Reference_klass, java_lang_ref_Reference, Pre ) \
\
do_klass(SoftReference_klass, java_lang_ref_SoftReference, Pre ) \
do_klass(WeakReference_klass, java_lang_ref_WeakReference, Pre ) \
do_klass(FinalReference_klass, java_lang_ref_FinalReference, Pre ) \
do_klass(PhantomReference_klass, java_lang_ref_PhantomReference, Pre ) \
do_klass(Cleaner_klass, sun_misc_Cleaner, Pre ) \
do_klass(Finalizer_klass, java_lang_ref_Finalizer, Pre ) \
do_klass(ReferenceQueue_klass, java_lang_ref_ReferenceQueue, Pre ) \
\
do_klass(Thread_klass, java_lang_Thread, Pre ) \
do_klass(ThreadGroup_klass, java_lang_ThreadGroup, Pre ) \
do_klass(Properties_klass, java_util_Properties, Pre ) \
do_klass(reflect_AccessibleObject_klass, java_lang_reflect_AccessibleObject, Pre ) \
do_klass(reflect_Field_klass, java_lang_reflect_Field, Pre ) \
do_klass(reflect_Parameter_klass, java_lang_reflect_Parameter, Opt ) \
do_klass(reflect_Method_klass, java_lang_reflect_Method, Pre ) \
do_klass(reflect_Constructor_klass, java_lang_reflect_Constructor, Pre ) \
\
do_klass(reflect_MagicAccessorImpl_klass, sun_reflect_MagicAccessorImpl, Opt ) \
do_klass(reflect_MethodAccessorImpl_klass, sun_reflect_MethodAccessorImpl, Opt_Only_JDK14NewRef) \
do_klass(reflect_ConstructorAccessorImpl_klass, sun_reflect_ConstructorAccessorImpl, Opt_Only_JDK14NewRef) \
do_klass(reflect_DelegatingClassLoader_klass, sun_reflect_DelegatingClassLoader, Opt ) \
do_klass(reflect_ConstantPool_klass, sun_reflect_ConstantPool, Opt_Only_JDK15 ) \
do_klass(reflect_UnsafeStaticFieldAccessorImpl_klass, sun_reflect_UnsafeStaticFieldAccessorImpl, Opt_Only_JDK15 ) \
do_klass(reflect_CallerSensitive_klass, sun_reflect_CallerSensitive, Opt ) \
\
do_klass(DirectMethodHandle_klass, java_lang_invoke_DirectMethodHandle, Opt ) \
do_klass(MethodHandle_klass, java_lang_invoke_MethodHandle, Pre_JSR292 ) \
do_klass(MemberName_klass, java_lang_invoke_MemberName, Pre_JSR292 ) \
do_klass(MethodHandleNatives_klass, java_lang_invoke_MethodHandleNatives, Pre_JSR292 ) \
do_klass(LambdaForm_klass, java_lang_invoke_LambdaForm, Opt ) \
do_klass(MethodType_klass, java_lang_invoke_MethodType, Pre_JSR292 ) \
do_klass(BootstrapMethodError_klass, java_lang_BootstrapMethodError, Pre_JSR292 ) \
do_klass(CallSite_klass, java_lang_invoke_CallSite, Pre_JSR292 ) \
do_klass(ConstantCallSite_klass, java_lang_invoke_ConstantCallSite, Pre_JSR292 ) \
do_klass(MutableCallSite_klass, java_lang_invoke_MutableCallSite, Pre_JSR292 ) \
do_klass(VolatileCallSite_klass, java_lang_invoke_VolatileCallSite, Pre_JSR292 ) \
\
do_klass(StringBuffer_klass, java_lang_StringBuffer, Pre ) \
do_klass(StringBuilder_klass, java_lang_StringBuilder, Pre ) \
do_klass(misc_Unsafe_klass, sun_misc_Unsafe, Pre ) \
\
do_klass(ByteArrayInputStream_klass, java_io_ByteArrayInputStream, Pre ) \
do_klass(File_klass, java_io_File, Pre ) \
do_klass(URLClassLoader_klass, java_net_URLClassLoader, Pre ) \
do_klass(URL_klass, java_net_URL, Pre ) \
do_klass(Jar_Manifest_klass, java_util_jar_Manifest, Pre ) \
do_klass(sun_misc_Launcher_klass, sun_misc_Launcher, Pre ) \
do_klass(sun_misc_Launcher_AppClassLoader_klass, sun_misc_Launcher_AppClassLoader, Pre ) \
do_klass(sun_misc_Launcher_ExtClassLoader_klass, sun_misc_Launcher_ExtClassLoader, Pre ) \
do_klass(CodeSource_klass, java_security_CodeSource, Pre ) \
\
do_klass(StackTraceElement_klass, java_lang_StackTraceElement, Opt ) \
do_klass(nio_Buffer_klass, java_nio_Buffer, Opt ) \
\
do_klass(Boolean_klass, java_lang_Boolean, Pre ) \
do_klass(Character_klass, java_lang_Character, Pre ) \
do_klass(Float_klass, java_lang_Float, Pre ) \
do_klass(Double_klass, java_lang_Double, Pre ) \
do_klass(Byte_klass, java_lang_Byte, Pre ) \
do_klass(Short_klass, java_lang_Short, Pre ) \
do_klass(Integer_klass, java_lang_Integer, Pre ) \
do_klass(Long_klass, java_lang_Long, Pre ) \
class SystemDictionary : AllStatic {
friend class VMStructs;
friend class SystemDictionaryHandles;
public:
enum WKID {
NO_WKID = 0,
#define WK_KLASS_ENUM(name, symbol, ignore_o) WK_KLASS_ENUM_NAME(name), WK_KLASS_ENUM_NAME(symbol) = WK_KLASS_ENUM_NAME(name),
WK_KLASSES_DO(WK_KLASS_ENUM)
#undef WK_KLASS_ENUM
WKID_LIMIT,
FIRST_WKID = NO_WKID + 1
};
enum InitOption {
Pre, // preloaded; error if not present
Pre_JSR292, // preloaded if EnableInvokeDynamic
Opt, // preload tried; NULL if not present
Opt_Only_JDK14NewRef, // preload tried; use only with NewReflection
Opt_Only_JDK15, // preload tried; use only with JDK1.5+
OPTION_LIMIT,
CEIL_LG_OPTION_LIMIT = 4 // OPTION_LIMIT <= (1<<CEIL_LG_OPTION_LIMIT)
};
static Klass* resolve_or_fail(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS);
static Klass* resolve_or_fail(Symbol* class_name, bool throw_error, TRAPS);
protected:
static Klass* handle_resolution_exception(Symbol* class_name, bool throw_error, KlassHandle klass_h, TRAPS);
public:
static Klass* resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
static Klass* resolve_or_null(Symbol* class_name, TRAPS);
static Klass* resolve_super_or_fail(Symbol* child_name,
Symbol* class_name,
Handle class_loader,
Handle protection_domain,
bool is_superclass,
TRAPS);
static Klass* parse_stream(Symbol* class_name,
Handle class_loader,
Handle protection_domain,
ClassFileStream* st,
TRAPS) {
KlassHandle nullHandle;
return parse_stream(class_name, class_loader, protection_domain, st, nullHandle, NULL, THREAD);
}
static Klass* parse_stream(Symbol* class_name,
Handle class_loader,
Handle protection_domain,
ClassFileStream* st,
KlassHandle host_klass,
GrowableArray<Handle>* cp_patches,
TRAPS);
static Klass* resolve_from_stream(Symbol* class_name, Handle class_loader,
Handle protection_domain,
ClassFileStream* st, bool verify, TRAPS);
static Klass* find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
static Klass* find_instance_or_array_klass(Symbol* class_name,
Handle class_loader,
Handle protection_domain,
TRAPS);
static Klass* find_constrained_instance_or_array_klass(Symbol* class_name,
Handle class_loader,
TRAPS);
static void classes_do(void f(Klass*));
static void classes_do(void f(Klass*, TRAPS), TRAPS);
static void classes_do(void f(Klass*, ClassLoaderData*));
static void placeholders_do(void f(Symbol*));
static void methods_do(void f(Method*));
static void always_strong_oops_do(OopClosure* blk);
static void always_strong_classes_do(KlassClosure* closure);
static bool do_unloading(BoolObjectClosure* is_alive, bool clean_alive = true);
static void remove_classes_in_error_state();
static int calculate_systemdictionary_size(int loadedclasses);
static void oops_do(OopClosure* f);
static void roots_oops_do(OopClosure* strong, OopClosure* weak);
static oop system_loader_lock() { return _system_loader_lock_obj; }
protected:
static void preloaded_classes_do(KlassClosure* f);
static void lazily_loaded_classes_do(KlassClosure* f);
public:
static void reorder_dictionary();
static void copy_buckets(char** top, char* end);
static void copy_table(char** top, char* end);
static void reverse();
static void set_shared_dictionary(HashtableBucket<mtClass>* t, int length,
int number_of_entries);
static void print(bool details = true);
static void print_shared(bool details = true);
static void print_class_statistics() PRODUCT_RETURN;
static void print_method_statistics() PRODUCT_RETURN;
static int number_of_classes();
static inline int number_of_modifications() { assert_locked_or_safepoint(Compile_lock); return _number_of_modifications; }
static inline void notice_modification() { assert_locked_or_safepoint(Compile_lock); ++_number_of_modifications; }
static void verify();
#ifdef ASSERT
static bool is_internal_format(Symbol* class_name);
#endif
static void initialize(TRAPS);
static Klass* check_klass(Klass* k) {
assert(k != NULL, "preloaded klass not initialized");
return k;
}
static Klass* check_klass_Pre( Klass* k) { return check_klass(k); }
static Klass* check_klass_Pre_JSR292(Klass* k) { return EnableInvokeDynamic ? check_klass(k) : k; }
static Klass* check_klass_Opt( Klass* k) { return k; }
static Klass* check_klass_Opt_Only_JDK15(Klass* k) {
assert(JDK_Version::is_gte_jdk15x_version(), "JDK 1.5 only");
return k;
}
static Klass* check_klass_Opt_Only_JDK14NewRef(Klass* k) {
assert(JDK_Version::is_gte_jdk14x_version() && UseNewReflection, "JDK 1.4 only");
return check_klass(k);
}
static bool initialize_wk_klass(WKID id, int init_opt, TRAPS);
static void initialize_wk_klasses_until(WKID limit_id, WKID &start_id, TRAPS);
static void initialize_wk_klasses_through(WKID end_id, WKID &start_id, TRAPS) {
int limit = (int)end_id + 1;
initialize_wk_klasses_until((WKID) limit, start_id, THREAD);
}
public:
#define WK_KLASS_DECLARE(name, symbol, option) \
static Klass* name() { return check_klass_##option(_well_known_klasses[WK_KLASS_ENUM_NAME(name)]); } \
static Klass** name##_addr() { \
return &SystemDictionary::_well_known_klasses[SystemDictionary::WK_KLASS_ENUM_NAME(name)]; \
}
WK_KLASSES_DO(WK_KLASS_DECLARE);
#undef WK_KLASS_DECLARE
static Klass* well_known_klass(WKID id) {
assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob");
return _well_known_klasses[id];
}
static Klass** well_known_klass_addr(WKID id) {
assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob");
return &_well_known_klasses[id];
}
#define WK_KLASS(name) _well_known_klasses[SystemDictionary::WK_KLASS_ENUM_NAME(name)]
static Klass* box_klass(BasicType t) {
assert((uint)t < T_VOID+1, "range check");
return check_klass(_box_klasses[t]);
}
static BasicType box_klass_type(Klass* k); // inverse of box_klass
static Klass* abstract_ownable_synchronizer_klass() { return check_klass(_abstract_ownable_synchronizer_klass); }
static void load_abstract_ownable_synchronizer_klass(TRAPS);
protected:
static bool has_loadClassInternal() { return _has_loadClassInternal; }
static ClassLoaderData *class_loader_data(Handle class_loader) {
return ClassLoaderData::class_loader_data(class_loader());
}
public:
static bool has_checkPackageAccess() { return _has_checkPackageAccess; }
static bool Parameter_klass_loaded() { return WK_KLASS(reflect_Parameter_klass) != NULL; }
static bool Class_klass_loaded() { return WK_KLASS(Class_klass) != NULL; }
static bool Cloneable_klass_loaded() { return WK_KLASS(Cloneable_klass) != NULL; }
static bool Object_klass_loaded() { return WK_KLASS(Object_klass) != NULL; }
static bool ClassLoader_klass_loaded() { return WK_KLASS(ClassLoader_klass) != NULL; }
static oop java_system_loader();
static void compute_java_system_loader(TRAPS);
static ClassLoaderData* register_loader(Handle class_loader, TRAPS);
protected:
static oop check_mirror(oop m) {
assert(m != NULL, "mirror not initialized");
return m;
}
public:
static bool add_loader_constraint(Symbol* name, Handle loader1,
Handle loader2, TRAPS);
static Symbol* check_signature_loaders(Symbol* signature, Handle loader1,
Handle loader2, bool is_method, TRAPS);
static methodHandle find_method_handle_invoker(Symbol* name,
Symbol* signature,
KlassHandle accessing_klass,
Handle *appendix_result,
Handle *method_type_result,
TRAPS);
static methodHandle find_method_handle_intrinsic(vmIntrinsics::ID iid,
Symbol* signature,
TRAPS);
static Handle find_method_handle_type(Symbol* signature,
KlassHandle accessing_klass,
TRAPS);
static Handle link_method_handle_constant(KlassHandle caller,
int ref_kind, //e.g., JVM_REF_invokeVirtual
KlassHandle callee,
Symbol* name,
Symbol* signature,
TRAPS);
static methodHandle find_dynamic_call_site_invoker(KlassHandle caller,
Handle bootstrap_method,
Symbol* name,
Symbol* type,
Handle *appendix_result,
Handle *method_type_result,
TRAPS);
static const char* loader_name(oop loader) {
return ((loader) == NULL ? "<bootloader>" :
InstanceKlass::cast((loader)->klass())->name()->as_C_string() );
}
static const char* loader_name(ClassLoaderData* loader_data) {
return (loader_data->class_loader() == NULL ? "<bootloader>" :
InstanceKlass::cast((loader_data->class_loader())->klass())->name()->as_C_string() );
}
static void add_resolution_error(constantPoolHandle pool, int which, Symbol* error,
Symbol* message);
static void delete_resolution_error(ConstantPool* pool);
static Symbol* find_resolution_error(constantPoolHandle pool, int which,
Symbol** message);
protected:
enum Constants {
_loader_constraint_size = 107, // number of entries in constraint table
_resolution_error_size = 107, // number of entries in resolution error table
_invoke_method_size = 139, // number of entries in invoke method table
_nof_buckets = 1009, // number of buckets in hash table for placeholders
_old_default_sdsize = 1009, // backward compat for system dictionary size
_prime_array_size = 8, // array of primes for system dictionary size
_average_depth_goal = 3 // goal for lookup length
};
static int _sdgeneration;
static const int _primelist[_prime_array_size];
static Dictionary* _dictionary;
static PlaceholderTable* _placeholders;
static Dictionary* _shared_dictionary;
static int _number_of_modifications;
static oop _system_loader_lock_obj;
static LoaderConstraintTable* _loader_constraints;
static ResolutionErrorTable* _resolution_errors;
static SymbolPropertyTable* _invoke_method_table;
public:
friend class CounterDecay;
static Klass* try_get_next_class();
protected:
static void validate_protection_domain(instanceKlassHandle klass,
Handle class_loader,
Handle protection_domain, TRAPS);
friend class VM_PopulateDumpSharedSpace;
friend class TraversePlaceholdersClosure;
static Dictionary* dictionary() { return _dictionary; }
static Dictionary* shared_dictionary() { return _shared_dictionary; }
static PlaceholderTable* placeholders() { return _placeholders; }
static LoaderConstraintTable* constraints() { return _loader_constraints; }
static ResolutionErrorTable* resolution_errors() { return _resolution_errors; }
static SymbolPropertyTable* invoke_method_table() { return _invoke_method_table; }
static Klass* resolve_instance_class_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
static Klass* resolve_array_class_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
static instanceKlassHandle handle_parallel_super_load(Symbol* class_name, Symbol* supername, Handle class_loader, Handle protection_domain, Handle lockObject, TRAPS);
static void double_lock_wait(Handle lockObject, TRAPS);
static void define_instance_class(instanceKlassHandle k, TRAPS);
static instanceKlassHandle find_or_define_instance_class(Symbol* class_name,
Handle class_loader,
instanceKlassHandle k, TRAPS);
static instanceKlassHandle load_shared_class(instanceKlassHandle ik,
Handle class_loader,
Handle protection_domain,
TRAPS);
static instanceKlassHandle load_instance_class(Symbol* class_name, Handle class_loader, TRAPS);
static Handle compute_loader_lock_object(Handle class_loader, TRAPS);
static void check_loader_lock_contention(Handle loader_lock, TRAPS);
static bool is_parallelCapable(Handle class_loader);
static bool is_parallelDefine(Handle class_loader);
public:
static instanceKlassHandle load_shared_class(Symbol* class_name,
Handle class_loader,
TRAPS);
static bool is_ext_class_loader(Handle class_loader);
protected:
static Klass* find_shared_class(Symbol* class_name);
static void add_to_hierarchy(instanceKlassHandle k, TRAPS);
static Klass* find_class(int index, unsigned int hash,
Symbol* name, ClassLoaderData* loader_data);
static Klass* find_class(Symbol* class_name, ClassLoaderData* loader_data);
static Symbol* find_placeholder(Symbol* name, ClassLoaderData* loader_data);
static void add_klass(int index, Symbol* class_name,
ClassLoaderData* loader_data, KlassHandle obj);
static void add_placeholder(int index,
Symbol* class_name,
ClassLoaderData* loader_data);
static void remove_placeholder(int index,
Symbol* class_name,
ClassLoaderData* loader_data);
static void resolution_cleanups(Symbol* class_name,
ClassLoaderData* loader_data,
TRAPS);
static void initialize_preloaded_classes(TRAPS);
static void check_constraints(int index, unsigned int hash,
instanceKlassHandle k, Handle loader,
bool defining, TRAPS);
static void update_dictionary(int d_index, unsigned int d_hash,
int p_index, unsigned int p_hash,
instanceKlassHandle k, Handle loader,
TRAPS);
static Klass* _well_known_klasses[];
static Klass* volatile _abstract_ownable_synchronizer_klass;
static Klass* _box_klasses[T_VOID+1];
static oop _java_system_loader;
static bool _has_loadClassInternal;
static bool _has_checkPackageAccess;
};
#endif // SHARE_VM_CLASSFILE_SYSTEMDICTIONARY_HPP
C:\hotspot-69087d08d473\src\share\vm/classfile/systemDictionaryShared.hpp
#ifndef SHARE_VM_CLASSFILE_SYSTEMDICTIONARYSHARED_HPP
#define SHARE_VM_CLASSFILE_SYSTEMDICTIONARYSHARED_HPP
#include "classfile/dictionary.hpp"
#include "classfile/systemDictionary.hpp"
class SystemDictionaryShared: public SystemDictionary {
public:
static void initialize(TRAPS) {}
static instanceKlassHandle find_or_load_shared_class(Symbol* class_name,
Handle class_loader,
TRAPS) {
return instanceKlassHandle();
}
static void roots_oops_do(OopClosure* blk) {}
static void oops_do(OopClosure* f) {}
static bool is_sharing_possible(ClassLoaderData* loader_data) {
oop class_loader = loader_data->class_loader();
return (class_loader == NULL);
}
static size_t dictionary_entry_size() {
return sizeof(DictionaryEntry);
}
static void init_shared_dictionary_entry(Klass* k, DictionaryEntry* entry) {}
static void add_verification_dependency(Klass* k, Symbol* accessor_clsname,
Symbol* target_clsname) {}
static void finalize_verification_dependencies() {}
static bool check_verification_dependencies(Klass* k, Handle class_loader,
Handle protection_domain,
char** message_buffer, TRAPS) {return true;}
};
#endif // SHARE_VM_CLASSFILE_SYSTEMDICTIONARYSHARED_HPP
C:\hotspot-69087d08d473\src\share\vm/classfile/verificationType.cpp
#include "precompiled.hpp"
#include "classfile/symbolTable.hpp"
#include "classfile/systemDictionaryShared.hpp"
#include "classfile/verificationType.hpp"
#include "classfile/verifier.hpp"
VerificationType VerificationType::from_tag(u1 tag) {
switch (tag) {
case ITEM_Top: return bogus_type();
case ITEM_Integer: return integer_type();
case ITEM_Float: return float_type();
case ITEM_Double: return double_type();
case ITEM_Long: return long_type();
case ITEM_Null: return null_type();
default:
ShouldNotReachHere();
return bogus_type();
}
}
bool VerificationType::is_reference_assignable_from(
const VerificationType& from, ClassVerifier* context,
bool from_field_is_protected, TRAPS) const {
instanceKlassHandle klass = context->current_class();
if (from.is_null()) {
return true;
} else if (is_null()) {
return false;
} else if (name() == from.name()) {
return true;
} else if (is_object()) {
if (name() == vmSymbols::java_lang_Object()) {
return true;
}
Klass* obj = SystemDictionary::resolve_or_fail(
name(), Handle(THREAD, klass->class_loader()),
Handle(THREAD, klass->protection_domain()), true, CHECK_false);
KlassHandle this_class(THREAD, obj);
if (this_class->is_interface() && (!from_field_is_protected ||
from.name() != vmSymbols::java_lang_Object())) {
return true;
} else if (from.is_object()) {
Klass* from_class = SystemDictionary::resolve_or_fail(
from.name(), Handle(THREAD, klass->class_loader()),
Handle(THREAD, klass->protection_domain()), true, CHECK_false);
bool result = InstanceKlass::cast(from_class)->is_subclass_of(this_class());
if (result && DumpSharedSpaces) {
if (klass()->is_subclass_of(from_class) && klass()->is_subclass_of(this_class())) {
} else {
Symbol* accessor_clsname = from.name();
Symbol* target_clsname = this_class()->name();
SystemDictionaryShared::add_verification_dependency(klass(),
accessor_clsname, target_clsname);
}
}
return result;
}
} else if (is_array() && from.is_array()) {
VerificationType comp_this = get_component(context, CHECK_false);
VerificationType comp_from = from.get_component(context, CHECK_false);
if (!comp_this.is_bogus() && !comp_from.is_bogus()) {
return comp_this.is_assignable_from(comp_from, context,
from_field_is_protected, THREAD);
}
}
return false;
}
VerificationType VerificationType::get_component(ClassVerifier *context, TRAPS) const {
assert(is_array() && name()->utf8_length() >= 2, "Must be a valid array");
Symbol* component;
switch (name()->byte_at(1)) {
case 'Z': return VerificationType(Boolean);
case 'B': return VerificationType(Byte);
case 'C': return VerificationType(Char);
case 'S': return VerificationType(Short);
case 'I': return VerificationType(Integer);
case 'J': return VerificationType(Long);
case 'F': return VerificationType(Float);
case 'D': return VerificationType(Double);
case '[':
component = context->create_temporary_symbol(
name(), 1, name()->utf8_length(),
CHECK_(VerificationType::bogus_type()));
return VerificationType::reference_type(component);
case 'L':
component = context->create_temporary_symbol(
name(), 2, name()->utf8_length() - 1,
CHECK_(VerificationType::bogus_type()));
return VerificationType::reference_type(component);
default:
return VerificationType::bogus_type();
}
}
void VerificationType::print_on(outputStream* st) const {
switch (_u._data) {
case Bogus: st->print("top"); break;
case Category1: st->print("category1"); break;
case Category2: st->print("category2"); break;
case Category2_2nd: st->print("category2_2nd"); break;
case Boolean: st->print("boolean"); break;
case Byte: st->print("byte"); break;
case Short: st->print("short"); break;
case Char: st->print("char"); break;
case Integer: st->print("integer"); break;
case Float: st->print("float"); break;
case Long: st->print("long"); break;
case Double: st->print("double"); break;
case Long_2nd: st->print("long_2nd"); break;
case Double_2nd: st->print("double_2nd"); break;
case Null: st->print("null"); break;
case ReferenceQuery: st->print("reference type"); break;
case Category1Query: st->print("category1 type"); break;
case Category2Query: st->print("category2 type"); break;
case Category2_2ndQuery: st->print("category2_2nd type"); break;
default:
if (is_uninitialized_this()) {
st->print("uninitializedThis");
} else if (is_uninitialized()) {
st->print("uninitialized %d", bci());
} else {
name()->print_value_on(st);
}
}
}
C:\hotspot-69087d08d473\src\share\vm/classfile/verificationType.hpp
#ifndef SHARE_VM_CLASSFILE_VERIFICATIONTYPE_HPP
#define SHARE_VM_CLASSFILE_VERIFICATIONTYPE_HPP
#include "classfile/systemDictionary.hpp"
#include "memory/allocation.hpp"
#include "oops/instanceKlass.hpp"
#include "oops/oop.inline.hpp"
#include "oops/symbol.hpp"
#include "runtime/handles.hpp"
#include "runtime/signature.hpp"
enum {
ITEM_Top = 0,
ITEM_Integer = 1,
ITEM_Float = 2,
ITEM_Double = 3,
ITEM_Long = 4,
ITEM_Null = 5,
ITEM_UninitializedThis = 6,
ITEM_Object = 7,
ITEM_Uninitialized = 8,
ITEM_Bogus = (uint)-1
};
class ClassVerifier;
class VerificationType VALUE_OBJ_CLASS_SPEC {
private:
union {
Symbol* _sym;
uintptr_t _data;
} _u;
enum {
ITEM_Boolean = 9, ITEM_Byte, ITEM_Short, ITEM_Char,
ITEM_Long_2nd, ITEM_Double_2nd
};
enum {
TypeMask = 0x00000003,
Reference = 0x0, // _sym contains the name
Primitive = 0x1, // see below for primitive list
Uninitialized = 0x2, // 0x00ffff00 contains bci
TypeQuery = 0x3, // Meta-types used for category testing
ReferenceFlag = 0x00, // For reference query types
Category1Flag = 0x01, // One-word values
Category2Flag = 0x02, // First word of a two-word value
Category2_2ndFlag = 0x04, // Second word of a two-word value
Null = 0x00000000, // A reference with a 0 sym is null
Category1 = (Category1Flag << 1 * BitsPerByte) | Primitive,
Category2 = (Category2Flag << 1 * BitsPerByte) | Primitive,
Category2_2nd = (Category2_2ndFlag << 1 * BitsPerByte) | Primitive,
Bogus = (ITEM_Bogus << 2 * BitsPerByte) | Category1,
Boolean = (ITEM_Boolean << 2 * BitsPerByte) | Category1,
Byte = (ITEM_Byte << 2 * BitsPerByte) | Category1,
Short = (ITEM_Short << 2 * BitsPerByte) | Category1,
Char = (ITEM_Char << 2 * BitsPerByte) | Category1,
Integer = (ITEM_Integer << 2 * BitsPerByte) | Category1,
Float = (ITEM_Float << 2 * BitsPerByte) | Category1,
Long = (ITEM_Long << 2 * BitsPerByte) | Category2,
Double = (ITEM_Double << 2 * BitsPerByte) | Category2,
Long_2nd = (ITEM_Long_2nd << 2 * BitsPerByte) | Category2_2nd,
Double_2nd = (ITEM_Double_2nd << 2 * BitsPerByte) | Category2_2nd,
BciMask = 0xffff << 1 * BitsPerByte,
BciForThis = ((u2)-1), // A bci of -1 is an Unintialized-This
ReferenceQuery = (ReferenceFlag << 1 * BitsPerByte) | TypeQuery,
Category1Query = (Category1Flag << 1 * BitsPerByte) | TypeQuery,
Category2Query = (Category2Flag << 1 * BitsPerByte) | TypeQuery,
Category2_2ndQuery = (Category2_2ndFlag << 1 * BitsPerByte) | TypeQuery
};
VerificationType(uintptr_t raw_data) {
_u._data = raw_data;
}
public:
VerificationType() { *this = bogus_type(); }
static VerificationType bogus_type() { return VerificationType(Bogus); }
static VerificationType top_type() { return bogus_type(); } // alias
static VerificationType null_type() { return VerificationType(Null); }
static VerificationType integer_type() { return VerificationType(Integer); }
static VerificationType float_type() { return VerificationType(Float); }
static VerificationType long_type() { return VerificationType(Long); }
static VerificationType long2_type() { return VerificationType(Long_2nd); }
static VerificationType double_type() { return VerificationType(Double); }
static VerificationType boolean_type() { return VerificationType(Boolean); }
static VerificationType byte_type() { return VerificationType(Byte); }
static VerificationType char_type() { return VerificationType(Char); }
static VerificationType short_type() { return VerificationType(Short); }
static VerificationType double2_type()
{ return VerificationType(Double_2nd); }
static VerificationType reference_check()
{ return VerificationType(ReferenceQuery); }
static VerificationType category1_check()
{ return VerificationType(Category1Query); }
static VerificationType category2_check()
{ return VerificationType(Category2Query); }
static VerificationType category2_2nd_check()
{ return VerificationType(Category2_2ndQuery); }
static VerificationType reference_type(Symbol* sh) {
assert(((uintptr_t)sh & 0x3) == 0, "Symbols must be aligned");
return VerificationType((uintptr_t)sh);
}
static VerificationType uninitialized_type(u2 bci)
{ return VerificationType(bci << 1 * BitsPerByte | Uninitialized); }
static VerificationType uninitialized_this_type()
{ return uninitialized_type(BciForThis); }
static VerificationType from_tag(u1 tag);
bool is_bogus() const { return (_u._data == Bogus); }
bool is_null() const { return (_u._data == Null); }
bool is_boolean() const { return (_u._data == Boolean); }
bool is_byte() const { return (_u._data == Byte); }
bool is_char() const { return (_u._data == Char); }
bool is_short() const { return (_u._data == Short); }
bool is_integer() const { return (_u._data == Integer); }
bool is_long() const { return (_u._data == Long); }
bool is_float() const { return (_u._data == Float); }
bool is_double() const { return (_u._data == Double); }
bool is_long2() const { return (_u._data == Long_2nd); }
bool is_double2() const { return (_u._data == Double_2nd); }
bool is_reference() const { return ((_u._data & TypeMask) == Reference); }
bool is_category1() const {
assert(!is_check(), "Must not be a check type (wrong value returned)");
return ((_u._data & Category1) != Primitive);
}
bool is_category2() const { return ((_u._data & Category2) == Category2); }
bool is_category2_2nd() const {
return ((_u._data & Category2_2nd) == Category2_2nd);
}
bool is_reference_check() const { return _u._data == ReferenceQuery; }
bool is_category1_check() const { return _u._data == Category1Query; }
bool is_category2_check() const { return _u._data == Category2Query; }
bool is_category2_2nd_check() const { return _u._data == Category2_2ndQuery; }
bool is_check() const { return (_u._data & TypeQuery) == TypeQuery; }
bool is_x_array(char sig) const {
return is_null() || (is_array() && (name()->byte_at(1) == sig));
}
bool is_int_array() const { return is_x_array('I'); }
bool is_byte_array() const { return is_x_array('B'); }
bool is_bool_array() const { return is_x_array('Z'); }
bool is_char_array() const { return is_x_array('C'); }
bool is_short_array() const { return is_x_array('S'); }
bool is_long_array() const { return is_x_array('J'); }
bool is_float_array() const { return is_x_array('F'); }
bool is_double_array() const { return is_x_array('D'); }
bool is_object_array() const { return is_x_array('L'); }
bool is_array_array() const { return is_x_array('['); }
bool is_reference_array() const
{ return is_object_array() || is_array_array(); }
bool is_object() const
{ return (is_reference() && !is_null() && name()->utf8_length() >= 1 &&
name()->byte_at(0) != '['); }
bool is_array() const
{ return (is_reference() && !is_null() && name()->utf8_length() >= 2 &&
name()->byte_at(0) == '['); }
bool is_uninitialized() const
{ return ((_u._data & Uninitialized) == Uninitialized); }
bool is_uninitialized_this() const
{ return is_uninitialized() && bci() == BciForThis; }
VerificationType to_category2_2nd() const {
assert(is_category2(), "Must be a double word");
return VerificationType(is_long() ? Long_2nd : Double_2nd);
}
u2 bci() const {
assert(is_uninitialized(), "Must be uninitialized type");
return ((_u._data & BciMask) >> 1 * BitsPerByte);
}
Symbol* name() const {
assert(is_reference() && !is_null(), "Must be a non-null reference");
return _u._sym;
}
bool equals(const VerificationType& t) const {
return (_u._data == t._u._data ||
(is_reference() && t.is_reference() && !is_null() && !t.is_null() &&
name() == t.name()));
}
bool operator ==(const VerificationType& t) const {
return equals(t);
}
bool operator !=(const VerificationType& t) const {
return !equals(t);
}
bool is_assignable_from(
const VerificationType& from, ClassVerifier* context,
bool from_field_is_protected, TRAPS) const {
if (equals(from) || is_bogus()) {
return true;
} else {
switch(_u._data) {
case Category1Query:
return from.is_category1();
case Category2Query:
return from.is_category2();
case Category2_2ndQuery:
return from.is_category2_2nd();
case ReferenceQuery:
return from.is_reference() || from.is_uninitialized();
case Boolean:
case Byte:
case Char:
case Short:
return from.is_integer();
default:
if (is_reference() && from.is_reference()) {
return is_reference_assignable_from(from, context,
from_field_is_protected,
THREAD);
} else {
return false;
}
}
}
}
VerificationType get_component(ClassVerifier* context, TRAPS) const;
int dimensions() const {
assert(is_array(), "Must be an array");
int index = 0;
while (name()->byte_at(index) == '[') index++;
return index;
}
void print_on(outputStream* st) const;
private:
bool is_reference_assignable_from(
const VerificationType&, ClassVerifier*, bool from_field_is_protected,
TRAPS) const;
};
#endif // SHARE_VM_CLASSFILE_VERIFICATIONTYPE_HPP
C:\hotspot-69087d08d473\src\share\vm/classfile/verifier.cpp
#include "precompiled.hpp"
#include "classfile/classFileStream.hpp"
#include "classfile/javaClasses.hpp"
#include "classfile/stackMapTable.hpp"
#include "classfile/stackMapFrame.hpp"
#include "classfile/stackMapTableFormat.hpp"
#include "classfile/systemDictionary.hpp"
#include "classfile/verifier.hpp"
#include "classfile/vmSymbols.hpp"
#include "interpreter/bytecodes.hpp"
#include "interpreter/bytecodeStream.hpp"
#include "memory/oopFactory.hpp"
#include "memory/resourceArea.hpp"
#include "oops/instanceKlass.hpp"
#include "oops/oop.inline.hpp"
#include "oops/typeArrayOop.hpp"
#include "prims/jvm.h"
#include "runtime/fieldDescriptor.hpp"
#include "runtime/handles.inline.hpp"
#include "runtime/interfaceSupport.hpp"
#include "runtime/javaCalls.hpp"
#include "runtime/orderAccess.inline.hpp"
#include "runtime/os.hpp"
#ifdef TARGET_ARCH_x86
# include "bytes_x86.hpp"
#endif
#ifdef TARGET_ARCH_aarch64
# include "bytes_aarch64.hpp"
#endif
#ifdef TARGET_ARCH_sparc
# include "bytes_sparc.hpp"
#endif
#ifdef TARGET_ARCH_zero
# include "bytes_zero.hpp"
#endif
#ifdef TARGET_ARCH_arm
# include "bytes_arm.hpp"
#endif
#ifdef TARGET_ARCH_ppc
# include "bytes_ppc.hpp"
#endif
#define NOFAILOVER_MAJOR_VERSION 51
#define NONZERO_PADDING_BYTES_IN_SWITCH_MAJOR_VERSION 51
#define STATIC_METHOD_IN_INTERFACE_MAJOR_VERSION 52
extern "C" {
typedef jboolean (*verify_byte_codes_fn_t)(JNIEnv *, jclass, char *, jint);
typedef jboolean (*verify_byte_codes_fn_new_t)(JNIEnv *, jclass, char *, jint, jint);
}
static void* volatile _verify_byte_codes_fn = NULL;
static volatile jint _is_new_verify_byte_codes_fn = (jint) true;
static void* verify_byte_codes_fn() {
if (_verify_byte_codes_fn == NULL) {
void *lib_handle = os::native_java_library();
void *func = os::dll_lookup(lib_handle, "VerifyClassCodesForMajorVersion");
OrderAccess::release_store_ptr(&_verify_byte_codes_fn, func);
if (func == NULL) {
OrderAccess::release_store(&_is_new_verify_byte_codes_fn, false);
func = os::dll_lookup(lib_handle, "VerifyClassCodes");
OrderAccess::release_store_ptr(&_verify_byte_codes_fn, func);
}
}
return (void*)_verify_byte_codes_fn;
}
bool Verifier::should_verify_for(oop class_loader, bool should_verify_class) {
return (class_loader == NULL || !should_verify_class) ?
BytecodeVerificationLocal : BytecodeVerificationRemote;
}
bool Verifier::relax_access_for(oop loader) {
bool trusted = java_lang_ClassLoader::is_trusted_loader(loader);
bool need_verify =
(BytecodeVerificationLocal && BytecodeVerificationRemote) ||
(!BytecodeVerificationLocal && BytecodeVerificationRemote && !trusted);
return !need_verify;
}
bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, TRAPS) {
HandleMark hm;
ResourceMark rm(THREAD);
Symbol* exception_name = NULL;
const size_t message_buffer_len = klass->name()->utf8_length() + 1024;
char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len);
char* exception_message = message_buffer;
const char* klassName = klass->external_name();
bool can_failover = FailOverToOldVerifier &&
klass->major_version() < NOFAILOVER_MAJOR_VERSION;
if (is_eligible_for_verification(klass, should_verify_class)) {
if (TraceClassInitialization) {
tty->print_cr("Start class verification for: %s", klassName);
}
if (klass->major_version() >= STACKMAP_ATTRIBUTE_MAJOR_VERSION) {
ClassVerifier split_verifier(klass, THREAD);
split_verifier.verify_class(THREAD);
exception_name = split_verifier.result();
if (can_failover && !HAS_PENDING_EXCEPTION &&
(exception_name == vmSymbols::java_lang_VerifyError() ||
exception_name == vmSymbols::java_lang_ClassFormatError())) {
if (TraceClassInitialization || VerboseVerification) {
tty->print_cr(
"Fail over class verification to old verifier for: %s", klassName);
}
exception_name = inference_verify(
klass, message_buffer, message_buffer_len, THREAD);
}
if (exception_name != NULL) {
exception_message = split_verifier.exception_message();
}
} else {
exception_name = inference_verify(
klass, message_buffer, message_buffer_len, THREAD);
}
if (TraceClassInitialization || VerboseVerification) {
if (HAS_PENDING_EXCEPTION) {
tty->print("Verification for %s has", klassName);
tty->print_cr(" exception pending %s ",
InstanceKlass::cast(PENDING_EXCEPTION->klass())->external_name());
} else if (exception_name != NULL) {
tty->print_cr("Verification for %s failed", klassName);
}
tty->print_cr("End class verification for: %s", klassName);
}
}
if (HAS_PENDING_EXCEPTION) {
return false; // use the existing exception
} else if (exception_name == NULL) {
return true; // verifcation succeeded
} else { // VerifyError or ClassFormatError to be created and thrown
ResourceMark rm(THREAD);
instanceKlassHandle kls =
SystemDictionary::resolve_or_fail(exception_name, true, CHECK_false);
while (!kls.is_null()) {
if (kls == klass) {
THROW_OOP_(Universe::virtual_machine_error_instance(), false);
}
kls = kls->super();
}
message_buffer[message_buffer_len - 1] = '\0'; // just to be sure
THROW_MSG_(exception_name, exception_message, false);
}
}
bool Verifier::is_eligible_for_verification(instanceKlassHandle klass, bool should_verify_class) {
Symbol* name = klass->name();
Klass* refl_magic_klass = SystemDictionary::reflect_MagicAccessorImpl_klass();
bool is_reflect = refl_magic_klass != NULL && klass->is_subtype_of(refl_magic_klass);
return (should_verify_for(klass->class_loader(), should_verify_class) &&
name != vmSymbols::java_lang_Object() &&
name != vmSymbols::java_lang_Class() &&
name != vmSymbols::java_lang_String() &&
name != vmSymbols::java_lang_Throwable() &&
!klass()->is_shared() &&
(!is_reflect || VerifyReflectionBytecodes));
}
Symbol* Verifier::inference_verify(
instanceKlassHandle klass, char* message, size_t message_len, TRAPS) {
JavaThread* thread = (JavaThread*)THREAD;
JNIEnv *env = thread->jni_environment();
void* verify_func = verify_byte_codes_fn();
if (verify_func == NULL) {
jio_snprintf(message, message_len, "Could not link verifier");
return vmSymbols::java_lang_VerifyError();
}
ResourceMark rm(THREAD);
if (VerboseVerification) {
tty->print_cr("Verifying class %s with old format", klass->external_name());
}
jclass cls = (jclass) JNIHandles::make_local(env, klass->java_mirror());
jint result;
{
HandleMark hm(thread);
ThreadToNativeFromVM ttn(thread);
if (_is_new_verify_byte_codes_fn) {
verify_byte_codes_fn_new_t func =
CAST_TO_FN_PTR(verify_byte_codes_fn_new_t, verify_func);
result = (*func)(env, cls, message, (int)message_len,
klass->major_version());
} else {
verify_byte_codes_fn_t func =
CAST_TO_FN_PTR(verify_byte_codes_fn_t, verify_func);
result = (*func)(env, cls, message, (int)message_len);
}
}
JNIHandles::destroy_local(cls);
if (result == 0) {
return vmSymbols::java_lang_VerifyError();
} else if (result == 1) {
return NULL; // verified.
} else if (result == 2) {
THROW_MSG_(vmSymbols::java_lang_OutOfMemoryError(), message, NULL);
} else if (result == 3) {
return vmSymbols::java_lang_ClassFormatError();
} else {
ShouldNotReachHere();
return NULL;
}
}
TypeOrigin TypeOrigin::null() {
return TypeOrigin();
}
TypeOrigin TypeOrigin::local(u2 index, StackMapFrame* frame) {
assert(frame != NULL, "Must have a frame");
return TypeOrigin(CF_LOCALS, index, StackMapFrame::copy(frame),
frame->local_at(index));
}
TypeOrigin TypeOrigin::stack(u2 index, StackMapFrame* frame) {
assert(frame != NULL, "Must have a frame");
return TypeOrigin(CF_STACK, index, StackMapFrame::copy(frame),
frame->stack_at(index));
}
TypeOrigin TypeOrigin::sm_local(u2 index, StackMapFrame* frame) {
assert(frame != NULL, "Must have a frame");
return TypeOrigin(SM_LOCALS, index, StackMapFrame::copy(frame),
frame->local_at(index));
}
TypeOrigin TypeOrigin::sm_stack(u2 index, StackMapFrame* frame) {
assert(frame != NULL, "Must have a frame");
return TypeOrigin(SM_STACK, index, StackMapFrame::copy(frame),
frame->stack_at(index));
}
TypeOrigin TypeOrigin::bad_index(u2 index) {
return TypeOrigin(BAD_INDEX, index, NULL, VerificationType::bogus_type());
}
TypeOrigin TypeOrigin::cp(u2 index, VerificationType vt) {
return TypeOrigin(CONST_POOL, index, NULL, vt);
}
TypeOrigin TypeOrigin::signature(VerificationType vt) {
return TypeOrigin(SIG, 0, NULL, vt);
}
TypeOrigin TypeOrigin::implicit(VerificationType t) {
return TypeOrigin(IMPLICIT, 0, NULL, t);
}
TypeOrigin TypeOrigin::frame(StackMapFrame* frame) {
return TypeOrigin(FRAME_ONLY, 0, StackMapFrame::copy(frame),
VerificationType::bogus_type());
}
void TypeOrigin::reset_frame() {
if (_frame != NULL) {
_frame->restore();
}
}
void TypeOrigin::details(outputStream* ss) const {
_type.print_on(ss);
switch (_origin) {
case CF_LOCALS:
ss->print(" (current frame, locals[%d])", _index);
break;
case CF_STACK:
ss->print(" (current frame, stack[%d])", _index);
break;
case SM_LOCALS:
ss->print(" (stack map, locals[%d])", _index);
break;
case SM_STACK:
ss->print(" (stack map, stack[%d])", _index);
break;
case CONST_POOL:
ss->print(" (constant pool %d)", _index);
break;
case SIG:
ss->print(" (from method signature)");
break;
case IMPLICIT:
case FRAME_ONLY:
case NONE:
default:
;
}
}
#ifdef ASSERT
void TypeOrigin::print_on(outputStream* str) const {
str->print("{%d,%d,%p:", _origin, _index, _frame);
if (_frame != NULL) {
_frame->print_on(str);
} else {
str->print("null");
}
str->print(",");
_type.print_on(str);
str->print("}");
}
#endif
void ErrorContext::details(outputStream* ss, const Method* method) const {
if (is_valid()) {
ss->cr();
ss->print_cr("Exception Details:");
location_details(ss, method);
reason_details(ss);
frame_details(ss);
bytecode_details(ss, method);
handler_details(ss, method);
stackmap_details(ss, method);
}
}
void ErrorContext::reason_details(outputStream* ss) const {
streamIndentor si(ss);
ss->indent().print_cr("Reason:");
streamIndentor si2(ss);
ss->indent().print("%s", "");
switch (_fault) {
case INVALID_BYTECODE:
ss->print("Error exists in the bytecode");
break;
case WRONG_TYPE:
if (_expected.is_valid()) {
ss->print("Type ");
_type.details(ss);
ss->print(" is not assignable to ");
_expected.details(ss);
} else {
ss->print("Invalid type: ");
_type.details(ss);
}
break;
case FLAGS_MISMATCH:
if (_expected.is_valid()) {
ss->print("Current frame's flags are not assignable "
"to stack map frame's.");
} else {
ss->print("Current frame's flags are invalid in this context.");
}
break;
case BAD_CP_INDEX:
ss->print("Constant pool index %d is invalid", _type.index());
break;
case BAD_LOCAL_INDEX:
ss->print("Local index %d is invalid", _type.index());
break;
case LOCALS_SIZE_MISMATCH:
ss->print("Current frame's local size doesn't match stackmap.");
break;
case STACK_SIZE_MISMATCH:
ss->print("Current frame's stack size doesn't match stackmap.");
break;
case STACK_OVERFLOW:
ss->print("Exceeded max stack size.");
break;
case STACK_UNDERFLOW:
ss->print("Attempt to pop empty stack.");
break;
case MISSING_STACKMAP:
ss->print("Expected stackmap frame at this location.");
break;
case BAD_STACKMAP:
ss->print("Invalid stackmap specification.");
break;
case UNKNOWN:
default:
ShouldNotReachHere();
ss->print_cr("Unknown");
}
ss->cr();
}
void ErrorContext::location_details(outputStream* ss, const Method* method) const {
if (_bci != -1 && method != NULL) {
streamIndentor si(ss);
const char* bytecode_name = "<invalid>";
if (method->validate_bci_from_bcx(_bci) != -1) {
Bytecodes::Code code = Bytecodes::code_or_bp_at(method->bcp_from(_bci));
if (Bytecodes::is_defined(code)) {
bytecode_name = Bytecodes::name(code);
} else {
bytecode_name = "<illegal>";
}
}
InstanceKlass* ik = method->method_holder();
ss->indent().print_cr("Location:");
streamIndentor si2(ss);
ss->indent().print_cr("%s.%s%s @%d: %s",
ik->name()->as_C_string(), method->name()->as_C_string(),
method->signature()->as_C_string(), _bci, bytecode_name);
}
}
void ErrorContext::frame_details(outputStream* ss) const {
streamIndentor si(ss);
if (_type.is_valid() && _type.frame() != NULL) {
ss->indent().print_cr("Current Frame:");
streamIndentor si2(ss);
_type.frame()->print_on(ss);
}
if (_expected.is_valid() && _expected.frame() != NULL) {
ss->indent().print_cr("Stackmap Frame:");
streamIndentor si2(ss);
_expected.frame()->print_on(ss);
}
}
void ErrorContext::bytecode_details(outputStream* ss, const Method* method) const {
if (method != NULL) {
streamIndentor si(ss);
ss->indent().print_cr("Bytecode:");
streamIndentor si2(ss);
ss->print_data(method->code_base(), method->code_size(), false);
}
}
void ErrorContext::handler_details(outputStream* ss, const Method* method) const {
if (method != NULL) {
streamIndentor si(ss);
ExceptionTable table(method);
if (table.length() > 0) {
ss->indent().print_cr("Exception Handler Table:");
streamIndentor si2(ss);
for (int i = 0; i < table.length(); ++i) {
ss->indent().print_cr("bci [%d, %d] => handler: %d", table.start_pc(i),
table.end_pc(i), table.handler_pc(i));
}
}
}
}
void ErrorContext::stackmap_details(outputStream* ss, const Method* method) const {
if (method != NULL && method->has_stackmap_table()) {
streamIndentor si(ss);
ss->indent().print_cr("Stackmap Table:");
Array<u1>* data = method->stackmap_data();
stack_map_table* sm_table =
stack_map_table::at((address)data->adr_at(0));
stack_map_frame* sm_frame = sm_table->entries();
streamIndentor si2(ss);
int current_offset = -1;
address end_of_sm_table = (address)sm_table + method->stackmap_data()->length();
for (u2 i = 0; i < sm_table->number_of_entries(); ++i) {
ss->indent();
if (!sm_frame->verify((address)sm_frame, end_of_sm_table)) {
sm_frame->print_truncated(ss, current_offset);
return;
}
sm_frame->print_on(ss, current_offset);
ss->cr();
current_offset += sm_frame->offset_delta();
sm_frame = sm_frame->next();
}
}
}
ClassVerifier::ClassVerifier(
instanceKlassHandle klass, TRAPS)
: _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass) {
_this_type = VerificationType::reference_type(klass->name());
_symbols = new GrowableArray<Symbol*>(100, 0, NULL);
}
ClassVerifier::~ClassVerifier() {
for (int i = 0; i < _symbols->length(); i++) {
Symbol* s = _symbols->at(i);
s->decrement_refcount();
}
}
VerificationType ClassVerifier::object_type() const {
return VerificationType::reference_type(vmSymbols::java_lang_Object());
}
TypeOrigin ClassVerifier::ref_ctx(const char* sig, TRAPS) {
VerificationType vt = VerificationType::reference_type(
create_temporary_symbol(sig, (int)strlen(sig), THREAD));
return TypeOrigin::implicit(vt);
}
void ClassVerifier::verify_class(TRAPS) {
if (VerboseVerification) {
tty->print_cr("Verifying class %s with new format",
_klass->external_name());
}
Array<Method*>* methods = _klass->methods();
int num_methods = methods->length();
for (int index = 0; index < num_methods; index++) {
if (was_recursively_verified()) return;
Method* m = methods->at(index);
if (m->is_native() || m->is_abstract() || m->is_overpass()) {
continue;
}
verify_method(methodHandle(THREAD, m), CHECK_VERIFY(this));
}
if (VerboseVerification || TraceClassInitialization) {
if (was_recursively_verified())
tty->print_cr("Recursive verification detected for: %s",
_klass->external_name());
}
}
void ClassVerifier::verify_method(methodHandle m, TRAPS) {
HandleMark hm(THREAD);
_method = m; // initialize _method
if (VerboseVerification) {
tty->print_cr("Verifying method %s", m->name_and_sig_as_C_string());
}
#define bad_type_msg "Bad type on operand stack in %s"
int32_t max_stack = m->verifier_max_stack();
int32_t max_locals = m->max_locals();
constantPoolHandle cp(THREAD, m->constants());
if (!SignatureVerifier::is_valid_method_signature(m->signature())) {
class_format_error("Invalid method signature");
return;
}
StackMapFrame current_frame(max_locals, max_stack, this);
VerificationType return_type = current_frame.set_locals_from_arg(
m, current_type(), CHECK_VERIFY(this));
int32_t stackmap_index = 0; // index to the stackmap array
u4 code_length = m->code_size();
char* code_data = generate_code_data(m, code_length, CHECK_VERIFY(this));
int ex_min = code_length;
int ex_max = -1;
verify_exception_handler_table(
code_length, code_data, ex_min, ex_max, CHECK_VERIFY(this));
if (m->has_localvariable_table()) {
verify_local_variable_table(code_length, code_data, CHECK_VERIFY(this));
}
Array<u1>* stackmap_data = m->stackmap_data();
StackMapStream stream(stackmap_data);
StackMapReader reader(this, &stream, code_data, code_length, THREAD);
StackMapTable stackmap_table(&reader, ¤t_frame, max_locals, max_stack,
code_data, code_length, CHECK_VERIFY(this));
if (VerboseVerification) {
stackmap_table.print_on(tty);
}
RawBytecodeStream bcs(m);
bool no_control_flow = false; // Set to true when there is no direct control
Bytecodes::Code opcode;
while (!bcs.is_last_bytecode()) {
if (was_recursively_verified()) return;
opcode = bcs.raw_next();
u2 bci = bcs.bci();
current_frame.set_offset(bci);
current_frame.set_mark();
stackmap_index = verify_stackmap_table(
stackmap_index, bci, ¤t_frame, &stackmap_table,
no_control_flow, CHECK_VERIFY(this));
bool this_uninit = false; // Set to true when invokespecial <init> initialized 'this'
bool verified_exc_handlers = false;
{
u2 index;
int target;
VerificationType type, type2;
VerificationType atype;
#ifndef PRODUCT
if (VerboseVerification) {
current_frame.print_on(tty);
tty->print_cr("offset = %d, opcode = %s", bci, Bytecodes::name(opcode));
}
#endif
if (bcs.is_wide()) {
if (opcode != Bytecodes::_iinc && opcode != Bytecodes::_iload &&
opcode != Bytecodes::_aload && opcode != Bytecodes::_lload &&
opcode != Bytecodes::_istore && opcode != Bytecodes::_astore &&
opcode != Bytecodes::_lstore && opcode != Bytecodes::_fload &&
opcode != Bytecodes::_dload && opcode != Bytecodes::_fstore &&
opcode != Bytecodes::_dstore) {
verify_error(ErrorContext::bad_code(bci), "Bad wide instruction");
return;
}
}
if (Bytecodes::is_store_into_local(opcode) && bci >= ex_min && bci < ex_max) {
verify_exception_handler_targets(
bci, this_uninit, ¤t_frame, &stackmap_table, CHECK_VERIFY(this));
verified_exc_handlers = true;
}
switch (opcode) {
case Bytecodes::_nop :
no_control_flow = false; break;
case Bytecodes::_aconst_null :
current_frame.push_stack(
VerificationType::null_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_iconst_m1 :
case Bytecodes::_iconst_0 :
case Bytecodes::_iconst_1 :
case Bytecodes::_iconst_2 :
case Bytecodes::_iconst_3 :
case Bytecodes::_iconst_4 :
case Bytecodes::_iconst_5 :
current_frame.push_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_lconst_0 :
case Bytecodes::_lconst_1 :
current_frame.push_stack_2(
VerificationType::long_type(),
VerificationType::long2_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_fconst_0 :
case Bytecodes::_fconst_1 :
case Bytecodes::_fconst_2 :
current_frame.push_stack(
VerificationType::float_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_dconst_0 :
case Bytecodes::_dconst_1 :
current_frame.push_stack_2(
VerificationType::double_type(),
VerificationType::double2_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_sipush :
case Bytecodes::_bipush :
current_frame.push_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_ldc :
verify_ldc(
opcode, bcs.get_index_u1(), ¤t_frame,
cp, bci, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_ldc_w :
case Bytecodes::_ldc2_w :
verify_ldc(
opcode, bcs.get_index_u2(), ¤t_frame,
cp, bci, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_iload :
verify_iload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_iload_0 :
case Bytecodes::_iload_1 :
case Bytecodes::_iload_2 :
case Bytecodes::_iload_3 :
index = opcode - Bytecodes::_iload_0;
verify_iload(index, ¤t_frame, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_lload :
verify_lload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_lload_0 :
case Bytecodes::_lload_1 :
case Bytecodes::_lload_2 :
case Bytecodes::_lload_3 :
index = opcode - Bytecodes::_lload_0;
verify_lload(index, ¤t_frame, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_fload :
verify_fload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_fload_0 :
case Bytecodes::_fload_1 :
case Bytecodes::_fload_2 :
case Bytecodes::_fload_3 :
index = opcode - Bytecodes::_fload_0;
verify_fload(index, ¤t_frame, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_dload :
verify_dload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_dload_0 :
case Bytecodes::_dload_1 :
case Bytecodes::_dload_2 :
case Bytecodes::_dload_3 :
index = opcode - Bytecodes::_dload_0;
verify_dload(index, ¤t_frame, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_aload :
verify_aload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_aload_0 :
case Bytecodes::_aload_1 :
case Bytecodes::_aload_2 :
case Bytecodes::_aload_3 :
index = opcode - Bytecodes::_aload_0;
verify_aload(index, ¤t_frame, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_iaload :
type = current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
atype = current_frame.pop_stack(
VerificationType::reference_check(), CHECK_VERIFY(this));
if (!atype.is_int_array()) {
verify_error(ErrorContext::bad_type(bci,
current_frame.stack_top_ctx(), ref_ctx("[I", THREAD)),
bad_type_msg, "iaload");
return;
}
current_frame.push_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_baload :
type = current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
atype = current_frame.pop_stack(
VerificationType::reference_check(), CHECK_VERIFY(this));
if (!atype.is_bool_array() && !atype.is_byte_array()) {
verify_error(
ErrorContext::bad_type(bci, current_frame.stack_top_ctx()),
bad_type_msg, "baload");
return;
}
current_frame.push_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_caload :
type = current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
atype = current_frame.pop_stack(
VerificationType::reference_check(), CHECK_VERIFY(this));
if (!atype.is_char_array()) {
verify_error(ErrorContext::bad_type(bci,
current_frame.stack_top_ctx(), ref_ctx("[C", THREAD)),
bad_type_msg, "caload");
return;
}
current_frame.push_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_saload :
type = current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
atype = current_frame.pop_stack(
VerificationType::reference_check(), CHECK_VERIFY(this));
if (!atype.is_short_array()) {
verify_error(ErrorContext::bad_type(bci,
current_frame.stack_top_ctx(), ref_ctx("[S", THREAD)),
bad_type_msg, "saload");
return;
}
current_frame.push_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_laload :
type = current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
atype = current_frame.pop_stack(
VerificationType::reference_check(), CHECK_VERIFY(this));
if (!atype.is_long_array()) {
verify_error(ErrorContext::bad_type(bci,
current_frame.stack_top_ctx(), ref_ctx("[J", THREAD)),
bad_type_msg, "laload");
return;
}
current_frame.push_stack_2(
VerificationType::long_type(),
VerificationType::long2_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_faload :
type = current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
atype = current_frame.pop_stack(
VerificationType::reference_check(), CHECK_VERIFY(this));
if (!atype.is_float_array()) {
verify_error(ErrorContext::bad_type(bci,
current_frame.stack_top_ctx(), ref_ctx("[F", THREAD)),
bad_type_msg, "faload");
return;
}
current_frame.push_stack(
VerificationType::float_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_daload :
type = current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
atype = current_frame.pop_stack(
VerificationType::reference_check(), CHECK_VERIFY(this));
if (!atype.is_double_array()) {
verify_error(ErrorContext::bad_type(bci,
current_frame.stack_top_ctx(), ref_ctx("[D", THREAD)),
bad_type_msg, "daload");
return;
}
current_frame.push_stack_2(
VerificationType::double_type(),
VerificationType::double2_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_aaload : {
type = current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
atype = current_frame.pop_stack(
VerificationType::reference_check(), CHECK_VERIFY(this));
if (!atype.is_reference_array()) {
verify_error(ErrorContext::bad_type(bci,
current_frame.stack_top_ctx(),
TypeOrigin::implicit(VerificationType::reference_check())),
bad_type_msg, "aaload");
return;
}
if (atype.is_null()) {
current_frame.push_stack(
VerificationType::null_type(), CHECK_VERIFY(this));
} else {
VerificationType component =
atype.get_component(this, CHECK_VERIFY(this));
current_frame.push_stack(component, CHECK_VERIFY(this));
}
no_control_flow = false; break;
}
case Bytecodes::_istore :
verify_istore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_istore_0 :
case Bytecodes::_istore_1 :
case Bytecodes::_istore_2 :
case Bytecodes::_istore_3 :
index = opcode - Bytecodes::_istore_0;
verify_istore(index, ¤t_frame, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_lstore :
verify_lstore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_lstore_0 :
case Bytecodes::_lstore_1 :
case Bytecodes::_lstore_2 :
case Bytecodes::_lstore_3 :
index = opcode - Bytecodes::_lstore_0;
verify_lstore(index, ¤t_frame, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_fstore :
verify_fstore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_fstore_0 :
case Bytecodes::_fstore_1 :
case Bytecodes::_fstore_2 :
case Bytecodes::_fstore_3 :
index = opcode - Bytecodes::_fstore_0;
verify_fstore(index, ¤t_frame, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_dstore :
verify_dstore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_dstore_0 :
case Bytecodes::_dstore_1 :
case Bytecodes::_dstore_2 :
case Bytecodes::_dstore_3 :
index = opcode - Bytecodes::_dstore_0;
verify_dstore(index, ¤t_frame, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_astore :
verify_astore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_astore_0 :
case Bytecodes::_astore_1 :
case Bytecodes::_astore_2 :
case Bytecodes::_astore_3 :
index = opcode - Bytecodes::_astore_0;
verify_astore(index, ¤t_frame, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_iastore :
type = current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
type2 = current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
atype = current_frame.pop_stack(
VerificationType::reference_check(), CHECK_VERIFY(this));
if (!atype.is_int_array()) {
verify_error(ErrorContext::bad_type(bci,
current_frame.stack_top_ctx(), ref_ctx("[I", THREAD)),
bad_type_msg, "iastore");
return;
}
no_control_flow = false; break;
case Bytecodes::_bastore :
type = current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
type2 = current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
atype = current_frame.pop_stack(
VerificationType::reference_check(), CHECK_VERIFY(this));
if (!atype.is_bool_array() && !atype.is_byte_array()) {
verify_error(
ErrorContext::bad_type(bci, current_frame.stack_top_ctx()),
bad_type_msg, "bastore");
return;
}
no_control_flow = false; break;
case Bytecodes::_castore :
current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
atype = current_frame.pop_stack(
VerificationType::reference_check(), CHECK_VERIFY(this));
if (!atype.is_char_array()) {
verify_error(ErrorContext::bad_type(bci,
current_frame.stack_top_ctx(), ref_ctx("[C", THREAD)),
bad_type_msg, "castore");
return;
}
no_control_flow = false; break;
case Bytecodes::_sastore :
current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
atype = current_frame.pop_stack(
VerificationType::reference_check(), CHECK_VERIFY(this));
if (!atype.is_short_array()) {
verify_error(ErrorContext::bad_type(bci,
current_frame.stack_top_ctx(), ref_ctx("[S", THREAD)),
bad_type_msg, "sastore");
return;
}
no_control_flow = false; break;
case Bytecodes::_lastore :
current_frame.pop_stack_2(
VerificationType::long2_type(),
VerificationType::long_type(), CHECK_VERIFY(this));
current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
atype = current_frame.pop_stack(
VerificationType::reference_check(), CHECK_VERIFY(this));
if (!atype.is_long_array()) {
verify_error(ErrorContext::bad_type(bci,
current_frame.stack_top_ctx(), ref_ctx("[J", THREAD)),
bad_type_msg, "lastore");
return;
}
no_control_flow = false; break;
case Bytecodes::_fastore :
current_frame.pop_stack(
VerificationType::float_type(), CHECK_VERIFY(this));
current_frame.pop_stack
(VerificationType::integer_type(), CHECK_VERIFY(this));
atype = current_frame.pop_stack(
VerificationType::reference_check(), CHECK_VERIFY(this));
if (!atype.is_float_array()) {
verify_error(ErrorContext::bad_type(bci,
current_frame.stack_top_ctx(), ref_ctx("[F", THREAD)),
bad_type_msg, "fastore");
return;
}
no_control_flow = false; break;
case Bytecodes::_dastore :
current_frame.pop_stack_2(
VerificationType::double2_type(),
VerificationType::double_type(), CHECK_VERIFY(this));
current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
atype = current_frame.pop_stack(
VerificationType::reference_check(), CHECK_VERIFY(this));
if (!atype.is_double_array()) {
verify_error(ErrorContext::bad_type(bci,
current_frame.stack_top_ctx(), ref_ctx("[D", THREAD)),
bad_type_msg, "dastore");
return;
}
no_control_flow = false; break;
case Bytecodes::_aastore :
type = current_frame.pop_stack(object_type(), CHECK_VERIFY(this));
type2 = current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
atype = current_frame.pop_stack(
VerificationType::reference_check(), CHECK_VERIFY(this));
if (!atype.is_reference_array()) {
verify_error(ErrorContext::bad_type(bci,
current_frame.stack_top_ctx(),
TypeOrigin::implicit(VerificationType::reference_check())),
bad_type_msg, "aastore");
return;
}
no_control_flow = false; break;
case Bytecodes::_pop :
current_frame.pop_stack(
VerificationType::category1_check(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_pop2 :
type = current_frame.pop_stack(CHECK_VERIFY(this));
if (type.is_category1()) {
current_frame.pop_stack(
VerificationType::category1_check(), CHECK_VERIFY(this));
} else if (type.is_category2_2nd()) {
current_frame.pop_stack(
VerificationType::category2_check(), CHECK_VERIFY(this));
} else {
verify_error(
ErrorContext::bad_type(bci, current_frame.stack_top_ctx()),
bad_type_msg, "pop2");
return;
}
no_control_flow = false; break;
case Bytecodes::_dup :
type = current_frame.pop_stack(
VerificationType::category1_check(), CHECK_VERIFY(this));
current_frame.push_stack(type, CHECK_VERIFY(this));
current_frame.push_stack(type, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_dup_x1 :
type = current_frame.pop_stack(
VerificationType::category1_check(), CHECK_VERIFY(this));
type2 = current_frame.pop_stack(
VerificationType::category1_check(), CHECK_VERIFY(this));
current_frame.push_stack(type, CHECK_VERIFY(this));
current_frame.push_stack(type2, CHECK_VERIFY(this));
current_frame.push_stack(type, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_dup_x2 :
{
VerificationType type3;
type = current_frame.pop_stack(
VerificationType::category1_check(), CHECK_VERIFY(this));
type2 = current_frame.pop_stack(CHECK_VERIFY(this));
if (type2.is_category1()) {
type3 = current_frame.pop_stack(
VerificationType::category1_check(), CHECK_VERIFY(this));
} else if (type2.is_category2_2nd()) {
type3 = current_frame.pop_stack(
VerificationType::category2_check(), CHECK_VERIFY(this));
} else {
verify_error(ErrorContext::bad_type(
bci, current_frame.stack_top_ctx()), bad_type_msg, "dup_x2");
return;
}
current_frame.push_stack(type, CHECK_VERIFY(this));
current_frame.push_stack(type3, CHECK_VERIFY(this));
current_frame.push_stack(type2, CHECK_VERIFY(this));
current_frame.push_stack(type, CHECK_VERIFY(this));
no_control_flow = false; break;
}
case Bytecodes::_dup2 :
type = current_frame.pop_stack(CHECK_VERIFY(this));
if (type.is_category1()) {
type2 = current_frame.pop_stack(
VerificationType::category1_check(), CHECK_VERIFY(this));
} else if (type.is_category2_2nd()) {
type2 = current_frame.pop_stack(
VerificationType::category2_check(), CHECK_VERIFY(this));
} else {
verify_error(
ErrorContext::bad_type(bci, current_frame.stack_top_ctx()),
bad_type_msg, "dup2");
return;
}
current_frame.push_stack(type2, CHECK_VERIFY(this));
current_frame.push_stack(type, CHECK_VERIFY(this));
current_frame.push_stack(type2, CHECK_VERIFY(this));
current_frame.push_stack(type, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_dup2_x1 :
{
VerificationType type3;
type = current_frame.pop_stack(CHECK_VERIFY(this));
if (type.is_category1()) {
type2 = current_frame.pop_stack(
VerificationType::category1_check(), CHECK_VERIFY(this));
} else if (type.is_category2_2nd()) {
type2 = current_frame.pop_stack(
VerificationType::category2_check(), CHECK_VERIFY(this));
} else {
verify_error(
ErrorContext::bad_type(bci, current_frame.stack_top_ctx()),
bad_type_msg, "dup2_x1");
return;
}
type3 = current_frame.pop_stack(
VerificationType::category1_check(), CHECK_VERIFY(this));
current_frame.push_stack(type2, CHECK_VERIFY(this));
current_frame.push_stack(type, CHECK_VERIFY(this));
current_frame.push_stack(type3, CHECK_VERIFY(this));
current_frame.push_stack(type2, CHECK_VERIFY(this));
current_frame.push_stack(type, CHECK_VERIFY(this));
no_control_flow = false; break;
}
case Bytecodes::_dup2_x2 :
{
VerificationType type3, type4;
type = current_frame.pop_stack(CHECK_VERIFY(this));
if (type.is_category1()) {
type2 = current_frame.pop_stack(
VerificationType::category1_check(), CHECK_VERIFY(this));
} else if (type.is_category2_2nd()) {
type2 = current_frame.pop_stack(
VerificationType::category2_check(), CHECK_VERIFY(this));
} else {
verify_error(
ErrorContext::bad_type(bci, current_frame.stack_top_ctx()),
bad_type_msg, "dup2_x2");
return;
}
type3 = current_frame.pop_stack(CHECK_VERIFY(this));
if (type3.is_category1()) {
type4 = current_frame.pop_stack(
VerificationType::category1_check(), CHECK_VERIFY(this));
} else if (type3.is_category2_2nd()) {
type4 = current_frame.pop_stack(
VerificationType::category2_check(), CHECK_VERIFY(this));
} else {
verify_error(
ErrorContext::bad_type(bci, current_frame.stack_top_ctx()),
bad_type_msg, "dup2_x2");
return;
}
current_frame.push_stack(type2, CHECK_VERIFY(this));
current_frame.push_stack(type, CHECK_VERIFY(this));
current_frame.push_stack(type4, CHECK_VERIFY(this));
current_frame.push_stack(type3, CHECK_VERIFY(this));
current_frame.push_stack(type2, CHECK_VERIFY(this));
current_frame.push_stack(type, CHECK_VERIFY(this));
no_control_flow = false; break;
}
case Bytecodes::_swap :
type = current_frame.pop_stack(
VerificationType::category1_check(), CHECK_VERIFY(this));
type2 = current_frame.pop_stack(
VerificationType::category1_check(), CHECK_VERIFY(this));
current_frame.push_stack(type, CHECK_VERIFY(this));
current_frame.push_stack(type2, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_iadd :
case Bytecodes::_isub :
case Bytecodes::_imul :
case Bytecodes::_idiv :
case Bytecodes::_irem :
case Bytecodes::_ishl :
case Bytecodes::_ishr :
case Bytecodes::_iushr :
case Bytecodes::_ior :
case Bytecodes::_ixor :
case Bytecodes::_iand :
current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
case Bytecodes::_ineg :
current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
current_frame.push_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_ladd :
case Bytecodes::_lsub :
case Bytecodes::_lmul :
case Bytecodes::_ldiv :
case Bytecodes::_lrem :
case Bytecodes::_land :
case Bytecodes::_lor :
case Bytecodes::_lxor :
current_frame.pop_stack_2(
VerificationType::long2_type(),
VerificationType::long_type(), CHECK_VERIFY(this));
case Bytecodes::_lneg :
current_frame.pop_stack_2(
VerificationType::long2_type(),
VerificationType::long_type(), CHECK_VERIFY(this));
current_frame.push_stack_2(
VerificationType::long_type(),
VerificationType::long2_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_lshl :
case Bytecodes::_lshr :
case Bytecodes::_lushr :
current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
current_frame.pop_stack_2(
VerificationType::long2_type(),
VerificationType::long_type(), CHECK_VERIFY(this));
current_frame.push_stack_2(
VerificationType::long_type(),
VerificationType::long2_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_fadd :
case Bytecodes::_fsub :
case Bytecodes::_fmul :
case Bytecodes::_fdiv :
case Bytecodes::_frem :
current_frame.pop_stack(
VerificationType::float_type(), CHECK_VERIFY(this));
case Bytecodes::_fneg :
current_frame.pop_stack(
VerificationType::float_type(), CHECK_VERIFY(this));
current_frame.push_stack(
VerificationType::float_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_dadd :
case Bytecodes::_dsub :
case Bytecodes::_dmul :
case Bytecodes::_ddiv :
case Bytecodes::_drem :
current_frame.pop_stack_2(
VerificationType::double2_type(),
VerificationType::double_type(), CHECK_VERIFY(this));
case Bytecodes::_dneg :
current_frame.pop_stack_2(
VerificationType::double2_type(),
VerificationType::double_type(), CHECK_VERIFY(this));
current_frame.push_stack_2(
VerificationType::double_type(),
VerificationType::double2_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_iinc :
verify_iinc(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_i2l :
type = current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
current_frame.push_stack_2(
VerificationType::long_type(),
VerificationType::long2_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_l2i :
current_frame.pop_stack_2(
VerificationType::long2_type(),
VerificationType::long_type(), CHECK_VERIFY(this));
current_frame.push_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_i2f :
current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
current_frame.push_stack(
VerificationType::float_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_i2d :
current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
current_frame.push_stack_2(
VerificationType::double_type(),
VerificationType::double2_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_l2f :
current_frame.pop_stack_2(
VerificationType::long2_type(),
VerificationType::long_type(), CHECK_VERIFY(this));
current_frame.push_stack(
VerificationType::float_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_l2d :
current_frame.pop_stack_2(
VerificationType::long2_type(),
VerificationType::long_type(), CHECK_VERIFY(this));
current_frame.push_stack_2(
VerificationType::double_type(),
VerificationType::double2_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_f2i :
current_frame.pop_stack(
VerificationType::float_type(), CHECK_VERIFY(this));
current_frame.push_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_f2l :
current_frame.pop_stack(
VerificationType::float_type(), CHECK_VERIFY(this));
current_frame.push_stack_2(
VerificationType::long_type(),
VerificationType::long2_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_f2d :
current_frame.pop_stack(
VerificationType::float_type(), CHECK_VERIFY(this));
current_frame.push_stack_2(
VerificationType::double_type(),
VerificationType::double2_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_d2i :
current_frame.pop_stack_2(
VerificationType::double2_type(),
VerificationType::double_type(), CHECK_VERIFY(this));
current_frame.push_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_d2l :
current_frame.pop_stack_2(
VerificationType::double2_type(),
VerificationType::double_type(), CHECK_VERIFY(this));
current_frame.push_stack_2(
VerificationType::long_type(),
VerificationType::long2_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_d2f :
current_frame.pop_stack_2(
VerificationType::double2_type(),
VerificationType::double_type(), CHECK_VERIFY(this));
current_frame.push_stack(
VerificationType::float_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_i2b :
case Bytecodes::_i2c :
case Bytecodes::_i2s :
current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
current_frame.push_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_lcmp :
current_frame.pop_stack_2(
VerificationType::long2_type(),
VerificationType::long_type(), CHECK_VERIFY(this));
current_frame.pop_stack_2(
VerificationType::long2_type(),
VerificationType::long_type(), CHECK_VERIFY(this));
current_frame.push_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_fcmpl :
case Bytecodes::_fcmpg :
current_frame.pop_stack(
VerificationType::float_type(), CHECK_VERIFY(this));
current_frame.pop_stack(
VerificationType::float_type(), CHECK_VERIFY(this));
current_frame.push_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_dcmpl :
case Bytecodes::_dcmpg :
current_frame.pop_stack_2(
VerificationType::double2_type(),
VerificationType::double_type(), CHECK_VERIFY(this));
current_frame.pop_stack_2(
VerificationType::double2_type(),
VerificationType::double_type(), CHECK_VERIFY(this));
current_frame.push_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_if_icmpeq:
case Bytecodes::_if_icmpne:
case Bytecodes::_if_icmplt:
case Bytecodes::_if_icmpge:
case Bytecodes::_if_icmpgt:
case Bytecodes::_if_icmple:
current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
case Bytecodes::_ifeq:
case Bytecodes::_ifne:
case Bytecodes::_iflt:
case Bytecodes::_ifge:
case Bytecodes::_ifgt:
case Bytecodes::_ifle:
current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
target = bcs.dest();
stackmap_table.check_jump_target(
¤t_frame, target, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_if_acmpeq :
case Bytecodes::_if_acmpne :
current_frame.pop_stack(
VerificationType::reference_check(), CHECK_VERIFY(this));
case Bytecodes::_ifnull :
case Bytecodes::_ifnonnull :
current_frame.pop_stack(
VerificationType::reference_check(), CHECK_VERIFY(this));
target = bcs.dest();
stackmap_table.check_jump_target
(¤t_frame, target, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_goto :
target = bcs.dest();
stackmap_table.check_jump_target(
¤t_frame, target, CHECK_VERIFY(this));
no_control_flow = true; break;
case Bytecodes::_goto_w :
target = bcs.dest_w();
stackmap_table.check_jump_target(
¤t_frame, target, CHECK_VERIFY(this));
no_control_flow = true; break;
case Bytecodes::_tableswitch :
case Bytecodes::_lookupswitch :
verify_switch(
&bcs, code_length, code_data, ¤t_frame,
&stackmap_table, CHECK_VERIFY(this));
no_control_flow = true; break;
case Bytecodes::_ireturn :
type = current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
verify_return_value(return_type, type, bci,
¤t_frame, CHECK_VERIFY(this));
no_control_flow = true; break;
case Bytecodes::_lreturn :
type2 = current_frame.pop_stack(
VerificationType::long2_type(), CHECK_VERIFY(this));
type = current_frame.pop_stack(
VerificationType::long_type(), CHECK_VERIFY(this));
verify_return_value(return_type, type, bci,
¤t_frame, CHECK_VERIFY(this));
no_control_flow = true; break;
case Bytecodes::_freturn :
type = current_frame.pop_stack(
VerificationType::float_type(), CHECK_VERIFY(this));
verify_return_value(return_type, type, bci,
¤t_frame, CHECK_VERIFY(this));
no_control_flow = true; break;
case Bytecodes::_dreturn :
type2 = current_frame.pop_stack(
VerificationType::double2_type(), CHECK_VERIFY(this));
type = current_frame.pop_stack(
VerificationType::double_type(), CHECK_VERIFY(this));
verify_return_value(return_type, type, bci,
¤t_frame, CHECK_VERIFY(this));
no_control_flow = true; break;
case Bytecodes::_areturn :
type = current_frame.pop_stack(
VerificationType::reference_check(), CHECK_VERIFY(this));
verify_return_value(return_type, type, bci,
¤t_frame, CHECK_VERIFY(this));
no_control_flow = true; break;
case Bytecodes::_return :
if (return_type != VerificationType::bogus_type()) {
verify_error(ErrorContext::bad_code(bci),
"Method expects a return value");
return;
}
if (_method->name() == vmSymbols::object_initializer_name() &&
current_frame.flag_this_uninit()) {
verify_error(ErrorContext::bad_code(bci),
"Constructor must call super() or this() "
"before return");
return;
}
no_control_flow = true; break;
case Bytecodes::_getstatic :
case Bytecodes::_putstatic :
case Bytecodes::_getfield :
case Bytecodes::_putfield :
verify_field_instructions(
&bcs, ¤t_frame, cp, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_invokevirtual :
case Bytecodes::_invokespecial :
case Bytecodes::_invokestatic :
verify_invoke_instructions(
&bcs, code_length, ¤t_frame, (bci >= ex_min && bci < ex_max),
&this_uninit, return_type, cp, &stackmap_table, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_invokeinterface :
case Bytecodes::_invokedynamic :
verify_invoke_instructions(
&bcs, code_length, ¤t_frame, (bci >= ex_min && bci < ex_max),
&this_uninit, return_type, cp, &stackmap_table, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_new :
{
index = bcs.get_index_u2();
verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this));
VerificationType new_class_type =
cp_index_to_type(index, cp, CHECK_VERIFY(this));
if (!new_class_type.is_object()) {
verify_error(ErrorContext::bad_type(bci,
TypeOrigin::cp(index, new_class_type)),
"Illegal new instruction");
return;
}
type = VerificationType::uninitialized_type(bci);
current_frame.push_stack(type, CHECK_VERIFY(this));
no_control_flow = false; break;
}
case Bytecodes::_newarray :
type = get_newarray_type(bcs.get_index(), bci, CHECK_VERIFY(this));
current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
current_frame.push_stack(type, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_anewarray :
verify_anewarray(
bci, bcs.get_index_u2(), cp, ¤t_frame, CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_arraylength :
type = current_frame.pop_stack(
VerificationType::reference_check(), CHECK_VERIFY(this));
if (!(type.is_null() || type.is_array())) {
verify_error(ErrorContext::bad_type(
bci, current_frame.stack_top_ctx()),
bad_type_msg, "arraylength");
}
current_frame.push_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_checkcast :
{
index = bcs.get_index_u2();
verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this));
current_frame.pop_stack(object_type(), CHECK_VERIFY(this));
VerificationType klass_type = cp_index_to_type(
index, cp, CHECK_VERIFY(this));
current_frame.push_stack(klass_type, CHECK_VERIFY(this));
no_control_flow = false; break;
}
case Bytecodes::_instanceof : {
index = bcs.get_index_u2();
verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this));
current_frame.pop_stack(object_type(), CHECK_VERIFY(this));
current_frame.push_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
no_control_flow = false; break;
}
case Bytecodes::_monitorenter :
case Bytecodes::_monitorexit :
current_frame.pop_stack(
VerificationType::reference_check(), CHECK_VERIFY(this));
no_control_flow = false; break;
case Bytecodes::_multianewarray :
{
index = bcs.get_index_u2();
u2 dim = *(bcs.bcp()+3);
verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this));
VerificationType new_array_type =
cp_index_to_type(index, cp, CHECK_VERIFY(this));
if (!new_array_type.is_array()) {
verify_error(ErrorContext::bad_type(bci,
TypeOrigin::cp(index, new_array_type)),
"Illegal constant pool index in multianewarray instruction");
return;
}
if (dim < 1 || new_array_type.dimensions() < dim) {
verify_error(ErrorContext::bad_code(bci),
"Illegal dimension in multianewarray instruction: %d", dim);
return;
}
for (int i = 0; i < dim; i++) {
current_frame.pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
}
current_frame.push_stack(new_array_type, CHECK_VERIFY(this));
no_control_flow = false; break;
}
case Bytecodes::_athrow :
type = VerificationType::reference_type(
vmSymbols::java_lang_Throwable());
current_frame.pop_stack(type, CHECK_VERIFY(this));
no_control_flow = true; break;
default:
verify_error(ErrorContext::bad_code(bci),
"Bad instruction: %02x", opcode);
no_control_flow = false;
return;
} // end switch
} // end Merge with the next instruction
assert(!(verified_exc_handlers && this_uninit),
"Exception handler targets got verified before this_uninit got set");
if (!verified_exc_handlers && bci >= ex_min && bci < ex_max) {
verify_exception_handler_targets(
bci, this_uninit, ¤t_frame, &stackmap_table, CHECK_VERIFY(this));
}
} // end while
if (!no_control_flow) {
verify_error(ErrorContext::bad_code(code_length),
"Control flow falls through code end");
return;
}
}
#undef bad_type_message
char* ClassVerifier::generate_code_data(methodHandle m, u4 code_length, TRAPS) {
char* code_data = NEW_RESOURCE_ARRAY(char, code_length);
memset(code_data, 0, sizeof(char) * code_length);
RawBytecodeStream bcs(m);
while (!bcs.is_last_bytecode()) {
if (bcs.raw_next() != Bytecodes::_illegal) {
int bci = bcs.bci();
if (bcs.raw_code() == Bytecodes::_new) {
code_data[bci] = NEW_OFFSET;
} else {
code_data[bci] = BYTECODE_OFFSET;
}
} else {
verify_error(ErrorContext::bad_code(bcs.bci()), "Bad instruction");
return NULL;
}
}
return code_data;
}
void ClassVerifier::verify_exception_handler_table(u4 code_length, char* code_data, int& min, int& max, TRAPS) {
ExceptionTable exhandlers(_method());
int exlength = exhandlers.length();
constantPoolHandle cp (THREAD, _method->constants());
for(int i = 0; i < exlength; i++) {
ExceptionTable exhandlers(_method());
u2 start_pc = exhandlers.start_pc(i);
u2 end_pc = exhandlers.end_pc(i);
u2 handler_pc = exhandlers.handler_pc(i);
if (start_pc >= code_length || code_data[start_pc] == 0) {
class_format_error("Illegal exception table start_pc %d", start_pc);
return;
}
if (end_pc != code_length) { // special case: end_pc == code_length
if (end_pc > code_length || code_data[end_pc] == 0) {
class_format_error("Illegal exception table end_pc %d", end_pc);
return;
}
}
if (handler_pc >= code_length || code_data[handler_pc] == 0) {
class_format_error("Illegal exception table handler_pc %d", handler_pc);
return;
}
int catch_type_index = exhandlers.catch_type_index(i);
if (catch_type_index != 0) {
VerificationType catch_type = cp_index_to_type(
catch_type_index, cp, CHECK_VERIFY(this));
VerificationType throwable =
VerificationType::reference_type(vmSymbols::java_lang_Throwable());
bool is_subclass = throwable.is_assignable_from(
catch_type, this, false, CHECK_VERIFY(this));
if (!is_subclass) {
verify_error(ErrorContext::bad_type(handler_pc,
TypeOrigin::cp(catch_type_index, catch_type),
TypeOrigin::implicit(throwable)),
"Catch type is not a subclass "
"of Throwable in exception handler %d", handler_pc);
return;
}
}
if (start_pc < min) min = start_pc;
if (end_pc > max) max = end_pc;
}
}
void ClassVerifier::verify_local_variable_table(u4 code_length, char* code_data, TRAPS) {
int localvariable_table_length = _method()->localvariable_table_length();
if (localvariable_table_length > 0) {
LocalVariableTableElement* table = _method()->localvariable_table_start();
for (int i = 0; i < localvariable_table_length; i++) {
u2 start_bci = table[i].start_bci;
u2 length = table[i].length;
if (start_bci >= code_length || code_data[start_bci] == 0) {
class_format_error(
"Illegal local variable table start_pc %d", start_bci);
return;
}
u4 end_bci = (u4)(start_bci + length);
if (end_bci != code_length) {
if (end_bci >= code_length || code_data[end_bci] == 0) {
class_format_error( "Illegal local variable table length %d", length);
return;
}
}
}
}
}
u2 ClassVerifier::verify_stackmap_table(u2 stackmap_index, u2 bci,
StackMapFrame* current_frame,
StackMapTable* stackmap_table,
bool no_control_flow, TRAPS) {
if (stackmap_index < stackmap_table->get_frame_count()) {
u2 this_offset = stackmap_table->get_offset(stackmap_index);
if (no_control_flow && this_offset > bci) {
verify_error(ErrorContext::missing_stackmap(bci),
"Expecting a stack map frame");
return 0;
}
if (this_offset == bci) {
ErrorContext ctx;
bool matches = stackmap_table->match_stackmap(
current_frame, this_offset, stackmap_index,
!no_control_flow, true, &ctx, CHECK_VERIFY_(this, 0));
if (!matches) {
verify_error(ctx, "Instruction type does not match stack map");
return 0;
}
stackmap_index++;
} else if (this_offset < bci) {
class_format_error("Bad stack map offset %d", this_offset);
return 0;
}
} else if (no_control_flow) {
verify_error(ErrorContext::bad_code(bci), "Expecting a stack map frame");
return 0;
}
return stackmap_index;
}
void ClassVerifier::verify_exception_handler_targets(u2 bci, bool this_uninit, StackMapFrame* current_frame,
StackMapTable* stackmap_table, TRAPS) {
constantPoolHandle cp (THREAD, _method->constants());
ExceptionTable exhandlers(_method());
int exlength = exhandlers.length();
for(int i = 0; i < exlength; i++) {
ExceptionTable exhandlers(_method());
u2 start_pc = exhandlers.start_pc(i);
u2 end_pc = exhandlers.end_pc(i);
u2 handler_pc = exhandlers.handler_pc(i);
int catch_type_index = exhandlers.catch_type_index(i);
if(bci >= start_pc && bci < end_pc) {
u1 flags = current_frame->flags();
if (this_uninit) { flags |= FLAG_THIS_UNINIT; }
StackMapFrame* new_frame = current_frame->frame_in_exception_handler(flags);
if (catch_type_index != 0) {
VerificationType catch_type = cp_index_to_type(
catch_type_index, cp, CHECK_VERIFY(this));
new_frame->push_stack(catch_type, CHECK_VERIFY(this));
} else {
VerificationType throwable =
VerificationType::reference_type(vmSymbols::java_lang_Throwable());
new_frame->push_stack(throwable, CHECK_VERIFY(this));
}
ErrorContext ctx;
bool matches = stackmap_table->match_stackmap(
new_frame, handler_pc, true, false, &ctx, CHECK_VERIFY(this));
if (!matches) {
verify_error(ctx, "Stack map does not match the one at "
"exception handler %d", handler_pc);
return;
}
}
}
}
void ClassVerifier::verify_cp_index(
u2 bci, constantPoolHandle cp, int index, TRAPS) {
int nconstants = cp->length();
if ((index <= 0) || (index >= nconstants)) {
verify_error(ErrorContext::bad_cp_index(bci, index),
"Illegal constant pool index %d in class %s",
index, cp->pool_holder()->external_name());
return;
}
}
void ClassVerifier::verify_cp_type(
u2 bci, int index, constantPoolHandle cp, unsigned int types, TRAPS) {
guarantee(cp->cache() == NULL, "not rewritten yet");
verify_cp_index(bci, cp, index, CHECK_VERIFY(this));
unsigned int tag = cp->tag_at(index).value();
if ((types & (1 << tag)) == 0) {
verify_error(ErrorContext::bad_cp_index(bci, index),
"Illegal type at constant pool entry %d in class %s",
index, cp->pool_holder()->external_name());
return;
}
}
void ClassVerifier::verify_cp_class_type(
u2 bci, int index, constantPoolHandle cp, TRAPS) {
verify_cp_index(bci, cp, index, CHECK_VERIFY(this));
constantTag tag = cp->tag_at(index);
if (!tag.is_klass() && !tag.is_unresolved_klass()) {
verify_error(ErrorContext::bad_cp_index(bci, index),
"Illegal type at constant pool entry %d in class %s",
index, cp->pool_holder()->external_name());
return;
}
}
void ClassVerifier::verify_error(ErrorContext ctx, const char* msg, ...) {
stringStream ss;
ctx.reset_frames();
_exception_type = vmSymbols::java_lang_VerifyError();
_error_context = ctx;
va_list va;
va_start(va, msg);
ss.vprint(msg, va);
va_end(va);
_message = ss.as_string();
#ifdef ASSERT
ResourceMark rm;
const char* exception_name = _exception_type->as_C_string();
Exceptions::debug_check_abort(exception_name, NULL);
#endif // ndef ASSERT
}
void ClassVerifier::class_format_error(const char* msg, ...) {
stringStream ss;
_exception_type = vmSymbols::java_lang_ClassFormatError();
va_list va;
va_start(va, msg);
ss.vprint(msg, va);
va_end(va);
if (!_method.is_null()) {
ss.print(" in method %s", _method->name_and_sig_as_C_string());
}
_message = ss.as_string();
}
Klass* ClassVerifier::load_class(Symbol* name, TRAPS) {
oop loader = current_class()->class_loader();
oop protection_domain = current_class()->protection_domain();
return SystemDictionary::resolve_or_fail(
name, Handle(THREAD, loader), Handle(THREAD, protection_domain),
true, CHECK_NULL);
}
bool ClassVerifier::is_protected_access(instanceKlassHandle this_class,
Klass* target_class,
Symbol* field_name,
Symbol* field_sig,
bool is_method) {
No_Safepoint_Verifier nosafepoint;
if (!this_class->is_subclass_of(target_class)) {
return false;
}
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);
if (m != NULL && m->is_protected()) {
if (!this_class->is_same_class_package(m->method_holder())) {
return true;
}
}
} else {
Klass* member_klass = target_instance->find_field(field_name, field_sig, &fd);
if (member_klass != NULL && fd.is_protected()) {
if (!this_class->is_same_class_package(member_klass)) {
return true;
}
}
}
return false;
}
void ClassVerifier::verify_ldc(
int opcode, u2 index, StackMapFrame* current_frame,
constantPoolHandle cp, u2 bci, TRAPS) {
verify_cp_index(bci, cp, index, CHECK_VERIFY(this));
constantTag tag = cp->tag_at(index);
unsigned int types;
if (opcode == Bytecodes::_ldc || opcode == Bytecodes::_ldc_w) {
if (!tag.is_unresolved_klass()) {
types = (1 << JVM_CONSTANT_Integer) | (1 << JVM_CONSTANT_Float)
| (1 << JVM_CONSTANT_String) | (1 << JVM_CONSTANT_Class)
| (1 << JVM_CONSTANT_MethodHandle) | (1 << JVM_CONSTANT_MethodType);
verify_cp_type(bci, index, cp, types, CHECK_VERIFY(this));
}
} else {
assert(opcode == Bytecodes::_ldc2_w, "must be ldc2_w");
types = (1 << JVM_CONSTANT_Double) | (1 << JVM_CONSTANT_Long);
verify_cp_type(bci, index, cp, types, CHECK_VERIFY(this));
}
if (tag.is_string() && cp->is_pseudo_string_at(index)) {
current_frame->push_stack(object_type(), CHECK_VERIFY(this));
} else if (tag.is_string()) {
current_frame->push_stack(
VerificationType::reference_type(
vmSymbols::java_lang_String()), CHECK_VERIFY(this));
} else if (tag.is_klass() || tag.is_unresolved_klass()) {
current_frame->push_stack(
VerificationType::reference_type(
vmSymbols::java_lang_Class()), CHECK_VERIFY(this));
} else if (tag.is_int()) {
current_frame->push_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
} else if (tag.is_float()) {
current_frame->push_stack(
VerificationType::float_type(), CHECK_VERIFY(this));
} else if (tag.is_double()) {
current_frame->push_stack_2(
VerificationType::double_type(),
VerificationType::double2_type(), CHECK_VERIFY(this));
} else if (tag.is_long()) {
current_frame->push_stack_2(
VerificationType::long_type(),
VerificationType::long2_type(), CHECK_VERIFY(this));
} else if (tag.is_method_handle()) {
current_frame->push_stack(
VerificationType::reference_type(
vmSymbols::java_lang_invoke_MethodHandle()), CHECK_VERIFY(this));
} else if (tag.is_method_type()) {
current_frame->push_stack(
VerificationType::reference_type(
vmSymbols::java_lang_invoke_MethodType()), CHECK_VERIFY(this));
} else {
verify_error(
ErrorContext::bad_cp_index(bci, index), "Invalid index in ldc");
return;
}
}
void ClassVerifier::verify_switch(
RawBytecodeStream* bcs, u4 code_length, char* code_data,
StackMapFrame* current_frame, StackMapTable* stackmap_table, TRAPS) {
int bci = bcs->bci();
address bcp = bcs->bcp();
address aligned_bcp = (address) round_to((intptr_t)(bcp + 1), jintSize);
if (_klass->major_version() < NONZERO_PADDING_BYTES_IN_SWITCH_MAJOR_VERSION) {
u2 padding_offset = 1;
while ((bcp + padding_offset) < aligned_bcp) {
if(*(bcp + padding_offset) != 0) {
verify_error(ErrorContext::bad_code(bci),
"Nonzero padding byte in lookswitch or tableswitch");
return;
}
padding_offset++;
}
}
int default_offset = (int) Bytes::get_Java_u4(aligned_bcp);
int keys, delta;
current_frame->pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
if (bcs->raw_code() == Bytecodes::_tableswitch) {
jint low = (jint)Bytes::get_Java_u4(aligned_bcp + jintSize);
jint high = (jint)Bytes::get_Java_u4(aligned_bcp + 2*jintSize);
if (low > high) {
verify_error(ErrorContext::bad_code(bci),
"low must be less than or equal to high in tableswitch");
return;
}
keys = high - low + 1;
if (keys < 0) {
verify_error(ErrorContext::bad_code(bci), "too many keys in tableswitch");
return;
}
delta = 1;
} else {
keys = (int)Bytes::get_Java_u4(aligned_bcp + jintSize);
if (keys < 0) {
verify_error(ErrorContext::bad_code(bci),
"number of keys in lookupswitch less than 0");
return;
}
delta = 2;
for (int i = 0; i < (keys - 1); i++) {
jint this_key = Bytes::get_Java_u4(aligned_bcp + (2+2*i)*jintSize);
jint next_key = Bytes::get_Java_u4(aligned_bcp + (2+2*i+2)*jintSize);
if (this_key >= next_key) {
verify_error(ErrorContext::bad_code(bci),
"Bad lookupswitch instruction");
return;
}
}
}
int target = bci + default_offset;
stackmap_table->check_jump_target(current_frame, target, CHECK_VERIFY(this));
for (int i = 0; i < keys; i++) {
aligned_bcp = (address)round_to((intptr_t)(bcs->bcp() + 1), jintSize);
target = bci + (jint)Bytes::get_Java_u4(aligned_bcp+(3+i*delta)*jintSize);
stackmap_table->check_jump_target(
current_frame, target, CHECK_VERIFY(this));
}
NOT_PRODUCT(aligned_bcp = NULL); // no longer valid at this point
}
bool ClassVerifier::name_in_supers(
Symbol* ref_name, instanceKlassHandle current) {
Klass* super = current->super();
while (super != NULL) {
if (super->name() == ref_name) {
return true;
}
super = super->super();
}
return false;
}
void ClassVerifier::verify_field_instructions(RawBytecodeStream* bcs,
StackMapFrame* current_frame,
constantPoolHandle cp,
TRAPS) {
u2 index = bcs->get_index_u2();
verify_cp_type(bcs->bci(), index, cp,
1 << JVM_CONSTANT_Fieldref, CHECK_VERIFY(this));
Symbol* field_name = cp->name_ref_at(index);
Symbol* field_sig = cp->signature_ref_at(index);
bool is_getfield = false;
if (!SignatureVerifier::is_valid_type_signature(field_sig)) {
class_format_error(
"Invalid signature for field in class %s referenced "
"from constant pool index %d", _klass->external_name(), index);
return;
}
VerificationType ref_class_type = cp_ref_index_to_type(
index, cp, CHECK_VERIFY(this));
if (!ref_class_type.is_object()) {
verify_error(ErrorContext::bad_type(bcs->bci(),
TypeOrigin::cp(index, ref_class_type)),
"Expecting reference to class in class %s at constant pool index %d",
_klass->external_name(), index);
return;
}
VerificationType target_class_type = ref_class_type;
assert(sizeof(VerificationType) == sizeof(uintptr_t),
"buffer type must match VerificationType size");
uintptr_t field_type_buffer[2];
VerificationType* field_type = (VerificationType*)field_type_buffer;
SignatureStream sig_stream(field_sig, false);
VerificationType stack_object_type;
int n = change_sig_to_verificationType(
&sig_stream, field_type, CHECK_VERIFY(this));
u2 bci = bcs->bci();
bool is_assignable;
switch (bcs->raw_code()) {
case Bytecodes::_getstatic: {
for (int i = 0; i < n; i++) {
current_frame->push_stack(field_type[i], CHECK_VERIFY(this));
}
break;
}
case Bytecodes::_putstatic: {
for (int i = n - 1; i >= 0; i--) {
current_frame->pop_stack(field_type[i], CHECK_VERIFY(this));
}
break;
}
case Bytecodes::_getfield: {
is_getfield = true;
stack_object_type = current_frame->pop_stack(
target_class_type, CHECK_VERIFY(this));
goto check_protected;
}
case Bytecodes::_putfield: {
for (int i = n - 1; i >= 0; i--) {
current_frame->pop_stack(field_type[i], CHECK_VERIFY(this));
}
stack_object_type = current_frame->pop_stack(CHECK_VERIFY(this));
fieldDescriptor fd;
if (stack_object_type == VerificationType::uninitialized_this_type() &&
target_class_type.equals(current_type()) &&
_klass->find_local_field(field_name, field_sig, &fd)) {
stack_object_type = current_type();
}
is_assignable = target_class_type.is_assignable_from(
stack_object_type, this, false, CHECK_VERIFY(this));
if (!is_assignable) {
verify_error(ErrorContext::bad_type(bci,
current_frame->stack_top_ctx(),
TypeOrigin::cp(index, target_class_type)),
"Bad type on operand stack in putfield");
return;
}
}
check_protected: {
if (_this_type == stack_object_type)
break; // stack_object_type must be assignable to _current_class_type
if (was_recursively_verified()) {
if (is_getfield) {
for (int i = 0; i < n; i++) {
current_frame->push_stack(field_type[i], CHECK_VERIFY(this));
}
}
return;
}
Symbol* ref_class_name =
cp->klass_name_at(cp->klass_ref_index_at(index));
if (!name_in_supers(ref_class_name, current_class()))
break;
Klass* ref_class_oop = load_class(ref_class_name, CHECK);
if (is_protected_access(current_class(), ref_class_oop, field_name,
field_sig, false)) {
is_assignable = current_type().is_assignable_from(
stack_object_type, this, true, CHECK_VERIFY(this));
if (!is_assignable) {
verify_error(ErrorContext::bad_type(bci,
current_frame->stack_top_ctx(),
TypeOrigin::implicit(current_type())),
"Bad access to protected data in getfield");
return;
}
}
break;
}
default: ShouldNotReachHere();
}
if (is_getfield) {
for (int i = 0; i < n; i++) {
current_frame->push_stack(field_type[i], CHECK_VERIFY(this));
}
}
}
void ClassVerifier::push_handlers(ExceptionTable* exhandlers,
GrowableArray<u4>* handler_list,
GrowableArray<u4>* handler_stack,
u4 bci) {
int exlength = exhandlers->length();
for(int x = 0; x < exlength; x++) {
if (bci >= exhandlers->start_pc(x) && bci < exhandlers->end_pc(x)) {
u4 exhandler_pc = exhandlers->handler_pc(x);
if (!handler_list->contains(exhandler_pc)) {
handler_stack->append_if_missing(exhandler_pc);
handler_list->append(exhandler_pc);
}
}
}
}
bool ClassVerifier::ends_in_athrow(u4 start_bc_offset) {
ResourceMark rm;
RawBytecodeStream bcs(method());
u4 code_length = method()->code_size();
bcs.set_start(start_bc_offset);
u4 target;
GrowableArray<u4>* bci_stack = new GrowableArray<u4>(30);
GrowableArray<u4>* handler_stack = new GrowableArray<u4>(30);
GrowableArray<u4>* handler_list = new GrowableArray<u4>(30);
GrowableArray<u4>* visited_branches = new GrowableArray<u4>(30);
ExceptionTable exhandlers(_method());
while (true) {
if (bcs.is_last_bytecode()) {
if ((bci_stack->is_empty()) || ((u4)bcs.end_bci() == code_length))
return false;
bcs.set_start(bci_stack->pop());
}
Bytecodes::Code opcode = bcs.raw_next();
u4 bci = bcs.bci();
push_handlers(&exhandlers, handler_list, handler_stack, bci);
switch (opcode) {
case Bytecodes::_if_icmpeq:
case Bytecodes::_if_icmpne:
case Bytecodes::_if_icmplt:
case Bytecodes::_if_icmpge:
case Bytecodes::_if_icmpgt:
case Bytecodes::_if_icmple:
case Bytecodes::_ifeq:
case Bytecodes::_ifne:
case Bytecodes::_iflt:
case Bytecodes::_ifge:
case Bytecodes::_ifgt:
case Bytecodes::_ifle:
case Bytecodes::_if_acmpeq:
case Bytecodes::_if_acmpne:
case Bytecodes::_ifnull:
case Bytecodes::_ifnonnull:
target = bcs.dest();
if (visited_branches->contains(bci)) {
if (bci_stack->is_empty()) {
if (handler_stack->is_empty()) {
return true;
} else {
bcs.set_start(handler_stack->pop());
}
} else {
bcs.set_start(bci_stack->pop());
}
} else {
if (target > bci) { // forward branch
if (target >= code_length) return false;
bci_stack->push(target);
bcs.set_start(bcs.next_bci());
} else { // backward branch
bci_stack->push(bcs.next_bci());
bcs.set_start(target);
}
visited_branches->append(bci);
}
break;
case Bytecodes::_goto:
case Bytecodes::_goto_w:
target = (opcode == Bytecodes::_goto ? bcs.dest() : bcs.dest_w());
if (visited_branches->contains(bci)) {
if (bci_stack->is_empty()) {
if (handler_stack->is_empty()) {
return true;
} else {
bcs.set_start(handler_stack->pop());
}
} else {
bcs.set_start(bci_stack->pop());
}
} else {
if (target >= code_length) return false;
bcs.set_start(target);
visited_branches->append(bci);
}
break;
case Bytecodes::_lookupswitch:
case Bytecodes::_tableswitch:
{
address aligned_bcp = (address) round_to((intptr_t)(bcs.bcp() + 1), jintSize);
u4 default_offset = Bytes::get_Java_u4(aligned_bcp) + bci;
int keys, delta;
if (opcode == Bytecodes::_tableswitch) {
jint low = (jint)Bytes::get_Java_u4(aligned_bcp + jintSize);
jint high = (jint)Bytes::get_Java_u4(aligned_bcp + 2*jintSize);
if (low > high) return true;
keys = high - low + 1;
delta = 1;
} else {
keys = (int)Bytes::get_Java_u4(aligned_bcp + jintSize);
delta = 2;
}
if (keys < 0) return true;
bci_stack->push(bcs.next_bci());
for (int i = 0; i < keys; i++) {
u4 target = bci + (jint)Bytes::get_Java_u4(aligned_bcp+(3+i*delta)*jintSize);
if (target > code_length) return false;
bci_stack->push(target);
}
if (default_offset > code_length) return false;
bcs.set_start(default_offset);
break;
}
case Bytecodes::_return:
return false;
case Bytecodes::_athrow:
{
if (bci_stack->is_empty()) {
if (handler_stack->is_empty()) {
return true;
} else {
bcs.set_start(handler_stack->pop());
}
} else {
bcs.set_start(bci_stack->pop());
}
}
break;
default:
;
} // end switch
} // end while loop
return false;
}
void ClassVerifier::verify_invoke_init(
RawBytecodeStream* bcs, u2 ref_class_index, VerificationType ref_class_type,
StackMapFrame* current_frame, u4 code_length, bool in_try_block,
bool *this_uninit, constantPoolHandle cp, StackMapTable* stackmap_table,
TRAPS) {
u2 bci = bcs->bci();
VerificationType type = current_frame->pop_stack(
VerificationType::reference_check(), CHECK_VERIFY(this));
if (type == VerificationType::uninitialized_this_type()) {
Klass* superk = current_class()->super();
if (ref_class_type.name() != current_class()->name() &&
ref_class_type.name() != superk->name()) {
verify_error(ErrorContext::bad_type(bci,
TypeOrigin::implicit(ref_class_type),
TypeOrigin::implicit(current_type())),
"Bad <init> method call");
return;
}
if (in_try_block) {
ExceptionTable exhandlers(_method());
int exlength = exhandlers.length();
for(int i = 0; i < exlength; i++) {
u2 start_pc = exhandlers.start_pc(i);
u2 end_pc = exhandlers.end_pc(i);
if (bci >= start_pc && bci < end_pc) {
if (!ends_in_athrow(exhandlers.handler_pc(i))) {
verify_error(ErrorContext::bad_code(bci),
"Bad <init> method call from after the start of a try block");
return;
} else if (VerboseVerification) {
ResourceMark rm;
tty->print_cr(
"Survived call to ends_in_athrow(): %s",
current_class()->name()->as_C_string());
}
}
}
verify_exception_handler_targets(bci, true, current_frame,
stackmap_table, CHECK_VERIFY(this));
} // in_try_block
current_frame->initialize_object(type, current_type());
} else if (type.is_uninitialized()) {
u2 new_offset = type.bci();
address new_bcp = bcs->bcp() - bci + new_offset;
if (new_offset > (code_length - 3) || (*new_bcp) != Bytecodes::_new) {
verify_error(ErrorContext::bad_code(new_offset),
"Expecting new instruction");
return;
}
u2 new_class_index = Bytes::get_Java_u2(new_bcp + 1);
verify_cp_class_type(bci, new_class_index, cp, CHECK_VERIFY(this));
VerificationType new_class_type = cp_index_to_type(
new_class_index, cp, CHECK_VERIFY(this));
if (!new_class_type.equals(ref_class_type)) {
verify_error(ErrorContext::bad_type(bci,
TypeOrigin::cp(new_class_index, new_class_type),
TypeOrigin::cp(ref_class_index, ref_class_type)),
"Call to wrong <init> method");
return;
}
VerificationType objectref_type = new_class_type;
if (name_in_supers(ref_class_type.name(), current_class())) {
Klass* ref_klass = load_class(ref_class_type.name(), CHECK);
Method* m = InstanceKlass::cast(ref_klass)->uncached_lookup_method(
vmSymbols::object_initializer_name(),
cp->signature_ref_at(bcs->get_index_u2()), Klass::find_overpass);
if (m != NULL) {
instanceKlassHandle mh(THREAD, m->method_holder());
if (m->is_protected() && !mh->is_same_class_package(_klass())) {
bool assignable = current_type().is_assignable_from(
objectref_type, this, true, CHECK_VERIFY(this));
if (!assignable) {
verify_error(ErrorContext::bad_type(bci,
TypeOrigin::cp(new_class_index, objectref_type),
TypeOrigin::implicit(current_type())),
"Bad access to protected <init> method");
return;
}
}
}
}
if (in_try_block) {
verify_exception_handler_targets(bci, *this_uninit, current_frame,
stackmap_table, CHECK_VERIFY(this));
}
current_frame->initialize_object(type, new_class_type);
} else {
verify_error(ErrorContext::bad_type(bci, current_frame->stack_top_ctx()),
"Bad operand type when invoking <init>");
return;
}
}
bool ClassVerifier::is_same_or_direct_interface(
instanceKlassHandle klass,
VerificationType klass_type,
VerificationType ref_class_type) {
if (ref_class_type.equals(klass_type)) return true;
Array<Klass*>* local_interfaces = klass->local_interfaces();
if (local_interfaces != NULL) {
for (int x = 0; x < local_interfaces->length(); x++) {
Klass* k = local_interfaces->at(x);
assert (k != NULL && k->is_interface(), "invalid interface");
if (ref_class_type.equals(VerificationType::reference_type(k->name()))) {
return true;
}
}
}
return false;
}
void ClassVerifier::verify_invoke_instructions(
RawBytecodeStream* bcs, u4 code_length, StackMapFrame* current_frame,
bool in_try_block, bool *this_uninit, VerificationType return_type,
constantPoolHandle cp, StackMapTable* stackmap_table, TRAPS) {
u2 index = bcs->get_index_u2();
Bytecodes::Code opcode = bcs->raw_code();
unsigned int types;
switch (opcode) {
case Bytecodes::_invokeinterface:
types = 1 << JVM_CONSTANT_InterfaceMethodref;
break;
case Bytecodes::_invokedynamic:
types = 1 << JVM_CONSTANT_InvokeDynamic;
break;
case Bytecodes::_invokespecial:
case Bytecodes::_invokestatic:
types = (_klass->major_version() < STATIC_METHOD_IN_INTERFACE_MAJOR_VERSION) ?
(1 << JVM_CONSTANT_Methodref) :
((1 << JVM_CONSTANT_InterfaceMethodref) | (1 << JVM_CONSTANT_Methodref));
break;
default:
types = 1 << JVM_CONSTANT_Methodref;
}
verify_cp_type(bcs->bci(), index, cp, types, CHECK_VERIFY(this));
Symbol* method_name = cp->name_ref_at(index);
Symbol* method_sig = cp->signature_ref_at(index);
if (!SignatureVerifier::is_valid_method_signature(method_sig)) {
class_format_error(
"Invalid method signature in class %s referenced "
"from constant pool index %d", _klass->external_name(), index);
return;
}
VerificationType ref_class_type;
if (opcode == Bytecodes::_invokedynamic) {
if (!EnableInvokeDynamic ||
_klass->major_version() < Verifier::INVOKEDYNAMIC_MAJOR_VERSION) {
if (!EnableInvokeDynamic) {
class_format_error("invokedynamic instructions not enabled in this JVM");
} else {
class_format_error("invokedynamic instructions not supported by this class file version (%d), class %s",
_klass->major_version(), _klass->external_name());
}
return;
}
} else {
ref_class_type = cp_ref_index_to_type(index, cp, CHECK_VERIFY(this));
}
assert(sizeof(VerificationType) == sizeof(uintptr_t),
"buffer type must match VerificationType size");
uintptr_t on_stack_sig_types_buffer[128];
VerificationType* sig_types;
int size = (method_sig->utf8_length() - 3) * 2;
if (size > 128) {
ArgumentSizeComputer size_it(method_sig);
size = size_it.size();
sig_types = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, VerificationType, size);
} else{
sig_types = (VerificationType*)on_stack_sig_types_buffer;
}
SignatureStream sig_stream(method_sig);
int sig_i = 0;
while (!sig_stream.at_return_type()) {
sig_i += change_sig_to_verificationType(
&sig_stream, &sig_types[sig_i], CHECK_VERIFY(this));
sig_stream.next();
}
int nargs = sig_i;
#ifdef ASSERT
{
ArgumentSizeComputer size_it(method_sig);
assert(nargs == size_it.size(), "Argument sizes do not match");
assert(nargs <= (method_sig->utf8_length() - 3) * 2, "estimate of max size isn't conservative enough");
}
#endif
u2 bci = bcs->bci();
if (opcode == Bytecodes::_invokeinterface) {
address bcp = bcs->bcp();
if (*(bcp+3) != (nargs+1)) {
verify_error(ErrorContext::bad_code(bci),
"Inconsistent args count operand in invokeinterface");
return;
}
if (*(bcp+4) != 0) {
verify_error(ErrorContext::bad_code(bci),
"Fourth operand byte of invokeinterface must be zero");
return;
}
}
if (opcode == Bytecodes::_invokedynamic) {
address bcp = bcs->bcp();
if (*(bcp+3) != 0 || *(bcp+4) != 0) {
verify_error(ErrorContext::bad_code(bci),
"Third and fourth operand bytes of invokedynamic must be zero");
return;
}
}
if (method_name->byte_at(0) == '<') {
if (opcode != Bytecodes::_invokespecial ||
method_name != vmSymbols::object_initializer_name()) {
verify_error(ErrorContext::bad_code(bci),
"Illegal call to internal method");
return;
}
} else if (opcode == Bytecodes::_invokespecial
&& !is_same_or_direct_interface(current_class(), current_type(), ref_class_type)
&& !ref_class_type.equals(VerificationType::reference_type(
current_class()->super()->name()))) {
bool subtype = false;
bool have_imr_indirect = cp->tag_at(index).value() == JVM_CONSTANT_InterfaceMethodref;
if (!current_class()->is_anonymous()) {
subtype = ref_class_type.is_assignable_from(
current_type(), this, false, CHECK_VERIFY(this));
} else {
VerificationType host_klass_type =
VerificationType::reference_type(current_class()->host_klass()->name());
subtype = ref_class_type.is_assignable_from(host_klass_type, this, false, CHECK_VERIFY(this));
have_imr_indirect = (have_imr_indirect &&
!is_same_or_direct_interface(
InstanceKlass::cast(current_class()->host_klass()),
host_klass_type, ref_class_type));
}
if (!subtype) {
verify_error(ErrorContext::bad_code(bci),
"Bad invokespecial instruction: "
"current class isn't assignable to reference class.");
return;
} else if (have_imr_indirect) {
verify_error(ErrorContext::bad_code(bci),
"Bad invokespecial instruction: "
"interface method reference is in an indirect superinterface.");
return;
}
}
for (int i = nargs - 1; i >= 0; i--) { // Run backwards
current_frame->pop_stack(sig_types[i], CHECK_VERIFY(this));
}
if (opcode != Bytecodes::_invokestatic &&
opcode != Bytecodes::_invokedynamic) {
if (method_name == vmSymbols::object_initializer_name()) { // <init> method
verify_invoke_init(bcs, index, ref_class_type, current_frame,
code_length, in_try_block, this_uninit, cp, stackmap_table,
CHECK_VERIFY(this));
} else { // other methods
if (opcode == Bytecodes::_invokespecial) {
if (!current_class()->is_anonymous()) {
current_frame->pop_stack(current_type(), CHECK_VERIFY(this));
} else {
VerificationType top = current_frame->pop_stack(CHECK_VERIFY(this));
VerificationType hosttype =
VerificationType::reference_type(current_class()->host_klass()->name());
bool subtype = hosttype.is_assignable_from(top, this, false, CHECK_VERIFY(this));
if (!subtype) {
verify_error( ErrorContext::bad_type(current_frame->offset(),
current_frame->stack_top_ctx(),
TypeOrigin::implicit(top)),
"Bad type on operand stack");
return;
}
}
} else if (opcode == Bytecodes::_invokevirtual) {
VerificationType stack_object_type =
current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this));
if (current_type() != stack_object_type) {
assert(cp->cache() == NULL, "not rewritten yet");
Symbol* ref_class_name =
cp->klass_name_at(cp->klass_ref_index_at(index));
if (name_in_supers(ref_class_name, current_class())) {
Klass* ref_class = load_class(ref_class_name, CHECK);
if (is_protected_access(
_klass, ref_class, method_name, method_sig, true)) {
bool is_assignable = current_type().is_assignable_from(
stack_object_type, this, true, CHECK_VERIFY(this));
if (!is_assignable) {
if (ref_class_type.name() == vmSymbols::java_lang_Object()
&& stack_object_type.is_array()
&& method_name == vmSymbols::clone_name()) {
} else {
verify_error(ErrorContext::bad_type(bci,
current_frame->stack_top_ctx(),
TypeOrigin::implicit(current_type())),
"Bad access to protected data in invokevirtual");
return;
}
}
}
}
}
} else {
assert(opcode == Bytecodes::_invokeinterface, "Unexpected opcode encountered");
current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this));
}
}
}
if (sig_stream.type() != T_VOID) {
if (method_name == vmSymbols::object_initializer_name()) {
verify_error(ErrorContext::bad_code(bci),
"Return type must be void in <init> method");
return;
}
VerificationType return_type[2];
int n = change_sig_to_verificationType(
&sig_stream, return_type, CHECK_VERIFY(this));
for (int i = 0; i < n; i++) {
current_frame->push_stack(return_type[i], CHECK_VERIFY(this)); // push types backwards
}
}
}
VerificationType ClassVerifier::get_newarray_type(
u2 index, u2 bci, TRAPS) {
const char* from_bt[] = {
NULL, NULL, NULL, NULL, "[Z", "[C", "[F", "[D", "[B", "[S", "[I", "[J",
};
if (index < T_BOOLEAN || index > T_LONG) {
verify_error(ErrorContext::bad_code(bci), "Illegal newarray instruction");
return VerificationType::bogus_type();
}
Symbol* sig = create_temporary_symbol(
from_bt[index], 2, CHECK_(VerificationType::bogus_type()));
return VerificationType::reference_type(sig);
}
void ClassVerifier::verify_anewarray(
u2 bci, u2 index, constantPoolHandle cp,
StackMapFrame* current_frame, TRAPS) {
verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this));
current_frame->pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
VerificationType component_type =
cp_index_to_type(index, cp, CHECK_VERIFY(this));
int length;
char* arr_sig_str;
if (component_type.is_array()) { // it's an array
const char* component_name = component_type.name()->as_utf8();
length = (int)strlen(component_name) + 1;
arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length);
arr_sig_str[0] = '[';
strncpy(&arr_sig_str[1], component_name, length - 1);
} else { // it's an object or interface
const char* component_name = component_type.name()->as_utf8();
length = (int)strlen(component_name) + 3;
arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length);
arr_sig_str[0] = '[';
arr_sig_str[1] = 'L';
strncpy(&arr_sig_str[2], component_name, length - 2);
arr_sig_str[length - 1] = ';';
}
Symbol* arr_sig = create_temporary_symbol(
arr_sig_str, length, CHECK_VERIFY(this));
VerificationType new_array_type = VerificationType::reference_type(arr_sig);
current_frame->push_stack(new_array_type, CHECK_VERIFY(this));
}
void ClassVerifier::verify_iload(u2 index, StackMapFrame* current_frame, TRAPS) {
current_frame->get_local(
index, VerificationType::integer_type(), CHECK_VERIFY(this));
current_frame->push_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
}
void ClassVerifier::verify_lload(u2 index, StackMapFrame* current_frame, TRAPS) {
current_frame->get_local_2(
index, VerificationType::long_type(),
VerificationType::long2_type(), CHECK_VERIFY(this));
current_frame->push_stack_2(
VerificationType::long_type(),
VerificationType::long2_type(), CHECK_VERIFY(this));
}
void ClassVerifier::verify_fload(u2 index, StackMapFrame* current_frame, TRAPS) {
current_frame->get_local(
index, VerificationType::float_type(), CHECK_VERIFY(this));
current_frame->push_stack(
VerificationType::float_type(), CHECK_VERIFY(this));
}
void ClassVerifier::verify_dload(u2 index, StackMapFrame* current_frame, TRAPS) {
current_frame->get_local_2(
index, VerificationType::double_type(),
VerificationType::double2_type(), CHECK_VERIFY(this));
current_frame->push_stack_2(
VerificationType::double_type(),
VerificationType::double2_type(), CHECK_VERIFY(this));
}
void ClassVerifier::verify_aload(u2 index, StackMapFrame* current_frame, TRAPS) {
VerificationType type = current_frame->get_local(
index, VerificationType::reference_check(), CHECK_VERIFY(this));
current_frame->push_stack(type, CHECK_VERIFY(this));
}
void ClassVerifier::verify_istore(u2 index, StackMapFrame* current_frame, TRAPS) {
current_frame->pop_stack(
VerificationType::integer_type(), CHECK_VERIFY(this));
current_frame->set_local(
index, VerificationType::integer_type(), CHECK_VERIFY(this));
}
void ClassVerifier::verify_lstore(u2 index, StackMapFrame* current_frame, TRAPS) {
current_frame->pop_stack_2(
VerificationType::long2_type(),
VerificationType::long_type(), CHECK_VERIFY(this));
current_frame->set_local_2(
index, VerificationType::long_type(),
VerificationType::long2_type(), CHECK_VERIFY(this));
}
void ClassVerifier::verify_fstore(u2 index, StackMapFrame* current_frame, TRAPS) {
current_frame->pop_stack(VerificationType::float_type(), CHECK_VERIFY(this));
current_frame->set_local(
index, VerificationType::float_type(), CHECK_VERIFY(this));
}
void ClassVerifier::verify_dstore(u2 index, StackMapFrame* current_frame, TRAPS) {
current_frame->pop_stack_2(
VerificationType::double2_type(),
VerificationType::double_type(), CHECK_VERIFY(this));
current_frame->set_local_2(
index, VerificationType::double_type(),
VerificationType::double2_type(), CHECK_VERIFY(this));
}
void ClassVerifier::verify_astore(u2 index, StackMapFrame* current_frame, TRAPS) {
VerificationType type = current_frame->pop_stack(
VerificationType::reference_check(), CHECK_VERIFY(this));
current_frame->set_local(index, type, CHECK_VERIFY(this));
}
void ClassVerifier::verify_iinc(u2 index, StackMapFrame* current_frame, TRAPS) {
VerificationType type = current_frame->get_local(
index, VerificationType::integer_type(), CHECK_VERIFY(this));
current_frame->set_local(index, type, CHECK_VERIFY(this));
}
void ClassVerifier::verify_return_value(
VerificationType return_type, VerificationType type, u2 bci,
StackMapFrame* current_frame, TRAPS) {
if (return_type == VerificationType::bogus_type()) {
verify_error(ErrorContext::bad_type(bci,
current_frame->stack_top_ctx(), TypeOrigin::signature(return_type)),
"Method expects a return value");
return;
}
bool match = return_type.is_assignable_from(type, this, false, CHECK_VERIFY(this));
if (!match) {
verify_error(ErrorContext::bad_type(bci,
current_frame->stack_top_ctx(), TypeOrigin::signature(return_type)),
"Bad return type");
return;
}
}
Symbol* ClassVerifier::create_temporary_symbol(const Symbol *s, int begin,
int end, TRAPS) {
Symbol* sym = SymbolTable::new_symbol(s, begin, end, CHECK_NULL);
_symbols->push(sym);
return sym;
}
Symbol* ClassVerifier::create_temporary_symbol(const char *s, int length, TRAPS) {
Symbol* sym = SymbolTable::new_symbol(s, length, CHECK_NULL);
_symbols->push(sym);
return sym;
}
C:\hotspot-69087d08d473\src\share\vm/classfile/verifier.hpp
#ifndef SHARE_VM_CLASSFILE_VERIFIER_HPP
#define SHARE_VM_CLASSFILE_VERIFIER_HPP
#include "classfile/verificationType.hpp"
#include "memory/gcLocker.hpp"
#include "oops/klass.hpp"
#include "oops/method.hpp"
#include "runtime/handles.hpp"
#include "utilities/growableArray.hpp"
#include "utilities/exceptions.hpp"
class Verifier : AllStatic {
public:
enum {
STRICTER_ACCESS_CTRL_CHECK_VERSION = 49,
STACKMAP_ATTRIBUTE_MAJOR_VERSION = 50,
INVOKEDYNAMIC_MAJOR_VERSION = 51,
NO_RELAX_ACCESS_CTRL_CHECK_VERSION = 52
};
typedef enum { ThrowException, NoException } Mode;
static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, TRAPS);
static bool should_verify_for(oop class_loader, bool should_verify_class);
static bool relax_access_for(oop class_loader);
private:
static bool is_eligible_for_verification(instanceKlassHandle klass, bool should_verify_class);
static Symbol* inference_verify(
instanceKlassHandle klass, char* msg, size_t msg_len, TRAPS);
};
class RawBytecodeStream;
class StackMapFrame;
class StackMapTable;
#define CHECK_VERIFY(verifier) \
CHECK); if ((verifier)->has_error()) return; ((void)0
#define CHECK_VERIFY_(verifier, result) \
CHECK_(result)); if ((verifier)->has_error()) return (result); ((void)0
class TypeOrigin VALUE_OBJ_CLASS_SPEC {
private:
typedef enum {
CF_LOCALS, // Comes from the current frame locals
CF_STACK, // Comes from the current frame expression stack
SM_LOCALS, // Comes from stackmap locals
SM_STACK, // Comes from stackmap expression stack
CONST_POOL, // Comes from the constant pool
SIG, // Comes from method signature
IMPLICIT, // Comes implicitly from code or context
BAD_INDEX, // No type, but the index is bad
FRAME_ONLY, // No type, context just contains the frame
NONE
} Origin;
Origin _origin;
u2 _index; // local, stack, or constant pool index
StackMapFrame* _frame; // source frame if CF or SM
VerificationType _type; // The actual type
TypeOrigin(
Origin origin, u2 index, StackMapFrame* frame, VerificationType type)
: _origin(origin), _index(index), _frame(frame), _type(type) {}
public:
TypeOrigin() : _origin(NONE), _index(0), _frame(NULL) {}
static TypeOrigin null();
static TypeOrigin local(u2 index, StackMapFrame* frame);
static TypeOrigin stack(u2 index, StackMapFrame* frame);
static TypeOrigin sm_local(u2 index, StackMapFrame* frame);
static TypeOrigin sm_stack(u2 index, StackMapFrame* frame);
static TypeOrigin cp(u2 index, VerificationType vt);
static TypeOrigin signature(VerificationType vt);
static TypeOrigin bad_index(u2 index);
static TypeOrigin implicit(VerificationType t);
static TypeOrigin frame(StackMapFrame* frame);
void reset_frame();
void details(outputStream* ss) const;
void print_frame(outputStream* ss) const;
const StackMapFrame* frame() const { return _frame; }
bool is_valid() const { return _origin != NONE; }
u2 index() const { return _index; }
#ifdef ASSERT
void print_on(outputStream* str) const;
#endif
};
class ErrorContext VALUE_OBJ_CLASS_SPEC {
private:
typedef enum {
INVALID_BYTECODE, // There was a problem with the bytecode
WRONG_TYPE, // Type value was not as expected
FLAGS_MISMATCH, // Frame flags are not assignable
BAD_CP_INDEX, // Invalid constant pool index
BAD_LOCAL_INDEX, // Invalid local index
LOCALS_SIZE_MISMATCH, // Frames have differing local counts
STACK_SIZE_MISMATCH, // Frames have different stack sizes
STACK_OVERFLOW, // Attempt to push onto a full expression stack
STACK_UNDERFLOW, // Attempt to pop and empty expression stack
MISSING_STACKMAP, // No stackmap for this location and there should be
BAD_STACKMAP, // Format error in stackmap
NO_FAULT, // No error
UNKNOWN
} FaultType;
int _bci;
FaultType _fault;
TypeOrigin _type;
TypeOrigin _expected;
ErrorContext(int bci, FaultType fault) :
_bci(bci), _fault(fault) {}
ErrorContext(int bci, FaultType fault, TypeOrigin type) :
_bci(bci), _fault(fault), _type(type) {}
ErrorContext(int bci, FaultType fault, TypeOrigin type, TypeOrigin exp) :
_bci(bci), _fault(fault), _type(type), _expected(exp) {}
public:
ErrorContext() : _bci(-1), _fault(NO_FAULT) {}
static ErrorContext bad_code(u2 bci) {
return ErrorContext(bci, INVALID_BYTECODE);
}
static ErrorContext bad_type(u2 bci, TypeOrigin type) {
return ErrorContext(bci, WRONG_TYPE, type);
}
static ErrorContext bad_type(u2 bci, TypeOrigin type, TypeOrigin exp) {
return ErrorContext(bci, WRONG_TYPE, type, exp);
}
static ErrorContext bad_flags(u2 bci, StackMapFrame* frame) {
return ErrorContext(bci, FLAGS_MISMATCH, TypeOrigin::frame(frame));
}
static ErrorContext bad_flags(u2 bci, StackMapFrame* cur, StackMapFrame* sm) {
return ErrorContext(bci, FLAGS_MISMATCH,
TypeOrigin::frame(cur), TypeOrigin::frame(sm));
}
static ErrorContext bad_cp_index(u2 bci, u2 index) {
return ErrorContext(bci, BAD_CP_INDEX, TypeOrigin::bad_index(index));
}
static ErrorContext bad_local_index(u2 bci, u2 index) {
return ErrorContext(bci, BAD_LOCAL_INDEX, TypeOrigin::bad_index(index));
}
static ErrorContext locals_size_mismatch(
u2 bci, StackMapFrame* frame0, StackMapFrame* frame1) {
return ErrorContext(bci, LOCALS_SIZE_MISMATCH,
TypeOrigin::frame(frame0), TypeOrigin::frame(frame1));
}
static ErrorContext stack_size_mismatch(
u2 bci, StackMapFrame* frame0, StackMapFrame* frame1) {
return ErrorContext(bci, STACK_SIZE_MISMATCH,
TypeOrigin::frame(frame0), TypeOrigin::frame(frame1));
}
static ErrorContext stack_overflow(u2 bci, StackMapFrame* frame) {
return ErrorContext(bci, STACK_OVERFLOW, TypeOrigin::frame(frame));
}
static ErrorContext stack_underflow(u2 bci, StackMapFrame* frame) {
return ErrorContext(bci, STACK_UNDERFLOW, TypeOrigin::frame(frame));
}
static ErrorContext missing_stackmap(u2 bci) {
return ErrorContext(bci, MISSING_STACKMAP);
}
static ErrorContext bad_stackmap(int index, StackMapFrame* frame) {
return ErrorContext(0, BAD_STACKMAP, TypeOrigin::frame(frame));
}
bool is_valid() const { return _fault != NO_FAULT; }
int bci() const { return _bci; }
void reset_frames() {
_type.reset_frame();
_expected.reset_frame();
}
void details(outputStream* ss, const Method* method) const;
#ifdef ASSERT
void print_on(outputStream* str) const {
str->print("error_context(%d, %d,", _bci, _fault);
_type.print_on(str);
str->print(",");
_expected.print_on(str);
str->print(")");
}
#endif
private:
void location_details(outputStream* ss, const Method* method) const;
void reason_details(outputStream* ss) const;
void frame_details(outputStream* ss) const;
void bytecode_details(outputStream* ss, const Method* method) const;
void handler_details(outputStream* ss, const Method* method) const;
void stackmap_details(outputStream* ss, const Method* method) const;
};
class ClassVerifier : public StackObj {
private:
Thread* _thread;
GrowableArray<Symbol*>* _symbols; // keep a list of symbols created
Symbol* _exception_type;
char* _message;
ErrorContext _error_context; // contains information about an error
void verify_method(methodHandle method, TRAPS);
char* generate_code_data(methodHandle m, u4 code_length, TRAPS);
void verify_exception_handler_table(u4 code_length, char* code_data,
int& min, int& max, TRAPS);
void verify_local_variable_table(u4 code_length, char* code_data, TRAPS);
VerificationType cp_ref_index_to_type(
int index, constantPoolHandle cp, TRAPS) {
return cp_index_to_type(cp->klass_ref_index_at(index), cp, THREAD);
}
bool is_protected_access(
instanceKlassHandle this_class, Klass* target_class,
Symbol* field_name, Symbol* field_sig, bool is_method);
void verify_cp_index(u2 bci, constantPoolHandle cp, int index, TRAPS);
void verify_cp_type(u2 bci, int index, constantPoolHandle cp,
unsigned int types, TRAPS);
void verify_cp_class_type(u2 bci, int index, constantPoolHandle cp, TRAPS);
u2 verify_stackmap_table(
u2 stackmap_index, u2 bci, StackMapFrame* current_frame,
StackMapTable* stackmap_table, bool no_control_flow, TRAPS);
void verify_exception_handler_targets(
u2 bci, bool this_uninit, StackMapFrame* current_frame,
StackMapTable* stackmap_table, TRAPS);
void verify_ldc(
int opcode, u2 index, StackMapFrame *current_frame,
constantPoolHandle cp, u2 bci, TRAPS);
void verify_switch(
RawBytecodeStream* bcs, u4 code_length, char* code_data,
StackMapFrame* current_frame, StackMapTable* stackmap_table, TRAPS);
void verify_field_instructions(
RawBytecodeStream* bcs, StackMapFrame* current_frame,
constantPoolHandle cp, TRAPS);
void verify_invoke_init(
RawBytecodeStream* bcs, u2 ref_index, VerificationType ref_class_type,
StackMapFrame* current_frame, u4 code_length, bool in_try_block,
bool* this_uninit, constantPoolHandle cp, StackMapTable* stackmap_table,
TRAPS);
void push_handlers(ExceptionTable* exhandlers,
GrowableArray<u4>* handler_list,
GrowableArray<u4>* handler_stack,
u4 bci);
bool ends_in_athrow(u4 start_bc_offset);
void verify_invoke_instructions(
RawBytecodeStream* bcs, u4 code_length, StackMapFrame* current_frame,
bool in_try_block, bool* this_uninit, VerificationType return_type,
constantPoolHandle cp, StackMapTable* stackmap_table, TRAPS);
VerificationType get_newarray_type(u2 index, u2 bci, TRAPS);
void verify_anewarray(u2 bci, u2 index, constantPoolHandle cp,
StackMapFrame* current_frame, TRAPS);
void verify_return_value(
VerificationType return_type, VerificationType type, u2 offset,
StackMapFrame* current_frame, TRAPS);
void verify_iload (u2 index, StackMapFrame* current_frame, TRAPS);
void verify_lload (u2 index, StackMapFrame* current_frame, TRAPS);
void verify_fload (u2 index, StackMapFrame* current_frame, TRAPS);
void verify_dload (u2 index, StackMapFrame* current_frame, TRAPS);
void verify_aload (u2 index, StackMapFrame* current_frame, TRAPS);
void verify_istore(u2 index, StackMapFrame* current_frame, TRAPS);
void verify_lstore(u2 index, StackMapFrame* current_frame, TRAPS);
void verify_fstore(u2 index, StackMapFrame* current_frame, TRAPS);
void verify_dstore(u2 index, StackMapFrame* current_frame, TRAPS);
void verify_astore(u2 index, StackMapFrame* current_frame, TRAPS);
void verify_iinc (u2 index, StackMapFrame* current_frame, TRAPS);
bool name_in_supers(Symbol* ref_name, instanceKlassHandle current);
VerificationType object_type() const;
instanceKlassHandle _klass; // the class being verified
methodHandle _method; // current method being verified
VerificationType _this_type; // the verification type of the current class
bool was_recursively_verified() { return _klass->is_rewritten(); }
bool is_same_or_direct_interface(instanceKlassHandle klass,
VerificationType klass_type, VerificationType ref_class_type);
public:
enum {
BYTECODE_OFFSET = 1,
NEW_OFFSET = 2
};
ClassVerifier(instanceKlassHandle klass, TRAPS);
~ClassVerifier();
Thread* thread() { return _thread; }
methodHandle method() { return _method; }
instanceKlassHandle current_class() const { return _klass; }
VerificationType current_type() const { return _this_type; }
void verify_class(TRAPS);
Symbol* result() const { return _exception_type; }
bool has_error() const { return result() != NULL; }
char* exception_message() {
stringStream ss;
ss.print("%s", _message);
_error_context.details(&ss, _method());
return ss.as_string();
}
void verify_error(ErrorContext ctx, const char* fmt, ...) ATTRIBUTE_PRINTF(3, 4);
void class_format_error(const char* fmt, ...) ATTRIBUTE_PRINTF(2, 3);
Klass* load_class(Symbol* name, TRAPS);
int change_sig_to_verificationType(
SignatureStream* sig_type, VerificationType* inference_type, TRAPS);
VerificationType cp_index_to_type(int index, constantPoolHandle cp, TRAPS) {
return VerificationType::reference_type(cp->klass_name_at(index));
}
Symbol* create_temporary_symbol(
const Symbol* s, int begin, int end, TRAPS);
Symbol* create_temporary_symbol(const char *s, int length, TRAPS);
TypeOrigin ref_ctx(const char* str, TRAPS);
};
inline int ClassVerifier::change_sig_to_verificationType(
SignatureStream* sig_type, VerificationType* inference_type, TRAPS) {
BasicType bt = sig_type->type();
switch (bt) {
case T_OBJECT:
case T_ARRAY:
{
Symbol* name = sig_type->as_symbol(CHECK_0);
Symbol* name_copy =
create_temporary_symbol(name, 0, name->utf8_length(), CHECK_0);
assert(name_copy == name, "symbols don't match");
VerificationType::reference_type(name_copy);
return 1;
}
case T_LONG:
return 2;
case T_DOUBLE:
return 2;
case T_INT:
case T_BOOLEAN:
case T_BYTE:
case T_CHAR:
case T_SHORT:
return 1;
case T_FLOAT:
return 1;
default:
ShouldNotReachHere();
return 1;
}
}
#endif // SHARE_VM_CLASSFILE_VERIFIER_HPP
C:\hotspot-69087d08d473\src\share\vm/classfile/vmSymbols.cpp
#include "precompiled.hpp"
#include "classfile/vmSymbols.hpp"
#include "memory/oopFactory.hpp"
#include "oops/oop.inline.hpp"
#include "runtime/handles.inline.hpp"
#include "utilities/xmlstream.hpp"
Symbol* vmSymbols::_symbols[vmSymbols::SID_LIMIT];
Symbol* vmSymbols::_type_signatures[T_VOID+1] = { NULL /*, NULL...*/ };
inline int compare_symbol(Symbol* a, Symbol* b) {
if (a == b) return 0;
return (address)a > (address)b ? +1 : -1;
}
static vmSymbols::SID vm_symbol_index[vmSymbols::SID_LIMIT];
extern "C" {
static int compare_vmsymbol_sid(const void* void_a, const void* void_b) {
Symbol* a = vmSymbols::symbol_at(*((vmSymbols::SID*) void_a));
Symbol* b = vmSymbols::symbol_at(*((vmSymbols::SID*) void_b));
return compare_symbol(a, b);
}
}
#ifdef ASSERT
#define VM_SYMBOL_ENUM_NAME_BODY(name, string) #name "\0"
static const char* vm_symbol_enum_names =
VM_SYMBOLS_DO(VM_SYMBOL_ENUM_NAME_BODY, VM_ALIAS_IGNORE)
"\0";
static const char* vm_symbol_enum_name(vmSymbols::SID sid) {
const char* string = &vm_symbol_enum_names[0];
int skip = (int)sid - (int)vmSymbols::FIRST_SID;
for (; skip != 0; skip--) {
size_t skiplen = strlen(string);
if (skiplen == 0) return "<unknown>"; // overflow
string += skiplen+1;
}
return string;
}
#endif //ASSERT
#define VM_SYMBOL_BODY(name, string) string "\0"
static const char* vm_symbol_bodies = VM_SYMBOLS_DO(VM_SYMBOL_BODY, VM_ALIAS_IGNORE);
void vmSymbols::initialize(TRAPS) {
assert((int)SID_LIMIT <= (1<<log2_SID_LIMIT), "must fit in this bitfield");
assert((int)SID_LIMIT*5 > (1<<log2_SID_LIMIT), "make the bitfield smaller, please");
assert(vmIntrinsics::FLAG_LIMIT <= (1 << vmIntrinsics::log2_FLAG_LIMIT), "must fit in this bitfield");
if (!UseSharedSpaces) {
const char* string = &vm_symbol_bodies[0];
for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
Symbol* sym = SymbolTable::new_permanent_symbol(string, CHECK);
_symbols[index] = sym;
string += strlen(string); // skip string body
string += 1; // skip trailing null
}
_type_signatures[T_BYTE] = byte_signature();
_type_signatures[T_CHAR] = char_signature();
_type_signatures[T_DOUBLE] = double_signature();
_type_signatures[T_FLOAT] = float_signature();
_type_signatures[T_INT] = int_signature();
_type_signatures[T_LONG] = long_signature();
_type_signatures[T_SHORT] = short_signature();
_type_signatures[T_BOOLEAN] = bool_signature();
_type_signatures[T_VOID] = void_signature();
}
#ifdef ASSERT
for (int i1 = (int)FIRST_SID; i1 < (int)SID_LIMIT; i1++) {
Symbol* sym = symbol_at((SID)i1);
for (int i2 = (int)FIRST_SID; i2 < i1; i2++) {
if (symbol_at((SID)i2) == sym) {
tty->print("*** Duplicate VM symbol SIDs %s(%d) and %s(%d): \"",
vm_symbol_enum_name((SID)i2), i2,
vm_symbol_enum_name((SID)i1), i1);
sym->print_symbol_on(tty);
tty->print_cr("\"");
}
}
}
#endif //ASSERT
{
for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
vm_symbol_index[index] = (SID)index;
}
int num_sids = SID_LIMIT-FIRST_SID;
qsort(&vm_symbol_index[FIRST_SID], num_sids, sizeof(vm_symbol_index[0]),
compare_vmsymbol_sid);
}
#ifdef ASSERT
{
assert(_symbols[NO_SID] == NULL, "must be");
const char* str = "java/lang/Object";
TempNewSymbol jlo = SymbolTable::new_permanent_symbol(str, CHECK);
assert(strncmp(str, (char*)jlo->base(), jlo->utf8_length()) == 0, "");
assert(jlo == java_lang_Object(), "");
SID sid = VM_SYMBOL_ENUM_NAME(java_lang_Object);
assert(find_sid(jlo) == sid, "");
assert(symbol_at(sid) == jlo, "");
for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
Symbol* sym = symbol_at((SID)index);
sid = find_sid(sym);
assert(sid == (SID)index, "symbol index works");
}
str = "format";
TempNewSymbol fmt = SymbolTable::new_permanent_symbol(str, CHECK);
sid = find_sid(fmt);
assert(sid == NO_SID, "symbol index works (negative test)");
}
#endif
}
#ifndef PRODUCT
const char* vmSymbols::name_for(vmSymbols::SID sid) {
if (sid == NO_SID)
return "NO_SID";
const char* string = &vm_symbol_bodies[0];
for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
if (index == (int)sid)
return string;
string += strlen(string); // skip string body
string += 1; // skip trailing null
}
return "BAD_SID";
}
#endif
void vmSymbols::symbols_do(SymbolClosure* f) {
for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
f->do_symbol(&_symbols[index]);
}
for (int i = 0; i < T_VOID+1; i++) {
f->do_symbol(&_type_signatures[i]);
}
}
void vmSymbols::serialize(SerializeClosure* soc) {
soc->do_region((u_char*)&_symbols[FIRST_SID],
(SID_LIMIT - FIRST_SID) * sizeof(_symbols[0]));
soc->do_region((u_char*)_type_signatures, sizeof(_type_signatures));
}
BasicType vmSymbols::signature_type(Symbol* s) {
assert(s != NULL, "checking");
for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
if (s == _type_signatures[i]) {
return (BasicType)i;
}
}
return T_OBJECT;
}
static int mid_hint = (int)vmSymbols::FIRST_SID+1;
#ifndef PRODUCT
static int find_sid_calls, find_sid_probes;
#endif
vmSymbols::SID vmSymbols::find_sid(Symbol* symbol) {
NOT_PRODUCT(find_sid_calls++);
int min = (int)FIRST_SID, max = (int)SID_LIMIT - 1;
SID sid = NO_SID, sid1;
int cmp1;
sid1 = vm_symbol_index[min];
cmp1 = compare_symbol(symbol, symbol_at(sid1));
if (cmp1 <= 0) { // before the first
if (cmp1 == 0) sid = sid1;
} else {
sid1 = vm_symbol_index[max];
cmp1 = compare_symbol(symbol, symbol_at(sid1));
if (cmp1 >= 0) { // after the last
if (cmp1 == 0) sid = sid1;
} else {
++min; --max; // endpoints are done
int mid = mid_hint; // start at previous success
while (max >= min) {
assert(mid >= min && mid <= max, "");
NOT_PRODUCT(find_sid_probes++);
sid1 = vm_symbol_index[mid];
cmp1 = compare_symbol(symbol, symbol_at(sid1));
if (cmp1 == 0) {
mid_hint = mid;
sid = sid1;
break;
}
if (cmp1 < 0)
max = mid - 1; // symbol < symbol_at(sid)
else
min = mid + 1;
mid = (max + min) / 2;
}
}
}
#ifdef ASSERT
static int find_sid_check_count = -2000;
if ((uint)++find_sid_check_count > (uint)100) {
if (find_sid_check_count > 0) find_sid_check_count = 0;
SID sid2 = NO_SID;
for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
Symbol* sym2 = symbol_at((SID)index);
if (sym2 == symbol) {
sid2 = (SID)index;
break;
}
}
if (_symbols[sid] != _symbols[sid2]) {
assert(sid == sid2, "binary same as linear search");
}
}
#endif //ASSERT
return sid;
}
vmSymbols::SID vmSymbols::find_sid(const char* symbol_name) {
Symbol* symbol = SymbolTable::probe(symbol_name, (int) strlen(symbol_name));
if (symbol == NULL) return NO_SID;
return find_sid(symbol);
}
static vmIntrinsics::ID wrapper_intrinsic(BasicType type, bool unboxing) {
#define TYPE2(type, unboxing) ((int)(type)*2 + ((unboxing) ? 1 : 0))
switch (TYPE2(type, unboxing)) {
#define BASIC_TYPE_CASE(type, box, unbox) \
case TYPE2(type, false): return vmIntrinsics::box; \
case TYPE2(type, true): return vmIntrinsics::unbox
BASIC_TYPE_CASE(T_BOOLEAN, _Boolean_valueOf, _booleanValue);
BASIC_TYPE_CASE(T_BYTE, _Byte_valueOf, _byteValue);
BASIC_TYPE_CASE(T_CHAR, _Character_valueOf, _charValue);
BASIC_TYPE_CASE(T_SHORT, _Short_valueOf, _shortValue);
BASIC_TYPE_CASE(T_INT, _Integer_valueOf, _intValue);
BASIC_TYPE_CASE(T_LONG, _Long_valueOf, _longValue);
BASIC_TYPE_CASE(T_FLOAT, _Float_valueOf, _floatValue);
BASIC_TYPE_CASE(T_DOUBLE, _Double_valueOf, _doubleValue);
#undef BASIC_TYPE_CASE
}
#undef TYPE2
return vmIntrinsics::_none;
}
sssssss16
最新推荐文章于 2024-09-08 10:25:07 发布