aoqi@0: /* aoqi@0: * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef SHARE_VM_CI_CIOBJECTFACTORY_HPP aoqi@0: #define SHARE_VM_CI_CIOBJECTFACTORY_HPP aoqi@0: aoqi@0: #include "ci/ciClassList.hpp" aoqi@0: #include "ci/ciObject.hpp" aoqi@0: #include "utilities/growableArray.hpp" aoqi@0: aoqi@0: // ciObjectFactory aoqi@0: // aoqi@0: // This class handles requests for the creation of new instances aoqi@0: // of ciObject and its subclasses. It contains a caching mechanism aoqi@0: // which ensures that for each oop, at most one ciObject is created. aoqi@0: // This invariant allows efficient implementation of ciObject. aoqi@0: class ciObjectFactory : public ResourceObj { aoqi@0: friend class VMStructs; aoqi@0: friend class ciEnv; aoqi@0: aoqi@0: private: aoqi@0: static volatile bool _initialized; aoqi@0: static GrowableArray* _shared_ci_metadata; aoqi@0: static ciSymbol* _shared_ci_symbols[]; aoqi@0: static int _shared_ident_limit; aoqi@0: aoqi@0: Arena* _arena; aoqi@0: GrowableArray* _ci_metadata; aoqi@0: GrowableArray* _unloaded_methods; aoqi@0: GrowableArray* _unloaded_klasses; aoqi@0: GrowableArray* _unloaded_instances; aoqi@0: GrowableArray* _return_addresses; aoqi@0: GrowableArray* _symbols; // keep list of symbols created aoqi@0: int _next_ident; aoqi@0: aoqi@0: public: aoqi@0: struct NonPermObject : public ResourceObj { aoqi@0: ciObject* _object; aoqi@0: NonPermObject* _next; aoqi@0: aoqi@0: inline NonPermObject(NonPermObject* &bucket, oop key, ciObject* object); aoqi@0: ciObject* object() { return _object; } aoqi@0: NonPermObject* &next() { return _next; } aoqi@0: }; aoqi@0: private: aoqi@0: enum { NON_PERM_BUCKETS = 61 }; aoqi@0: NonPermObject* _non_perm_bucket[NON_PERM_BUCKETS]; aoqi@0: int _non_perm_count; aoqi@0: aoqi@0: int find(Metadata* key, GrowableArray* objects); aoqi@0: bool is_found_at(int index, Metadata* key, GrowableArray* objects); aoqi@0: void insert(int index, ciMetadata* obj, GrowableArray* objects); aoqi@0: aoqi@0: ciObject* create_new_object(oop o); aoqi@0: ciMetadata* create_new_object(Metadata* o); aoqi@0: aoqi@0: static bool is_equal(NonPermObject* p, oop key) { aoqi@0: return p->object()->get_oop() == key; aoqi@0: } aoqi@0: aoqi@0: NonPermObject* &find_non_perm(oop key); aoqi@0: void insert_non_perm(NonPermObject* &where, oop key, ciObject* obj); aoqi@0: aoqi@0: void init_ident_of(ciBaseObject* obj); aoqi@0: aoqi@0: Arena* arena() { return _arena; } aoqi@0: aoqi@0: void print_contents_impl(); aoqi@0: aoqi@0: ciInstance* get_unloaded_instance(ciInstanceKlass* klass); aoqi@0: aoqi@0: public: aoqi@0: static bool is_initialized() { return _initialized; } aoqi@0: aoqi@0: static void initialize(); aoqi@0: void init_shared_objects(); aoqi@0: void remove_symbols(); aoqi@0: aoqi@0: ciObjectFactory(Arena* arena, int expected_size); aoqi@0: aoqi@0: // Get the ciObject corresponding to some oop. aoqi@0: ciObject* get(oop key); aoqi@0: ciMetadata* get_metadata(Metadata* key); aoqi@0: ciSymbol* get_symbol(Symbol* key); aoqi@0: aoqi@0: // Get the ciSymbol corresponding to one of the vmSymbols. aoqi@0: static ciSymbol* vm_symbol_at(int index); aoqi@0: aoqi@0: // Get the ciMethod representing an unloaded/unfound method. aoqi@0: ciMethod* get_unloaded_method(ciInstanceKlass* holder, aoqi@0: ciSymbol* name, aoqi@0: ciSymbol* signature, aoqi@0: ciInstanceKlass* accessor); aoqi@0: aoqi@0: // Get a ciKlass representing an unloaded klass. aoqi@0: ciKlass* get_unloaded_klass(ciKlass* accessing_klass, aoqi@0: ciSymbol* name, aoqi@0: bool create_if_not_found); aoqi@0: aoqi@0: // Get a ciInstance representing an unresolved klass mirror. aoqi@0: ciInstance* get_unloaded_klass_mirror(ciKlass* type); aoqi@0: aoqi@0: // Get a ciInstance representing an unresolved method handle constant. aoqi@0: ciInstance* get_unloaded_method_handle_constant(ciKlass* holder, aoqi@0: ciSymbol* name, aoqi@0: ciSymbol* signature, aoqi@0: int ref_kind); aoqi@0: aoqi@0: // Get a ciInstance representing an unresolved method type constant. aoqi@0: ciInstance* get_unloaded_method_type_constant(ciSymbol* signature); aoqi@0: aoqi@0: aoqi@0: ciInstance* get_unloaded_object_constant(); aoqi@0: aoqi@0: // Get the ciMethodData representing the methodData for a method aoqi@0: // with none. aoqi@0: ciMethodData* get_empty_methodData(); aoqi@0: aoqi@0: ciReturnAddress* get_return_address(int bci); aoqi@0: aoqi@0: GrowableArray* get_ci_metadata() const { return _ci_metadata; } aoqi@0: // RedefineClasses support aoqi@0: void metadata_do(void f(Metadata*)); aoqi@0: aoqi@0: void print_contents(); aoqi@0: void print(); aoqi@0: }; aoqi@0: aoqi@0: #endif // SHARE_VM_CI_CIOBJECTFACTORY_HPP