ciObjectFactory.cpp revision 2223
0N/A/*
1455N/A * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
0N/A * questions.
0N/A *
0N/A */
0N/A
0N/A#include "precompiled.hpp"
0N/A#include "ci/ciCPCache.hpp"
0N/A#include "ci/ciCallSite.hpp"
0N/A#include "ci/ciInstance.hpp"
0N/A#include "ci/ciInstanceKlass.hpp"
0N/A#include "ci/ciInstanceKlassKlass.hpp"
0N/A#include "ci/ciMethod.hpp"
0N/A#include "ci/ciMethodData.hpp"
0N/A#include "ci/ciMethodHandle.hpp"
0N/A#include "ci/ciMethodKlass.hpp"
0N/A#include "ci/ciNullObject.hpp"
0N/A#include "ci/ciObjArray.hpp"
0N/A#include "ci/ciObjArrayKlass.hpp"
0N/A#include "ci/ciObjArrayKlassKlass.hpp"
0N/A#include "ci/ciObjectFactory.hpp"
0N/A#include "ci/ciSymbol.hpp"
0N/A#include "ci/ciTypeArray.hpp"
0N/A#include "ci/ciTypeArrayKlass.hpp"
0N/A#include "ci/ciTypeArrayKlassKlass.hpp"
0N/A#include "ci/ciUtilities.hpp"
0N/A#include "classfile/systemDictionary.hpp"
0N/A#include "gc_interface/collectedHeap.inline.hpp"
0N/A#include "memory/allocation.inline.hpp"
0N/A#include "oops/oop.inline.hpp"
0N/A#include "oops/oop.inline2.hpp"
0N/A#include "runtime/fieldType.hpp"
0N/A
0N/A// ciObjectFactory
0N/A//
0N/A// This class handles requests for the creation of new instances
0N/A// of ciObject and its subclasses. It contains a caching mechanism
0N/A// which ensures that for each oop, at most one ciObject is created.
0N/A// This invariant allows more efficient implementation of ciObject.
0N/A//
0N/A// Implementation note: the oop->ciObject mapping is represented as
0N/A// a table stored in an array. Even though objects are moved
0N/A// by the garbage collector, the compactor preserves their relative
0N/A// order; address comparison of oops (in perm space) is safe so long
0N/A// as we prohibit GC during our comparisons. We currently use binary
0N/A// search to find the oop in the table, and inserting a new oop
0N/A// into the table may be costly. If this cost ends up being
1455N/A// problematic the underlying data structure can be switched to some
1455N/A// sort of balanced binary tree.
1455N/A
0N/AGrowableArray<ciObject*>* ciObjectFactory::_shared_ci_objects = NULL;
1455N/AciSymbol* ciObjectFactory::_shared_ci_symbols[vmSymbols::SID_LIMIT];
1455N/Aint ciObjectFactory::_shared_ident_limit = 0;
1455N/Avolatile bool ciObjectFactory::_initialized = false;
1455N/A
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObjectFactory::ciObjectFactory
0N/AciObjectFactory::ciObjectFactory(Arena* arena,
0N/A int expected_size) {
0N/A
0N/A for (int i = 0; i < NON_PERM_BUCKETS; i++) {
0N/A _non_perm_bucket[i] = NULL;
0N/A }
0N/A _non_perm_count = 0;
0N/A
0N/A _next_ident = _shared_ident_limit;
0N/A _arena = arena;
0N/A _ci_objects = new (arena) GrowableArray<ciObject*>(arena, expected_size, 0, NULL);
0N/A
0N/A // If the shared ci objects exist append them to this factory's objects
0N/A
0N/A if (_shared_ci_objects != NULL) {
0N/A _ci_objects->appendAll(_shared_ci_objects);
0N/A }
0N/A
0N/A _unloaded_methods = new (arena) GrowableArray<ciMethod*>(arena, 4, 0, NULL);
0N/A _unloaded_klasses = new (arena) GrowableArray<ciKlass*>(arena, 8, 0, NULL);
0N/A _unloaded_instances = new (arena) GrowableArray<ciInstance*>(arena, 4, 0, NULL);
0N/A _return_addresses =
0N/A new (arena) GrowableArray<ciReturnAddress*>(arena, 8, 0, NULL);
0N/A
0N/A _symbols = new (arena) GrowableArray<ciSymbol*>(arena, 100, 0, NULL);
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObjectFactory::ciObjectFactory
0N/Avoid ciObjectFactory::initialize() {
0N/A ASSERT_IN_VM;
0N/A JavaThread* thread = JavaThread::current();
0N/A HandleMark handle_mark(thread);
0N/A
0N/A // This Arena is long lived and exists in the resource mark of the
0N/A // compiler thread that initializes the initial ciObjectFactory which
0N/A // creates the shared ciObjects that all later ciObjectFactories use.
0N/A Arena* arena = new Arena();
0N/A ciEnv initial(arena);
0N/A ciEnv* env = ciEnv::current();
0N/A env->_factory->init_shared_objects();
0N/A
0N/A _initialized = true;
0N/A
0N/A}
0N/A
0N/Avoid ciObjectFactory::init_shared_objects() {
0N/A
0N/A _next_ident = 1; // start numbering CI objects at 1
0N/A
0N/A {
0N/A // Create the shared symbols, but not in _shared_ci_objects.
0N/A int i;
0N/A for (i = vmSymbols::FIRST_SID; i < vmSymbols::SID_LIMIT; i++) {
0N/A Symbol* vmsym = vmSymbols::symbol_at((vmSymbols::SID) i);
0N/A assert(vmSymbols::find_sid(vmsym) == i, "1-1 mapping");
0N/A ciSymbol* sym = new (_arena) ciSymbol(vmsym, (vmSymbols::SID) i);
0N/A init_ident_of(sym);
0N/A _shared_ci_symbols[i] = sym;
0N/A }
0N/A#ifdef ASSERT
0N/A for (i = vmSymbols::FIRST_SID; i < vmSymbols::SID_LIMIT; i++) {
0N/A Symbol* vmsym = vmSymbols::symbol_at((vmSymbols::SID) i);
0N/A ciSymbol* sym = vm_symbol_at((vmSymbols::SID) i);
0N/A assert(sym->get_symbol() == vmsym, "oop must match");
0N/A }
0N/A assert(ciSymbol::void_class_signature()->get_symbol() == vmSymbols::void_class_signature(), "spot check");
0N/A#endif
0N/A }
0N/A
0N/A _ci_objects = new (_arena) GrowableArray<ciObject*>(_arena, 64, 0, NULL);
0N/A
0N/A for (int i = T_BOOLEAN; i <= T_CONFLICT; i++) {
0N/A BasicType t = (BasicType)i;
0N/A if (type2name(t) != NULL && t != T_OBJECT && t != T_ARRAY && t != T_NARROWOOP) {
0N/A ciType::_basic_types[t] = new (_arena) ciType(t);
0N/A init_ident_of(ciType::_basic_types[t]);
0N/A }
0N/A }
0N/A
0N/A ciEnv::_null_object_instance = new (_arena) ciNullObject();
0N/A init_ident_of(ciEnv::_null_object_instance);
0N/A ciEnv::_method_klass_instance =
0N/A get(Universe::methodKlassObj())->as_method_klass();
0N/A ciEnv::_klass_klass_instance =
0N/A get(Universe::klassKlassObj())->as_klass_klass();
0N/A ciEnv::_instance_klass_klass_instance =
0N/A get(Universe::instanceKlassKlassObj())
0N/A ->as_instance_klass_klass();
0N/A ciEnv::_type_array_klass_klass_instance =
0N/A get(Universe::typeArrayKlassKlassObj())
0N/A ->as_type_array_klass_klass();
0N/A ciEnv::_obj_array_klass_klass_instance =
0N/A get(Universe::objArrayKlassKlassObj())
0N/A ->as_obj_array_klass_klass();
0N/A
0N/A#define WK_KLASS_DEFN(name, ignore_s, opt) \
0N/A if (SystemDictionary::name() != NULL) \
0N/A ciEnv::_##name = get(SystemDictionary::name())->as_instance_klass();
0N/A
0N/A WK_KLASSES_DO(WK_KLASS_DEFN)
0N/A#undef WK_KLASS_DEFN
0N/A
0N/A for (int len = -1; len != _ci_objects->length(); ) {
0N/A len = _ci_objects->length();
0N/A for (int i2 = 0; i2 < len; i2++) {
0N/A ciObject* obj = _ci_objects->at(i2);
0N/A if (obj->is_loaded() && obj->is_instance_klass()) {
0N/A obj->as_instance_klass()->compute_nonstatic_fields();
0N/A }
0N/A }
0N/A }
0N/A
0N/A ciEnv::_unloaded_cisymbol = ciObjectFactory::get_symbol(vmSymbols::dummy_symbol());
0N/A // Create dummy instanceKlass and objArrayKlass object and assign them idents
0N/A ciEnv::_unloaded_ciinstance_klass = new (_arena) ciInstanceKlass(ciEnv::_unloaded_cisymbol, NULL, NULL);
0N/A init_ident_of(ciEnv::_unloaded_ciinstance_klass);
0N/A ciEnv::_unloaded_ciobjarrayklass = new (_arena) ciObjArrayKlass(ciEnv::_unloaded_cisymbol, ciEnv::_unloaded_ciinstance_klass, 1);
0N/A init_ident_of(ciEnv::_unloaded_ciobjarrayklass);
0N/A assert(ciEnv::_unloaded_ciobjarrayklass->is_obj_array_klass(), "just checking");
0N/A
0N/A get(Universe::boolArrayKlassObj());
0N/A get(Universe::charArrayKlassObj());
0N/A get(Universe::singleArrayKlassObj());
0N/A get(Universe::doubleArrayKlassObj());
0N/A get(Universe::byteArrayKlassObj());
0N/A get(Universe::shortArrayKlassObj());
0N/A get(Universe::intArrayKlassObj());
1455N/A get(Universe::longArrayKlassObj());
1455N/A
917N/A
917N/A
917N/A assert(_non_perm_count == 0, "no shared non-perm objects");
917N/A
0N/A // The shared_ident_limit is the first ident number that will
0N/A // be used for non-shared objects. That is, numbers less than
0N/A // this limit are permanently assigned to shared CI objects,
0N/A // while the higher numbers are recycled afresh by each new ciEnv.
0N/A
0N/A _shared_ident_limit = _next_ident;
0N/A _shared_ci_objects = _ci_objects;
0N/A}
ciSymbol* ciObjectFactory::get_symbol(Symbol* key) {
vmSymbols::SID sid = vmSymbols::find_sid(key);
if (sid != vmSymbols::NO_SID) {
// do not pollute the main cache with it
return vm_symbol_at(sid);
}
assert(vmSymbols::find_sid(key) == vmSymbols::NO_SID, "");
ciSymbol* s = new (arena()) ciSymbol(key, vmSymbols::NO_SID);
_symbols->push(s);
return s;
}
// Decrement the refcount when done on symbols referenced by this compilation.
void ciObjectFactory::remove_symbols() {
for (int i = 0; i < _symbols->length(); i++) {
ciSymbol* s = _symbols->at(i);
s->get_symbol()->decrement_refcount();
}
// Since _symbols is resource allocated we're not allowed to delete it
// but it'll go away just the same.
}
// ------------------------------------------------------------------
// ciObjectFactory::get
//
// Get the ciObject corresponding to some oop. If the ciObject has
// already been created, it is returned. Otherwise, a new ciObject
// is created.
ciObject* ciObjectFactory::get(oop key) {
ASSERT_IN_VM;
#ifdef ASSERT
if (CIObjectFactoryVerify) {
oop last = NULL;
for (int j = 0; j< _ci_objects->length(); j++) {
oop o = _ci_objects->at(j)->get_oop();
assert(last < o, "out of order");
last = o;
}
}
#endif // ASSERT
int len = _ci_objects->length();
int index = find(key, _ci_objects);
#ifdef ASSERT
if (CIObjectFactoryVerify) {
for (int i=0; i<_ci_objects->length(); i++) {
if (_ci_objects->at(i)->get_oop() == key) {
assert(index == i, " bad lookup");
}
}
}
#endif
if (!is_found_at(index, key, _ci_objects)) {
// Check in the non-perm area before putting it in the list.
NonPermObject* &bucket = find_non_perm(key);
if (bucket != NULL) {
return bucket->object();
}
// The ciObject does not yet exist. Create it and insert it
// into the cache.
Handle keyHandle(key);
ciObject* new_object = create_new_object(keyHandle());
assert(keyHandle() == new_object->get_oop(), "must be properly recorded");
init_ident_of(new_object);
if (!new_object->is_perm()) {
// Not a perm-space object.
insert_non_perm(bucket, keyHandle(), new_object);
return new_object;
}
if (len != _ci_objects->length()) {
// creating the new object has recursively entered new objects
// into the table. We need to recompute our index.
index = find(keyHandle(), _ci_objects);
}
assert(!is_found_at(index, keyHandle(), _ci_objects), "no double insert");
insert(index, new_object, _ci_objects);
return new_object;
}
return _ci_objects->at(index);
}
// ------------------------------------------------------------------
// ciObjectFactory::create_new_object
//
// Create a new ciObject from an oop.
//
// Implementation note: this functionality could be virtual behavior
// of the oop itself. For now, we explicitly marshal the object.
ciObject* ciObjectFactory::create_new_object(oop o) {
EXCEPTION_CONTEXT;
if (o->is_klass()) {
KlassHandle h_k(THREAD, (klassOop)o);
Klass* k = ((klassOop)o)->klass_part();
if (k->oop_is_instance()) {
return new (arena()) ciInstanceKlass(h_k);
} else if (k->oop_is_objArray()) {
return new (arena()) ciObjArrayKlass(h_k);
} else if (k->oop_is_typeArray()) {
return new (arena()) ciTypeArrayKlass(h_k);
} else if (k->oop_is_method()) {
return new (arena()) ciMethodKlass(h_k);
} else if (k->oop_is_klass()) {
if (k->oop_is_objArrayKlass()) {
return new (arena()) ciObjArrayKlassKlass(h_k);
} else if (k->oop_is_typeArrayKlass()) {
return new (arena()) ciTypeArrayKlassKlass(h_k);
} else if (k->oop_is_instanceKlass()) {
return new (arena()) ciInstanceKlassKlass(h_k);
} else {
assert(o == Universe::klassKlassObj(), "bad klassKlass");
return new (arena()) ciKlassKlass(h_k);
}
}
} else if (o->is_method()) {
methodHandle h_m(THREAD, (methodOop)o);
return new (arena()) ciMethod(h_m);
} else if (o->is_methodData()) {
methodDataHandle h_md(THREAD, (methodDataOop)o);
return new (arena()) ciMethodData(h_md);
} else if (o->is_instance()) {
instanceHandle h_i(THREAD, (instanceOop)o);
if (java_lang_invoke_CallSite::is_instance(o))
return new (arena()) ciCallSite(h_i);
else if (java_lang_invoke_MethodHandle::is_instance(o))
return new (arena()) ciMethodHandle(h_i);
else
return new (arena()) ciInstance(h_i);
} else if (o->is_objArray()) {
objArrayHandle h_oa(THREAD, (objArrayOop)o);
return new (arena()) ciObjArray(h_oa);
} else if (o->is_typeArray()) {
typeArrayHandle h_ta(THREAD, (typeArrayOop)o);
return new (arena()) ciTypeArray(h_ta);
} else if (o->is_constantPoolCache()) {
constantPoolCacheHandle h_cpc(THREAD, (constantPoolCacheOop) o);
return new (arena()) ciCPCache(h_cpc);
}
// The oop is of some type not supported by the compiler interface.
ShouldNotReachHere();
return NULL;
}
//------------------------------------------------------------------
// ciObjectFactory::get_unloaded_method
//
// Get the ciMethod representing an unloaded/unfound method.
//
// Implementation note: unloaded methods are currently stored in
// an unordered array, requiring a linear-time lookup for each
// unloaded method. This may need to change.
ciMethod* ciObjectFactory::get_unloaded_method(ciInstanceKlass* holder,
ciSymbol* name,
ciSymbol* signature) {
for (int i=0; i<_unloaded_methods->length(); i++) {
ciMethod* entry = _unloaded_methods->at(i);
if (entry->holder()->equals(holder) &&
entry->name()->equals(name) &&
entry->signature()->as_symbol()->equals(signature)) {
// We've found a match.
return entry;
}
}
// This is a new unloaded method. Create it and stick it in
// the cache.
ciMethod* new_method = new (arena()) ciMethod(holder, name, signature);
init_ident_of(new_method);
_unloaded_methods->append(new_method);
return new_method;
}
//------------------------------------------------------------------
// ciObjectFactory::get_unloaded_klass
//
// Get a ciKlass representing an unloaded klass.
//
// Implementation note: unloaded klasses are currently stored in
// an unordered array, requiring a linear-time lookup for each
// unloaded klass. This may need to change.
ciKlass* ciObjectFactory::get_unloaded_klass(ciKlass* accessing_klass,
ciSymbol* name,
bool create_if_not_found) {
EXCEPTION_CONTEXT;
oop loader = NULL;
oop domain = NULL;
if (accessing_klass != NULL) {
loader = accessing_klass->loader();
domain = accessing_klass->protection_domain();
}
for (int i=0; i<_unloaded_klasses->length(); i++) {
ciKlass* entry = _unloaded_klasses->at(i);
if (entry->name()->equals(name) &&
entry->loader() == loader &&
entry->protection_domain() == domain) {
// We've found a match.
return entry;
}
}
if (!create_if_not_found)
return NULL;
// This is a new unloaded klass. Create it and stick it in
// the cache.
ciKlass* new_klass = NULL;
// Two cases: this is an unloaded objArrayKlass or an
// unloaded instanceKlass. Deal with both.
if (name->byte_at(0) == '[') {
// Decompose the name.'
FieldArrayInfo fd;
BasicType element_type = FieldType::get_array_info(name->get_symbol(),
fd, THREAD);
if (HAS_PENDING_EXCEPTION) {
CLEAR_PENDING_EXCEPTION;
CURRENT_THREAD_ENV->record_out_of_memory_failure();
return ciEnv::_unloaded_ciobjarrayklass;
}
int dimension = fd.dimension();
assert(element_type != T_ARRAY, "unsuccessful decomposition");
ciKlass* element_klass = NULL;
if (element_type == T_OBJECT) {
ciEnv *env = CURRENT_THREAD_ENV;
ciSymbol* ci_name = env->get_symbol(fd.object_key());
element_klass =
env->get_klass_by_name(accessing_klass, ci_name, false)->as_instance_klass();
} else {
assert(dimension > 1, "one dimensional type arrays are always loaded.");
// The type array itself takes care of one of the dimensions.
dimension--;
// The element klass is a typeArrayKlass.
element_klass = ciTypeArrayKlass::make(element_type);
}
new_klass = new (arena()) ciObjArrayKlass(name, element_klass, dimension);
} else {
jobject loader_handle = NULL;
jobject domain_handle = NULL;
if (accessing_klass != NULL) {
loader_handle = accessing_klass->loader_handle();
domain_handle = accessing_klass->protection_domain_handle();
}
new_klass = new (arena()) ciInstanceKlass(name, loader_handle, domain_handle);
}
init_ident_of(new_klass);
_unloaded_klasses->append(new_klass);
return new_klass;
}
//------------------------------------------------------------------
// ciObjectFactory::get_unloaded_instance
//
// Get a ciInstance representing an as-yet undetermined instance of a given class.
//
ciInstance* ciObjectFactory::get_unloaded_instance(ciInstanceKlass* instance_klass) {
for (int i=0; i<_unloaded_instances->length(); i++) {
ciInstance* entry = _unloaded_instances->at(i);
if (entry->klass()->equals(instance_klass)) {
// We've found a match.
return entry;
}
}
// This is a new unloaded instance. Create it and stick it in
// the cache.
ciInstance* new_instance = new (arena()) ciInstance(instance_klass);
init_ident_of(new_instance);
_unloaded_instances->append(new_instance);
// make sure it looks the way we want:
assert(!new_instance->is_loaded(), "");
assert(new_instance->klass() == instance_klass, "");
return new_instance;
}
//------------------------------------------------------------------
// ciObjectFactory::get_unloaded_klass_mirror
//
// Get a ciInstance representing an unresolved klass mirror.
//
// Currently, this ignores the parameters and returns a unique unloaded instance.
ciInstance* ciObjectFactory::get_unloaded_klass_mirror(ciKlass* type) {
assert(ciEnv::_Class_klass != NULL, "");
return get_unloaded_instance(ciEnv::_Class_klass->as_instance_klass());
}
//------------------------------------------------------------------
// ciObjectFactory::get_unloaded_method_handle_constant
//
// Get a ciInstance representing an unresolved method handle constant.
//
// Currently, this ignores the parameters and returns a unique unloaded instance.
ciInstance* ciObjectFactory::get_unloaded_method_handle_constant(ciKlass* holder,
ciSymbol* name,
ciSymbol* signature,
int ref_kind) {
if (ciEnv::_MethodHandle_klass == NULL) return NULL;
return get_unloaded_instance(ciEnv::_MethodHandle_klass->as_instance_klass());
}
//------------------------------------------------------------------
// ciObjectFactory::get_unloaded_method_type_constant
//
// Get a ciInstance representing an unresolved method type constant.
//
// Currently, this ignores the parameters and returns a unique unloaded instance.
ciInstance* ciObjectFactory::get_unloaded_method_type_constant(ciSymbol* signature) {
if (ciEnv::_MethodType_klass == NULL) return NULL;
return get_unloaded_instance(ciEnv::_MethodType_klass->as_instance_klass());
}
//------------------------------------------------------------------
// ciObjectFactory::get_empty_methodData
//
// Get the ciMethodData representing the methodData for a method with
// none.
ciMethodData* ciObjectFactory::get_empty_methodData() {
ciMethodData* new_methodData = new (arena()) ciMethodData();
init_ident_of(new_methodData);
return new_methodData;
}
//------------------------------------------------------------------
// ciObjectFactory::get_return_address
//
// Get a ciReturnAddress for a specified bci.
ciReturnAddress* ciObjectFactory::get_return_address(int bci) {
for (int i=0; i<_return_addresses->length(); i++) {
ciReturnAddress* entry = _return_addresses->at(i);
if (entry->bci() == bci) {
// We've found a match.
return entry;
}
}
ciReturnAddress* new_ret_addr = new (arena()) ciReturnAddress(bci);
init_ident_of(new_ret_addr);
_return_addresses->append(new_ret_addr);
return new_ret_addr;
}
// ------------------------------------------------------------------
// ciObjectFactory::init_ident_of
void ciObjectFactory::init_ident_of(ciObject* obj) {
obj->set_ident(_next_ident++);
}
void ciObjectFactory::init_ident_of(ciSymbol* obj) {
obj->set_ident(_next_ident++);
}
// ------------------------------------------------------------------
// ciObjectFactory::find
//
// Use binary search to find the position of this oop in the cache.
// If there is no entry in the cache corresponding to this oop, return
// the position at which the oop should be inserted.
int ciObjectFactory::find(oop key, GrowableArray<ciObject*>* objects) {
int min = 0;
int max = objects->length()-1;
// print_contents();
while (max >= min) {
int mid = (max + min) / 2;
oop value = objects->at(mid)->get_oop();
if (value < key) {
min = mid + 1;
} else if (value > key) {
max = mid - 1;
} else {
return mid;
}
}
return min;
}
// ------------------------------------------------------------------
// ciObjectFactory::is_found_at
//
// Verify that the binary seach found the given key.
bool ciObjectFactory::is_found_at(int index, oop key, GrowableArray<ciObject*>* objects) {
return (index < objects->length() &&
objects->at(index)->get_oop() == key);
}
// ------------------------------------------------------------------
// ciObjectFactory::insert
//
// Insert a ciObject into the table at some index.
void ciObjectFactory::insert(int index, ciObject* obj, GrowableArray<ciObject*>* objects) {
int len = objects->length();
if (len == index) {
objects->append(obj);
} else {
objects->append(objects->at(len-1));
int pos;
for (pos = len-2; pos >= index; pos--) {
objects->at_put(pos+1,objects->at(pos));
}
objects->at_put(index, obj);
}
#ifdef ASSERT
if (CIObjectFactoryVerify) {
oop last = NULL;
for (int j = 0; j< objects->length(); j++) {
oop o = objects->at(j)->get_oop();
assert(last < o, "out of order");
last = o;
}
}
#endif // ASSERT
}
static ciObjectFactory::NonPermObject* emptyBucket = NULL;
// ------------------------------------------------------------------
// ciObjectFactory::find_non_perm
//
// Use a small hash table, hashed on the klass of the key.
// If there is no entry in the cache corresponding to this oop, return
// the null tail of the bucket into which the oop should be inserted.
ciObjectFactory::NonPermObject* &ciObjectFactory::find_non_perm(oop key) {
// Be careful: is_perm might change from false to true.
// Thus, there might be a matching perm object in the table.
// If there is, this probe must find it.
if (key->is_perm() && _non_perm_count == 0) {
return emptyBucket;
} else if (key->is_instance()) {
if (key->klass() == SystemDictionary::Class_klass() && JavaObjectsInPerm) {
// class mirror instances are always perm
return emptyBucket;
}
// fall through to probe
} else if (key->is_array()) {
// fall through to probe
} else {
// not an array or instance
return emptyBucket;
}
ciObject* klass = get(key->klass());
NonPermObject* *bp = &_non_perm_bucket[(unsigned) klass->hash() % NON_PERM_BUCKETS];
for (NonPermObject* p; (p = (*bp)) != NULL; bp = &p->next()) {
if (is_equal(p, key)) break;
}
return (*bp);
}
// ------------------------------------------------------------------
// Code for for NonPermObject
//
inline ciObjectFactory::NonPermObject::NonPermObject(ciObjectFactory::NonPermObject* &bucket, oop key, ciObject* object) {
assert(ciObjectFactory::is_initialized(), "");
_object = object;
_next = bucket;
bucket = this;
}
// ------------------------------------------------------------------
// ciObjectFactory::insert_non_perm
//
// Insert a ciObject into the non-perm table.
void ciObjectFactory::insert_non_perm(ciObjectFactory::NonPermObject* &where, oop key, ciObject* obj) {
assert(&where != &emptyBucket, "must not try to fill empty bucket");
NonPermObject* p = new (arena()) NonPermObject(where, key, obj);
assert(where == p && is_equal(p, key) && p->object() == obj, "entry must match");
assert(find_non_perm(key) == p, "must find the same spot");
++_non_perm_count;
}
// ------------------------------------------------------------------
// ciObjectFactory::vm_symbol_at
// Get the ciSymbol corresponding to some index in vmSymbols.
ciSymbol* ciObjectFactory::vm_symbol_at(int index) {
assert(index >= vmSymbols::FIRST_SID && index < vmSymbols::SID_LIMIT, "oob");
return _shared_ci_symbols[index];
}
// ------------------------------------------------------------------
// ciObjectFactory::print_contents_impl
void ciObjectFactory::print_contents_impl() {
int len = _ci_objects->length();
tty->print_cr("ciObjectFactory (%d) oop contents:", len);
for (int i=0; i<len; i++) {
_ci_objects->at(i)->print();
tty->cr();
}
}
// ------------------------------------------------------------------
// ciObjectFactory::print_contents
void ciObjectFactory::print_contents() {
print();
tty->cr();
GUARDED_VM_ENTRY(print_contents_impl();)
}
// ------------------------------------------------------------------
// ciObjectFactory::print
//
// Print debugging information about the object factory
void ciObjectFactory::print() {
tty->print("<ciObjectFactory oops=%d unloaded_methods=%d unloaded_instances=%d unloaded_klasses=%d>",
_ci_objects->length(), _unloaded_methods->length(),
_unloaded_instances->length(),
_unloaded_klasses->length());
}