ciObjectFactory.cpp revision 113
0N/A/*
0N/A * Copyright 1999-2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
0N/A * have any questions.
0N/A *
0N/A */
0N/A
0N/A#include "incls/_precompiled.incl"
0N/A#include "incls/_ciObjectFactory.cpp.incl"
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
0N/A// problematic the underlying data structure can be switched to some
0N/A// sort of balanced binary tree.
0N/A
0N/AGrowableArray<ciObject*>* ciObjectFactory::_shared_ci_objects = NULL;
0N/AciSymbol* ciObjectFactory::_shared_ci_symbols[vmSymbols::SID_LIMIT];
0N/Aint ciObjectFactory::_shared_ident_limit = 0;
0N/Avolatile bool ciObjectFactory::_initialized = false;
0N/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 _return_addresses =
0N/A new (arena) GrowableArray<ciReturnAddress*>(arena, 8, 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 symbolHandle sym_handle = vmSymbolHandles::symbol_handle_at((vmSymbols::SID) i);
0N/A assert(vmSymbols::find_sid(sym_handle()) == i, "1-1 mapping");
0N/A ciSymbol* sym = new (_arena) ciSymbol(sym_handle);
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 symbolHandle sym_handle = vmSymbolHandles::symbol_handle_at((vmSymbols::SID) i);
0N/A ciSymbol* sym = vm_symbol_at((vmSymbols::SID) i);
0N/A assert(sym->get_oop() == sym_handle(), "oop must match");
0N/A }
0N/A assert(ciSymbol::void_class_signature()->get_oop() == 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;
113N/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::_symbol_klass_instance =
0N/A get(Universe::symbolKlassObj())->as_symbol_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 ciEnv::_ArrayStoreException =
0N/A get(SystemDictionary::ArrayStoreException_klass())
0N/A ->as_instance_klass();
0N/A ciEnv::_Class =
0N/A get(SystemDictionary::class_klass())
0N/A ->as_instance_klass();
0N/A ciEnv::_ClassCastException =
0N/A get(SystemDictionary::ClassCastException_klass())
0N/A ->as_instance_klass();
0N/A ciEnv::_Object =
0N/A get(SystemDictionary::object_klass())
0N/A ->as_instance_klass();
0N/A ciEnv::_Throwable =
0N/A get(SystemDictionary::throwable_klass())
0N/A ->as_instance_klass();
0N/A ciEnv::_Thread =
0N/A get(SystemDictionary::thread_klass())
0N/A ->as_instance_klass();
0N/A ciEnv::_OutOfMemoryError =
0N/A get(SystemDictionary::OutOfMemoryError_klass())
0N/A ->as_instance_klass();
0N/A ciEnv::_String =
0N/A get(SystemDictionary::string_klass())
0N/A ->as_instance_klass();
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 = (ciSymbol*) ciObjectFactory::get(vmSymbols::dummy_symbol_oop());
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());
0N/A get(Universe::longArrayKlassObj());
0N/A
0N/A
0N/A
0N/A assert(_non_perm_count == 0, "no shared non-perm objects");
0N/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}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObjectFactory::get
0N/A//
0N/A// Get the ciObject corresponding to some oop. If the ciObject has
0N/A// already been created, it is returned. Otherwise, a new ciObject
0N/A// is created.
0N/AciObject* ciObjectFactory::get(oop key) {
0N/A ASSERT_IN_VM;
0N/A
0N/A#ifdef ASSERT
0N/A oop last = NULL;
0N/A for (int j = 0; j< _ci_objects->length(); j++) {
0N/A oop o = _ci_objects->at(j)->get_oop();
0N/A assert(last < o, "out of order");
0N/A last = o;
0N/A }
0N/A#endif // ASSERT
0N/A int len = _ci_objects->length();
0N/A int index = find(key, _ci_objects);
0N/A#ifdef ASSERT
0N/A for (int i=0; i<_ci_objects->length(); i++) {
0N/A if (_ci_objects->at(i)->get_oop() == key) {
0N/A assert(index == i, " bad lookup");
0N/A }
0N/A }
0N/A#endif
0N/A if (!is_found_at(index, key, _ci_objects)) {
0N/A
0N/A // Check in the non-perm area before putting it in the list.
0N/A NonPermObject* &bucket = find_non_perm(key);
0N/A if (bucket != NULL) {
0N/A return bucket->object();
0N/A }
0N/A
0N/A // Check in the shared symbol area before putting it in the list.
0N/A if (key->is_symbol()) {
0N/A vmSymbols::SID sid = vmSymbols::find_sid((symbolOop)key);
0N/A if (sid != vmSymbols::NO_SID) {
0N/A // do not pollute the main cache with it
0N/A return vm_symbol_at(sid);
0N/A }
0N/A }
0N/A
0N/A // The ciObject does not yet exist. Create it and insert it
0N/A // into the cache.
0N/A Handle keyHandle(key);
0N/A ciObject* new_object = create_new_object(keyHandle());
0N/A assert(keyHandle() == new_object->get_oop(), "must be properly recorded");
0N/A init_ident_of(new_object);
0N/A if (!keyHandle->is_perm()) {
0N/A // Not a perm-space object.
0N/A insert_non_perm(bucket, keyHandle(), new_object);
0N/A return new_object;
0N/A }
0N/A new_object->set_perm();
0N/A if (len != _ci_objects->length()) {
0N/A // creating the new object has recursively entered new objects
0N/A // into the table. We need to recompute our index.
0N/A index = find(keyHandle(), _ci_objects);
0N/A }
0N/A assert(!is_found_at(index, keyHandle(), _ci_objects), "no double insert");
0N/A insert(index, new_object, _ci_objects);
0N/A return new_object;
0N/A }
0N/A return _ci_objects->at(index);
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObjectFactory::create_new_object
0N/A//
0N/A// Create a new ciObject from an oop.
0N/A//
0N/A// Implementation note: this functionality could be virtual behavior
0N/A// of the oop itself. For now, we explicitly marshal the object.
0N/AciObject* ciObjectFactory::create_new_object(oop o) {
0N/A EXCEPTION_CONTEXT;
0N/A
0N/A if (o->is_symbol()) {
0N/A symbolHandle h_o(THREAD, (symbolOop)o);
0N/A return new (arena()) ciSymbol(h_o);
0N/A } else if (o->is_klass()) {
0N/A KlassHandle h_k(THREAD, (klassOop)o);
0N/A Klass* k = ((klassOop)o)->klass_part();
0N/A if (k->oop_is_instance()) {
0N/A return new (arena()) ciInstanceKlass(h_k);
0N/A } else if (k->oop_is_objArray()) {
0N/A return new (arena()) ciObjArrayKlass(h_k);
0N/A } else if (k->oop_is_typeArray()) {
0N/A return new (arena()) ciTypeArrayKlass(h_k);
0N/A } else if (k->oop_is_method()) {
0N/A return new (arena()) ciMethodKlass(h_k);
0N/A } else if (k->oop_is_symbol()) {
0N/A return new (arena()) ciSymbolKlass(h_k);
0N/A } else if (k->oop_is_klass()) {
0N/A if (k->oop_is_objArrayKlass()) {
0N/A return new (arena()) ciObjArrayKlassKlass(h_k);
0N/A } else if (k->oop_is_typeArrayKlass()) {
0N/A return new (arena()) ciTypeArrayKlassKlass(h_k);
0N/A } else if (k->oop_is_instanceKlass()) {
0N/A return new (arena()) ciInstanceKlassKlass(h_k);
0N/A } else {
0N/A assert(o == Universe::klassKlassObj(), "bad klassKlass");
0N/A return new (arena()) ciKlassKlass(h_k);
0N/A }
0N/A }
0N/A } else if (o->is_method()) {
0N/A methodHandle h_m(THREAD, (methodOop)o);
0N/A return new (arena()) ciMethod(h_m);
0N/A } else if (o->is_methodData()) {
0N/A methodDataHandle h_md(THREAD, (methodDataOop)o);
0N/A return new (arena()) ciMethodData(h_md);
0N/A } else if (o->is_instance()) {
0N/A instanceHandle h_i(THREAD, (instanceOop)o);
0N/A return new (arena()) ciInstance(h_i);
0N/A } else if (o->is_objArray()) {
0N/A objArrayHandle h_oa(THREAD, (objArrayOop)o);
0N/A return new (arena()) ciObjArray(h_oa);
0N/A } else if (o->is_typeArray()) {
0N/A typeArrayHandle h_ta(THREAD, (typeArrayOop)o);
0N/A return new (arena()) ciTypeArray(h_ta);
0N/A }
0N/A
0N/A // The oop is of some type not supported by the compiler interface.
0N/A ShouldNotReachHere();
0N/A return NULL;
0N/A}
0N/A
0N/A//------------------------------------------------------------------
0N/A// ciObjectFactory::get_unloaded_method
0N/A//
0N/A// Get the ciMethod representing an unloaded/unfound method.
0N/A//
0N/A// Implementation note: unloaded methods are currently stored in
0N/A// an unordered array, requiring a linear-time lookup for each
0N/A// unloaded method. This may need to change.
0N/AciMethod* ciObjectFactory::get_unloaded_method(ciInstanceKlass* holder,
0N/A ciSymbol* name,
0N/A ciSymbol* signature) {
0N/A for (int i=0; i<_unloaded_methods->length(); i++) {
0N/A ciMethod* entry = _unloaded_methods->at(i);
0N/A if (entry->holder()->equals(holder) &&
0N/A entry->name()->equals(name) &&
0N/A entry->signature()->as_symbol()->equals(signature)) {
0N/A // We've found a match.
0N/A return entry;
0N/A }
0N/A }
0N/A
0N/A // This is a new unloaded method. Create it and stick it in
0N/A // the cache.
0N/A ciMethod* new_method = new (arena()) ciMethod(holder, name, signature);
0N/A
0N/A init_ident_of(new_method);
0N/A _unloaded_methods->append(new_method);
0N/A
0N/A return new_method;
0N/A}
0N/A
0N/A//------------------------------------------------------------------
0N/A// ciObjectFactory::get_unloaded_klass
0N/A//
0N/A// Get a ciKlass representing an unloaded klass.
0N/A//
0N/A// Implementation note: unloaded klasses are currently stored in
0N/A// an unordered array, requiring a linear-time lookup for each
0N/A// unloaded klass. This may need to change.
0N/AciKlass* ciObjectFactory::get_unloaded_klass(ciKlass* accessing_klass,
0N/A ciSymbol* name,
0N/A bool create_if_not_found) {
0N/A EXCEPTION_CONTEXT;
0N/A oop loader = NULL;
0N/A oop domain = NULL;
0N/A if (accessing_klass != NULL) {
0N/A loader = accessing_klass->loader();
0N/A domain = accessing_klass->protection_domain();
0N/A }
0N/A for (int i=0; i<_unloaded_klasses->length(); i++) {
0N/A ciKlass* entry = _unloaded_klasses->at(i);
0N/A if (entry->name()->equals(name) &&
0N/A entry->loader() == loader &&
0N/A entry->protection_domain() == domain) {
0N/A // We've found a match.
0N/A return entry;
0N/A }
0N/A }
0N/A
0N/A if (!create_if_not_found)
0N/A return NULL;
0N/A
0N/A // This is a new unloaded klass. Create it and stick it in
0N/A // the cache.
0N/A ciKlass* new_klass = NULL;
0N/A
0N/A // Two cases: this is an unloaded objArrayKlass or an
0N/A // unloaded instanceKlass. Deal with both.
0N/A if (name->byte_at(0) == '[') {
0N/A // Decompose the name.'
0N/A jint dimension = 0;
0N/A symbolOop element_name = NULL;
0N/A BasicType element_type= FieldType::get_array_info(name->get_symbolOop(),
0N/A &dimension,
0N/A &element_name,
0N/A THREAD);
0N/A if (HAS_PENDING_EXCEPTION) {
0N/A CLEAR_PENDING_EXCEPTION;
0N/A CURRENT_THREAD_ENV->record_out_of_memory_failure();
0N/A return ciEnv::_unloaded_ciobjarrayklass;
0N/A }
0N/A assert(element_type != T_ARRAY, "unsuccessful decomposition");
0N/A ciKlass* element_klass = NULL;
0N/A if (element_type == T_OBJECT) {
0N/A ciEnv *env = CURRENT_THREAD_ENV;
0N/A ciSymbol* ci_name = env->get_object(element_name)->as_symbol();
0N/A element_klass =
0N/A env->get_klass_by_name(accessing_klass, ci_name, false)->as_instance_klass();
0N/A } else {
0N/A assert(dimension > 1, "one dimensional type arrays are always loaded.");
0N/A
0N/A // The type array itself takes care of one of the dimensions.
0N/A dimension--;
0N/A
0N/A // The element klass is a typeArrayKlass.
0N/A element_klass = ciTypeArrayKlass::make(element_type);
0N/A }
0N/A new_klass = new (arena()) ciObjArrayKlass(name, element_klass, dimension);
0N/A } else {
0N/A jobject loader_handle = NULL;
0N/A jobject domain_handle = NULL;
0N/A if (accessing_klass != NULL) {
0N/A loader_handle = accessing_klass->loader_handle();
0N/A domain_handle = accessing_klass->protection_domain_handle();
0N/A }
0N/A new_klass = new (arena()) ciInstanceKlass(name, loader_handle, domain_handle);
0N/A }
0N/A init_ident_of(new_klass);
0N/A _unloaded_klasses->append(new_klass);
0N/A
0N/A return new_klass;
0N/A}
0N/A
0N/A//------------------------------------------------------------------
0N/A// ciObjectFactory::get_empty_methodData
0N/A//
0N/A// Get the ciMethodData representing the methodData for a method with
0N/A// none.
0N/AciMethodData* ciObjectFactory::get_empty_methodData() {
0N/A ciMethodData* new_methodData = new (arena()) ciMethodData();
0N/A init_ident_of(new_methodData);
0N/A return new_methodData;
0N/A}
0N/A
0N/A//------------------------------------------------------------------
0N/A// ciObjectFactory::get_return_address
0N/A//
0N/A// Get a ciReturnAddress for a specified bci.
0N/AciReturnAddress* ciObjectFactory::get_return_address(int bci) {
0N/A for (int i=0; i<_return_addresses->length(); i++) {
0N/A ciReturnAddress* entry = _return_addresses->at(i);
0N/A if (entry->bci() == bci) {
0N/A // We've found a match.
0N/A return entry;
0N/A }
0N/A }
0N/A
0N/A ciReturnAddress* new_ret_addr = new (arena()) ciReturnAddress(bci);
0N/A init_ident_of(new_ret_addr);
0N/A _return_addresses->append(new_ret_addr);
0N/A return new_ret_addr;
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObjectFactory::init_ident_of
0N/Avoid ciObjectFactory::init_ident_of(ciObject* obj) {
0N/A obj->set_ident(_next_ident++);
0N/A}
0N/A
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObjectFactory::find
0N/A//
0N/A// Use binary search to find the position of this oop in the cache.
0N/A// If there is no entry in the cache corresponding to this oop, return
0N/A// the position at which the oop should be inserted.
0N/Aint ciObjectFactory::find(oop key, GrowableArray<ciObject*>* objects) {
0N/A int min = 0;
0N/A int max = objects->length()-1;
0N/A
0N/A // print_contents();
0N/A
0N/A while (max >= min) {
0N/A int mid = (max + min) / 2;
0N/A oop value = objects->at(mid)->get_oop();
0N/A if (value < key) {
0N/A min = mid + 1;
0N/A } else if (value > key) {
0N/A max = mid - 1;
0N/A } else {
0N/A return mid;
0N/A }
0N/A }
0N/A return min;
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObjectFactory::is_found_at
0N/A//
0N/A// Verify that the binary seach found the given key.
0N/Abool ciObjectFactory::is_found_at(int index, oop key, GrowableArray<ciObject*>* objects) {
0N/A return (index < objects->length() &&
0N/A objects->at(index)->get_oop() == key);
0N/A}
0N/A
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObjectFactory::insert
0N/A//
0N/A// Insert a ciObject into the table at some index.
0N/Avoid ciObjectFactory::insert(int index, ciObject* obj, GrowableArray<ciObject*>* objects) {
0N/A int len = objects->length();
0N/A if (len == index) {
0N/A objects->append(obj);
0N/A } else {
0N/A objects->append(objects->at(len-1));
0N/A int pos;
0N/A for (pos = len-2; pos >= index; pos--) {
0N/A objects->at_put(pos+1,objects->at(pos));
0N/A }
0N/A objects->at_put(index, obj);
0N/A }
0N/A#ifdef ASSERT
0N/A oop last = NULL;
0N/A for (int j = 0; j< objects->length(); j++) {
0N/A oop o = objects->at(j)->get_oop();
0N/A assert(last < o, "out of order");
0N/A last = o;
0N/A }
0N/A#endif // ASSERT
0N/A}
0N/A
0N/Astatic ciObjectFactory::NonPermObject* emptyBucket = NULL;
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObjectFactory::find_non_perm
0N/A//
0N/A// Use a small hash table, hashed on the klass of the key.
0N/A// If there is no entry in the cache corresponding to this oop, return
0N/A// the null tail of the bucket into which the oop should be inserted.
0N/AciObjectFactory::NonPermObject* &ciObjectFactory::find_non_perm(oop key) {
0N/A // Be careful: is_perm might change from false to true.
0N/A // Thus, there might be a matching perm object in the table.
0N/A // If there is, this probe must find it.
0N/A if (key->is_perm() && _non_perm_count == 0) {
0N/A return emptyBucket;
0N/A } else if (key->is_instance()) {
0N/A if (key->klass() == SystemDictionary::class_klass()) {
0N/A // class mirror instances are always perm
0N/A return emptyBucket;
0N/A }
0N/A // fall through to probe
0N/A } else if (key->is_array()) {
0N/A // fall through to probe
0N/A } else {
0N/A // not an array or instance
0N/A return emptyBucket;
0N/A }
0N/A
0N/A ciObject* klass = get(key->klass());
0N/A NonPermObject* *bp = &_non_perm_bucket[(unsigned) klass->hash() % NON_PERM_BUCKETS];
0N/A for (NonPermObject* p; (p = (*bp)) != NULL; bp = &p->next()) {
0N/A if (is_equal(p, key)) break;
0N/A }
0N/A return (*bp);
0N/A}
0N/A
0N/A
0N/A
0N/A// ------------------------------------------------------------------
0N/A// Code for for NonPermObject
0N/A//
0N/Ainline ciObjectFactory::NonPermObject::NonPermObject(ciObjectFactory::NonPermObject* &bucket, oop key, ciObject* object) {
0N/A assert(ciObjectFactory::is_initialized(), "");
0N/A _object = object;
0N/A _next = bucket;
0N/A bucket = this;
0N/A}
0N/A
0N/A
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObjectFactory::insert_non_perm
0N/A//
0N/A// Insert a ciObject into the non-perm table.
0N/Avoid ciObjectFactory::insert_non_perm(ciObjectFactory::NonPermObject* &where, oop key, ciObject* obj) {
0N/A assert(&where != &emptyBucket, "must not try to fill empty bucket");
0N/A NonPermObject* p = new (arena()) NonPermObject(where, key, obj);
0N/A assert(where == p && is_equal(p, key) && p->object() == obj, "entry must match");
0N/A assert(find_non_perm(key) == p, "must find the same spot");
0N/A ++_non_perm_count;
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObjectFactory::vm_symbol_at
0N/A// Get the ciSymbol corresponding to some index in vmSymbols.
0N/AciSymbol* ciObjectFactory::vm_symbol_at(int index) {
0N/A assert(index >= vmSymbols::FIRST_SID && index < vmSymbols::SID_LIMIT, "oob");
0N/A return _shared_ci_symbols[index];
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObjectFactory::print_contents_impl
0N/Avoid ciObjectFactory::print_contents_impl() {
0N/A int len = _ci_objects->length();
0N/A tty->print_cr("ciObjectFactory (%d) oop contents:", len);
0N/A for (int i=0; i<len; i++) {
0N/A _ci_objects->at(i)->print();
0N/A tty->cr();
0N/A }
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObjectFactory::print_contents
0N/Avoid ciObjectFactory::print_contents() {
0N/A print();
0N/A tty->cr();
0N/A GUARDED_VM_ENTRY(print_contents_impl();)
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObjectFactory::print
0N/A//
0N/A// Print debugging information about the object factory
0N/Avoid ciObjectFactory::print() {
0N/A tty->print("<ciObjectFactory oops=%d unloaded_methods=%d unloaded_klasses=%d>",
0N/A _ci_objects->length(), _unloaded_methods->length(),
0N/A _unloaded_klasses->length());
0N/A}