ciObjectFactory.hpp revision 5776:de6a9e811145
155714Skris/*
255714Skris * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
355714Skris * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
455714Skris *
555714Skris * This code is free software; you can redistribute it and/or modify it
655714Skris * under the terms of the GNU General Public License version 2 only, as
755714Skris * published by the Free Software Foundation.
855714Skris *
955714Skris * This code is distributed in the hope that it will be useful, but WITHOUT
1055714Skris * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1155714Skris * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1255714Skris * version 2 for more details (a copy is included in the LICENSE file that
1355714Skris * accompanied this code).
1455714Skris *
1555714Skris * You should have received a copy of the GNU General Public License version
1655714Skris * 2 along with this work; if not, write to the Free Software Foundation,
1755714Skris * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1855714Skris *
1955714Skris * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2055714Skris * or visit www.oracle.com if you need additional information or have any
2155714Skris * questions.
2255714Skris *
2355714Skris */
2455714Skris
2555714Skris#ifndef SHARE_VM_CI_CIOBJECTFACTORY_HPP
2655714Skris#define SHARE_VM_CI_CIOBJECTFACTORY_HPP
2755714Skris
2855714Skris#include "ci/ciClassList.hpp"
2955714Skris#include "ci/ciObject.hpp"
3055714Skris#include "utilities/growableArray.hpp"
3155714Skris
3255714Skris// ciObjectFactory
3355714Skris//
3455714Skris// This class handles requests for the creation of new instances
3555714Skris// of ciObject and its subclasses.  It contains a caching mechanism
3655714Skris// which ensures that for each oop, at most one ciObject is created.
3755714Skris// This invariant allows efficient implementation of ciObject.
3855714Skrisclass ciObjectFactory : public ResourceObj {
3955714Skris  friend class VMStructs;
4055714Skris  friend class ciEnv;
4155714Skris
4255714Skrisprivate:
4355714Skris  static volatile bool _initialized;
4455714Skris  static GrowableArray<ciMetadata*>* _shared_ci_metadata;
4555714Skris  static ciSymbol*                 _shared_ci_symbols[];
4655714Skris  static int                       _shared_ident_limit;
47
48  Arena*                    _arena;
49  GrowableArray<ciMetadata*>*        _ci_metadata;
50  GrowableArray<ciMethod*>* _unloaded_methods;
51  GrowableArray<ciKlass*>* _unloaded_klasses;
52  GrowableArray<ciInstance*>* _unloaded_instances;
53  GrowableArray<ciReturnAddress*>* _return_addresses;
54  GrowableArray<ciSymbol*>* _symbols;  // keep list of symbols created
55  int                       _next_ident;
56
57public:
58  struct NonPermObject : public ResourceObj {
59    ciObject*      _object;
60    NonPermObject* _next;
61
62    inline NonPermObject(NonPermObject* &bucket, oop key, ciObject* object);
63    ciObject*     object()  { return _object; }
64    NonPermObject* &next()  { return _next; }
65  };
66private:
67  enum { NON_PERM_BUCKETS = 61 };
68  NonPermObject* _non_perm_bucket[NON_PERM_BUCKETS];
69  int _non_perm_count;
70
71  int find(Metadata* key, GrowableArray<ciMetadata*>* objects);
72  bool is_found_at(int index, Metadata* key, GrowableArray<ciMetadata*>* objects);
73  void insert(int index, ciMetadata* obj, GrowableArray<ciMetadata*>* objects);
74
75  ciObject* create_new_object(oop o);
76  ciMetadata* create_new_object(Metadata* o);
77
78  static bool is_equal(NonPermObject* p, oop key) {
79    return p->object()->get_oop() == key;
80  }
81
82  NonPermObject* &find_non_perm(oop key);
83  void insert_non_perm(NonPermObject* &where, oop key, ciObject* obj);
84
85  void init_ident_of(ciBaseObject* obj);
86
87  Arena* arena() { return _arena; }
88
89  void print_contents_impl();
90
91  ciInstance* get_unloaded_instance(ciInstanceKlass* klass);
92
93public:
94  static bool is_initialized() { return _initialized; }
95
96  static void initialize();
97  void init_shared_objects();
98  void remove_symbols();
99
100  ciObjectFactory(Arena* arena, int expected_size);
101
102  // Get the ciObject corresponding to some oop.
103  ciObject* get(oop key);
104  ciMetadata* get_metadata(Metadata* key);
105  ciSymbol* get_symbol(Symbol* key);
106
107  // Get the ciSymbol corresponding to one of the vmSymbols.
108  static ciSymbol* vm_symbol_at(int index);
109
110  // Get the ciMethod representing an unloaded/unfound method.
111  ciMethod* get_unloaded_method(ciInstanceKlass* holder,
112                                ciSymbol*        name,
113                                ciSymbol*        signature,
114                                ciInstanceKlass* accessor);
115
116  // Get a ciKlass representing an unloaded klass.
117  ciKlass* get_unloaded_klass(ciKlass* accessing_klass,
118                              ciSymbol* name,
119                              bool create_if_not_found);
120
121  // Get a ciInstance representing an unresolved klass mirror.
122  ciInstance* get_unloaded_klass_mirror(ciKlass* type);
123
124  // Get a ciInstance representing an unresolved method handle constant.
125  ciInstance* get_unloaded_method_handle_constant(ciKlass*  holder,
126                                                  ciSymbol* name,
127                                                  ciSymbol* signature,
128                                                  int       ref_kind);
129
130  // Get a ciInstance representing an unresolved method type constant.
131  ciInstance* get_unloaded_method_type_constant(ciSymbol* signature);
132
133
134  ciInstance* get_unloaded_object_constant();
135
136  // Get the ciMethodData representing the methodData for a method
137  // with none.
138  ciMethodData* get_empty_methodData();
139
140  ciReturnAddress* get_return_address(int bci);
141
142  GrowableArray<ciMetadata*>* get_ci_metadata() const { return _ci_metadata; }
143  // RedefineClasses support
144  void metadata_do(void f(Metadata*));
145
146  void print_contents();
147  void print();
148};
149
150#endif // SHARE_VM_CI_CIOBJECTFACTORY_HPP
151