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