ciObjectFactory.cpp revision 1879
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "ci/ciCPCache.hpp"
#include "ci/ciCallSite.hpp"
#include "ci/ciInstance.hpp"
#include "ci/ciInstanceKlass.hpp"
#include "ci/ciInstanceKlassKlass.hpp"
#include "ci/ciMethod.hpp"
#include "ci/ciMethodData.hpp"
#include "ci/ciMethodHandle.hpp"
#include "ci/ciMethodKlass.hpp"
#include "ci/ciNullObject.hpp"
#include "ci/ciObjArray.hpp"
#include "ci/ciObjArrayKlass.hpp"
#include "ci/ciObjArrayKlassKlass.hpp"
#include "ci/ciObjectFactory.hpp"
#include "ci/ciSymbol.hpp"
#include "ci/ciSymbolKlass.hpp"
#include "ci/ciTypeArray.hpp"
#include "ci/ciTypeArrayKlass.hpp"
#include "ci/ciTypeArrayKlassKlass.hpp"
#include "ci/ciUtilities.hpp"
#include "classfile/systemDictionary.hpp"
#include "gc_interface/collectedHeap.inline.hpp"
#include "memory/allocation.inline.hpp"
#include "oops/oop.inline.hpp"
#include "oops/oop.inline2.hpp"
#include "runtime/fieldType.hpp"
// ciObjectFactory
//
// This class handles requests for the creation of new instances
// of ciObject and its subclasses. It contains a caching mechanism
// which ensures that for each oop, at most one ciObject is created.
// This invariant allows more efficient implementation of ciObject.
//
// Implementation note: the oop->ciObject mapping is represented as
// a table stored in an array. Even though objects are moved
// by the garbage collector, the compactor preserves their relative
// order; address comparison of oops (in perm space) is safe so long
// as we prohibit GC during our comparisons. We currently use binary
// search to find the oop in the table, and inserting a new oop
// into the table may be costly. If this cost ends up being
// problematic the underlying data structure can be switched to some
// sort of balanced binary tree.
int ciObjectFactory::_shared_ident_limit = 0;
volatile bool ciObjectFactory::_initialized = false;
// ------------------------------------------------------------------
// ciObjectFactory::ciObjectFactory
int expected_size) {
for (int i = 0; i < NON_PERM_BUCKETS; i++) {
_non_perm_bucket[i] = NULL;
}
_non_perm_count = 0;
// If the shared ci objects exist append them to this factory's objects
if (_shared_ci_objects != NULL) {
}
}
// ------------------------------------------------------------------
// ciObjectFactory::ciObjectFactory
void ciObjectFactory::initialize() {
// This Arena is long lived and exists in the resource mark of the
// compiler thread that initializes the initial ciObjectFactory which
// creates the shared ciObjects that all later ciObjectFactories use.
_initialized = true;
}
void ciObjectFactory::init_shared_objects() {
{
// Create the shared symbols, but not in _shared_ci_objects.
int i;
_shared_ci_symbols[i] = sym;
}
#ifdef ASSERT
}
assert(ciSymbol::void_class_signature()->get_oop() == vmSymbols::void_class_signature(), "spot check");
#endif
}
for (int i = T_BOOLEAN; i <= T_CONFLICT; i++) {
}
}
}
}
}
// Create dummy instanceKlass and objArrayKlass object and assign them idents
ciEnv::_unloaded_ciinstance_klass = new (_arena) ciInstanceKlass(ciEnv::_unloaded_cisymbol, NULL, NULL);
ciEnv::_unloaded_ciobjarrayklass = new (_arena) ciObjArrayKlass(ciEnv::_unloaded_cisymbol, ciEnv::_unloaded_ciinstance_klass, 1);
// The shared_ident_limit is the first ident number that will
// be used for non-shared objects. That is, numbers less than
// this limit are permanently assigned to shared CI objects,
// while the higher numbers are recycled afresh by each new ciEnv.
}
// ------------------------------------------------------------------
// 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.
#ifdef ASSERT
if (CIObjectFactoryVerify) {
for (int j = 0; j< _ci_objects->length(); j++) {
last = o;
}
}
#endif // ASSERT
#ifdef ASSERT
if (CIObjectFactoryVerify) {
for (int i=0; i<_ci_objects->length(); i++) {
}
}
}
#endif
// Check in the non-perm area before putting it in the list.
}
// Check in the shared symbol area before putting it in the list.
// do not pollute the main cache with it
return vm_symbol_at(sid);
}
}
// The ciObject does not yet exist. Create it and insert it
// into the cache.
if (!new_object->is_perm()) {
// Not a perm-space object.
return new_object;
}
// creating the new object has recursively entered new objects
// into the table. We need to recompute our index.
}
return new_object;
}
}
// ------------------------------------------------------------------
// 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.
if (o->is_symbol()) {
} else if (o->is_klass()) {
if (k->oop_is_instance()) {
} else if (k->oop_is_objArray()) {
} else if (k->oop_is_typeArray()) {
} else if (k->oop_is_method()) {
} else if (k->oop_is_symbol()) {
} else if (k->oop_is_klass()) {
if (k->oop_is_objArrayKlass()) {
} else if (k->oop_is_typeArrayKlass()) {
} else if (k->oop_is_instanceKlass()) {
} else {
}
}
} else if (o->is_method()) {
} else if (o->is_methodData()) {
} else if (o->is_instance()) {
if (java_dyn_CallSite::is_instance(o))
else if (java_dyn_MethodHandle::is_instance(o))
else
} else if (o->is_objArray()) {
} else if (o->is_typeArray()) {
} else if (o->is_constantPoolCache()) {
}
// The oop is of some type not supported by the compiler interface.
return NULL;
}
//------------------------------------------------------------------
// ciObjectFactory::get_unloaded_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.
for (int i=0; i<_unloaded_methods->length(); i++) {
// We've found a match.
return entry;
}
}
// This is a new unloaded method. Create it and stick it in
// the cache.
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.
bool create_if_not_found) {
if (accessing_klass != NULL) {
}
for (int i=0; i<_unloaded_klasses->length(); i++) {
// 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.
// Two cases: this is an unloaded objArrayKlass or an
// unloaded instanceKlass. Deal with both.
// Decompose the name.'
THREAD);
if (HAS_PENDING_EXCEPTION) {
return ciEnv::_unloaded_ciobjarrayklass;
}
if (element_type == T_OBJECT) {
} else {
// The type array itself takes care of one of the dimensions.
dimension--;
// The element klass is a typeArrayKlass.
}
} else {
if (accessing_klass != NULL) {
}
}
return new_klass;
}
//------------------------------------------------------------------
// ciObjectFactory::get_unloaded_instance
//
// Get a ciInstance representing an as-yet undetermined instance of a given class.
//
for (int i=0; i<_unloaded_instances->length(); i++) {
// We've found a match.
return entry;
}
}
// This is a new unloaded instance. Create it and stick it in
// the cache.
// make sure it looks the way we want:
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.
}
//------------------------------------------------------------------
// 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.
int ref_kind) {
}
//------------------------------------------------------------------
// 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.
}
//------------------------------------------------------------------
// ciObjectFactory::get_empty_methodData
//
// Get the ciMethodData representing the methodData for a method with
// none.
return new_methodData;
}
//------------------------------------------------------------------
// ciObjectFactory::get_return_address
//
// Get a ciReturnAddress for a specified bci.
for (int i=0; i<_return_addresses->length(); i++) {
// We've found a match.
return entry;
}
}
return new_ret_addr;
}
// ------------------------------------------------------------------
// ciObjectFactory::init_ident_of
}
// ------------------------------------------------------------------
// 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 min = 0;
// print_contents();
} else {
return mid;
}
}
return min;
}
// ------------------------------------------------------------------
// ciObjectFactory::is_found_at
//
// Verify that the binary seach found the given key.
}
// ------------------------------------------------------------------
// ciObjectFactory::insert
//
// Insert a ciObject into the table at some index.
} else {
int pos;
}
}
#ifdef ASSERT
if (CIObjectFactoryVerify) {
last = o;
}
}
#endif // ASSERT
}
// ------------------------------------------------------------------
// 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.
// 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.
return emptyBucket;
} else if (key->is_instance()) {
// class mirror instances are always perm
return emptyBucket;
}
// fall through to probe
// fall through to probe
} else {
// not an array or instance
return emptyBucket;
}
}
return (*bp);
}
// ------------------------------------------------------------------
// Code for for NonPermObject
//
inline ciObjectFactory::NonPermObject::NonPermObject(ciObjectFactory::NonPermObject* &bucket, oop key, ciObject* object) {
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) {
}
// ------------------------------------------------------------------
// ciObjectFactory::vm_symbol_at
// Get the ciSymbol corresponding to some index in vmSymbols.
return _shared_ci_symbols[index];
}
// ------------------------------------------------------------------
// ciObjectFactory::print_contents_impl
void ciObjectFactory::print_contents_impl() {
for (int i=0; i<len; i++) {
}
}
// ------------------------------------------------------------------
// ciObjectFactory::print_contents
void ciObjectFactory::print_contents() {
print();
}
// ------------------------------------------------------------------
// 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>",
_unloaded_klasses->length());
}