annotate src/share/vm/runtime/handles.hpp @ 10246:194f52aa2f23

7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap Summary: Refactor G1's hot card cache and card counts table into their own files. Simplify the card counts table, including removing the encoding of the card index in each entry. The card counts table now has a 1:1 correspondence with the cards spanned by heap. Space for the card counts table is reserved from virtual memory (rather than C heap) during JVM startup and is committed/expanded when the heap is expanded. Changes were also reviewed-by Vitaly Davidovich. Reviewed-by: tschatzl, jmasa
author johnc
date Thu, 09 May 2013 11:16:39 -0700
parents 5a9fa2ba85f0
children f9be75d21404
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
10135
5a9fa2ba85f0 8012907: anti-delta fix for 8010992
dcubed
parents: 10130
diff changeset
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 665
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 665
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 665
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #ifndef SHARE_VM_RUNTIME_HANDLES_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #define SHARE_VM_RUNTIME_HANDLES_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "oops/klass.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29
0
a61af66fc99e Initial load
duke
parents:
diff changeset
30 //------------------------------------------------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // In order to preserve oops during garbage collection, they should be
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // allocated and passed around via Handles within the VM. A handle is
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // simply an extra indirection allocated in a thread local handle area.
a61af66fc99e Initial load
duke
parents:
diff changeset
34 //
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // A handle is a ValueObj, so it can be passed around as a value, can
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // be used as a parameter w/o using &-passing, and can be returned as a
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // return value.
a61af66fc99e Initial load
duke
parents:
diff changeset
38 //
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // oop parameters and return types should be Handles whenever feasible.
a61af66fc99e Initial load
duke
parents:
diff changeset
40 //
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // Handles are declared in a straight-forward manner, e.g.
a61af66fc99e Initial load
duke
parents:
diff changeset
42 //
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // oop obj = ...;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // Handle h1(obj); // allocate new handle
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // Handle h2(thread, obj); // faster allocation when current thread is known
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // Handle h3; // declare handle only, no allocation occurs
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // ...
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // h3 = h1; // make h3 refer to same indirection as h1
a61af66fc99e Initial load
duke
parents:
diff changeset
49 // oop obj2 = h2(); // get handle value
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // h1->print(); // invoking operation on oop
a61af66fc99e Initial load
duke
parents:
diff changeset
51 //
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // Handles are specialized for different oop types to provide extra type
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // information and avoid unnecessary casting. For each oop type xxxOop
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // there is a corresponding handle called xxxHandle, e.g.
a61af66fc99e Initial load
duke
parents:
diff changeset
55 //
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // oop Handle
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
57 // Method* methodHandle
0
a61af66fc99e Initial load
duke
parents:
diff changeset
58 // instanceOop instanceHandle
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 //------------------------------------------------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
61 // Base class for all handles. Provides overloading of frequently
a61af66fc99e Initial load
duke
parents:
diff changeset
62 // used operators for ease of use.
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 class Handle VALUE_OBJ_CLASS_SPEC {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
66 oop* _handle;
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
69 oop obj() const { return _handle == NULL ? (oop)NULL : *_handle; }
a61af66fc99e Initial load
duke
parents:
diff changeset
70 oop non_null_obj() const { assert(_handle != NULL, "resolving NULL handle"); return *_handle; }
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
73 // Constructors
a61af66fc99e Initial load
duke
parents:
diff changeset
74 Handle() { _handle = NULL; }
a61af66fc99e Initial load
duke
parents:
diff changeset
75 Handle(oop obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
76 Handle(Thread* thread, oop obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // General access
a61af66fc99e Initial load
duke
parents:
diff changeset
79 oop operator () () const { return obj(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
80 oop operator -> () const { return non_null_obj(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
81 bool operator == (oop o) const { return obj() == o; }
a61af66fc99e Initial load
duke
parents:
diff changeset
82 bool operator == (const Handle& h) const { return obj() == h.obj(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // Null checks
a61af66fc99e Initial load
duke
parents:
diff changeset
85 bool is_null() const { return _handle == NULL; }
a61af66fc99e Initial load
duke
parents:
diff changeset
86 bool not_null() const { return _handle != NULL; }
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // Debugging
a61af66fc99e Initial load
duke
parents:
diff changeset
89 void print() { obj()->print(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 // Direct interface, use very sparingly.
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // Used by JavaCalls to quickly convert handles and to create handles static data structures.
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // Constructor takes a dummy argument to prevent unintentional type conversion in C++.
a61af66fc99e Initial load
duke
parents:
diff changeset
94 Handle(oop *handle, bool dummy) { _handle = handle; }
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // Raw handle access. Allows easy duplication of Handles. This can be very unsafe
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // since duplicates is only valid as long as original handle is alive.
a61af66fc99e Initial load
duke
parents:
diff changeset
98 oop* raw_value() { return _handle; }
a61af66fc99e Initial load
duke
parents:
diff changeset
99 static oop raw_resolve(oop *handle) { return handle == NULL ? (oop)NULL : *handle; }
a61af66fc99e Initial load
duke
parents:
diff changeset
100 };
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102 // Specific Handles for different oop types
a61af66fc99e Initial load
duke
parents:
diff changeset
103 #define DEF_HANDLE(type, is_a) \
a61af66fc99e Initial load
duke
parents:
diff changeset
104 class type##Handle: public Handle { \
a61af66fc99e Initial load
duke
parents:
diff changeset
105 protected: \
a61af66fc99e Initial load
duke
parents:
diff changeset
106 type##Oop obj() const { return (type##Oop)Handle::obj(); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
107 type##Oop non_null_obj() const { return (type##Oop)Handle::non_null_obj(); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
108 \
a61af66fc99e Initial load
duke
parents:
diff changeset
109 public: \
a61af66fc99e Initial load
duke
parents:
diff changeset
110 /* Constructors */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
111 type##Handle () : Handle() {} \
a61af66fc99e Initial load
duke
parents:
diff changeset
112 type##Handle (type##Oop obj) : Handle((oop)obj) { \
6867
bdb5f8c9978b 7199068: NPG: SharedSkipVerify is meaningless
coleenp
parents: 6725
diff changeset
113 assert(is_null() || ((oop)obj)->is_a(), \
0
a61af66fc99e Initial load
duke
parents:
diff changeset
114 "illegal type"); \
a61af66fc99e Initial load
duke
parents:
diff changeset
115 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
116 type##Handle (Thread* thread, type##Oop obj) : Handle(thread, (oop)obj) { \
6867
bdb5f8c9978b 7199068: NPG: SharedSkipVerify is meaningless
coleenp
parents: 6725
diff changeset
117 assert(is_null() || ((oop)obj)->is_a(), "illegal type"); \
0
a61af66fc99e Initial load
duke
parents:
diff changeset
118 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
119 \
a61af66fc99e Initial load
duke
parents:
diff changeset
120 /* Operators for ease of use */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
121 type##Oop operator () () const { return obj(); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
122 type##Oop operator -> () const { return non_null_obj(); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
123 };
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 DEF_HANDLE(instance , is_instance )
a61af66fc99e Initial load
duke
parents:
diff changeset
127 DEF_HANDLE(array , is_array )
a61af66fc99e Initial load
duke
parents:
diff changeset
128 DEF_HANDLE(objArray , is_objArray )
a61af66fc99e Initial load
duke
parents:
diff changeset
129 DEF_HANDLE(typeArray , is_typeArray )
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 //------------------------------------------------------------------------------------------------------------------------
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
132
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
133 // Metadata Handles. Unlike oop Handles these are needed to prevent metadata
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
134 // from being reclaimed by RedefineClasses.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
135
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
136 // Specific Handles for different oop types
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
137 #define DEF_METADATA_HANDLE(name, type) \
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
138 class name##Handle; \
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
139 class name##Handle { \
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
140 type* _value; \
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
141 Thread* _thread; \
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
142 protected: \
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
143 type* obj() const { return _value; } \
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
144 type* non_null_obj() const { assert(_value != NULL, "resolving NULL _value"); return _value; } \
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
145 \
0
a61af66fc99e Initial load
duke
parents:
diff changeset
146 public: \
a61af66fc99e Initial load
duke
parents:
diff changeset
147 /* Constructors */ \
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
148 name##Handle () : _value(NULL), _thread(NULL) {} \
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
149 name##Handle (type* obj); \
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
150 name##Handle (Thread* thread, type* obj); \
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
151 \
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
152 name##Handle (const name##Handle &h); \
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
153 name##Handle& operator=(const name##Handle &s); \
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
154 \
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
155 /* Destructor */ \
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
156 ~name##Handle (); \
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
157 void remove(); \
0
a61af66fc99e Initial load
duke
parents:
diff changeset
158 \
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
159 /* Operators for ease of use */ \
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
160 type* operator () () const { return obj(); } \
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
161 type* operator -> () const { return non_null_obj(); } \
0
a61af66fc99e Initial load
duke
parents:
diff changeset
162 \
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
163 bool operator == (type* o) const { return obj() == o; } \
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
164 bool operator == (const name##Handle& h) const { return obj() == h.obj(); } \
0
a61af66fc99e Initial load
duke
parents:
diff changeset
165 \
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
166 /* Null checks */ \
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
167 bool is_null() const { return _value == NULL; } \
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
168 bool not_null() const { return _value != NULL; } \
0
a61af66fc99e Initial load
duke
parents:
diff changeset
169 };
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
172 DEF_METADATA_HANDLE(method, Method)
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
173 DEF_METADATA_HANDLE(constantPool, ConstantPool)
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
174
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
175 // Writing this class explicitly, since DEF_METADATA_HANDLE(klass) doesn't
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
176 // provide the necessary Klass* <-> Klass* conversions. This Klass
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
177 // could be removed when we don't have the Klass* typedef anymore.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
178 class KlassHandle {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
179 Klass* _value;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
180 protected:
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
181 Klass* obj() const { return _value; }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
182 Klass* non_null_obj() const { assert(_value != NULL, "resolving NULL _value"); return _value; }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
183
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
184 public:
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
185 KlassHandle() : _value(NULL) {}
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
186 KlassHandle(const Klass* obj) : _value(const_cast<Klass *>(obj)) {};
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
187 KlassHandle(Thread* thread, const Klass* obj) : _value(const_cast<Klass *>(obj)) {};
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
188
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
189 Klass* operator () () const { return obj(); }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
190 Klass* operator -> () const { return non_null_obj(); }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
191
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
192 bool operator == (Klass* o) const { return obj() == o; }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
193 bool operator == (const KlassHandle& h) const { return obj() == h.obj(); }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
194
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
195 bool is_null() const { return _value == NULL; }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
196 bool not_null() const { return _value != NULL; }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
197 };
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
198
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
199 class instanceKlassHandle : public KlassHandle {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
200 public:
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
201 /* Constructors */
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
202 instanceKlassHandle () : KlassHandle() {}
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
203 instanceKlassHandle (const Klass* k) : KlassHandle(k) {
6867
bdb5f8c9978b 7199068: NPG: SharedSkipVerify is meaningless
coleenp
parents: 6725
diff changeset
204 assert(k == NULL || k->oop_is_instance(),
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
205 "illegal type");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
206 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
207 instanceKlassHandle (Thread* thread, const Klass* k) : KlassHandle(thread, k) {
6867
bdb5f8c9978b 7199068: NPG: SharedSkipVerify is meaningless
coleenp
parents: 6725
diff changeset
208 assert(k == NULL || k->oop_is_instance(),
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
209 "illegal type");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
210 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
211 /* Access to klass part */
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
212 InstanceKlass* operator () () const { return (InstanceKlass*)obj(); }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
213 InstanceKlass* operator -> () const { return (InstanceKlass*)obj(); }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
214 };
0
a61af66fc99e Initial load
duke
parents:
diff changeset
215
a61af66fc99e Initial load
duke
parents:
diff changeset
216
a61af66fc99e Initial load
duke
parents:
diff changeset
217 //------------------------------------------------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
218 // Thread local handle area
a61af66fc99e Initial load
duke
parents:
diff changeset
219 class HandleArea: public Arena {
a61af66fc99e Initial load
duke
parents:
diff changeset
220 friend class HandleMark;
a61af66fc99e Initial load
duke
parents:
diff changeset
221 friend class NoHandleMark;
a61af66fc99e Initial load
duke
parents:
diff changeset
222 friend class ResetNoHandleMark;
a61af66fc99e Initial load
duke
parents:
diff changeset
223 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
224 int _handle_mark_nesting;
a61af66fc99e Initial load
duke
parents:
diff changeset
225 int _no_handle_mark_nesting;
a61af66fc99e Initial load
duke
parents:
diff changeset
226 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
227 HandleArea* _prev; // link to outer (older) area
a61af66fc99e Initial load
duke
parents:
diff changeset
228 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
229 // Constructor
a61af66fc99e Initial load
duke
parents:
diff changeset
230 HandleArea(HandleArea* prev) {
a61af66fc99e Initial load
duke
parents:
diff changeset
231 debug_only(_handle_mark_nesting = 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
232 debug_only(_no_handle_mark_nesting = 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
233 _prev = prev;
a61af66fc99e Initial load
duke
parents:
diff changeset
234 }
a61af66fc99e Initial load
duke
parents:
diff changeset
235
a61af66fc99e Initial load
duke
parents:
diff changeset
236 // Handle allocation
a61af66fc99e Initial load
duke
parents:
diff changeset
237 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
238 oop* real_allocate_handle(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
239 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
240 oop* handle = (oop*) (UseMallocOnly ? internal_malloc_4(oopSize) : Amalloc_4(oopSize));
a61af66fc99e Initial load
duke
parents:
diff changeset
241 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
242 oop* handle = (oop*) Amalloc_4(oopSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
243 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
244 *handle = obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
245 return handle;
a61af66fc99e Initial load
duke
parents:
diff changeset
246 }
a61af66fc99e Initial load
duke
parents:
diff changeset
247 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
248 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
249 oop* allocate_handle(oop obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
250 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
251 oop* allocate_handle(oop obj) { return real_allocate_handle(obj); }
a61af66fc99e Initial load
duke
parents:
diff changeset
252 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
253
a61af66fc99e Initial load
duke
parents:
diff changeset
254 // Garbage collection support
a61af66fc99e Initial load
duke
parents:
diff changeset
255 void oops_do(OopClosure* f);
a61af66fc99e Initial load
duke
parents:
diff changeset
256
a61af66fc99e Initial load
duke
parents:
diff changeset
257 // Number of handles in use
a61af66fc99e Initial load
duke
parents:
diff changeset
258 size_t used() const { return Arena::used() / oopSize; }
a61af66fc99e Initial load
duke
parents:
diff changeset
259
a61af66fc99e Initial load
duke
parents:
diff changeset
260 debug_only(bool no_handle_mark_active() { return _no_handle_mark_nesting > 0; })
a61af66fc99e Initial load
duke
parents:
diff changeset
261 };
a61af66fc99e Initial load
duke
parents:
diff changeset
262
a61af66fc99e Initial load
duke
parents:
diff changeset
263
a61af66fc99e Initial load
duke
parents:
diff changeset
264 //------------------------------------------------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
265 // Handles are allocated in a (growable) thread local handle area. Deallocation
a61af66fc99e Initial load
duke
parents:
diff changeset
266 // is managed using a HandleMark. It should normally not be necessary to use
a61af66fc99e Initial load
duke
parents:
diff changeset
267 // HandleMarks manually.
a61af66fc99e Initial load
duke
parents:
diff changeset
268 //
a61af66fc99e Initial load
duke
parents:
diff changeset
269 // A HandleMark constructor will record the current handle area top, and the
a61af66fc99e Initial load
duke
parents:
diff changeset
270 // desctructor will reset the top, destroying all handles allocated in between.
a61af66fc99e Initial load
duke
parents:
diff changeset
271 // The following code will therefore NOT work:
a61af66fc99e Initial load
duke
parents:
diff changeset
272 //
a61af66fc99e Initial load
duke
parents:
diff changeset
273 // Handle h;
a61af66fc99e Initial load
duke
parents:
diff changeset
274 // {
a61af66fc99e Initial load
duke
parents:
diff changeset
275 // HandleMark hm;
a61af66fc99e Initial load
duke
parents:
diff changeset
276 // h = Handle(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
277 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
278 // h()->print(); // WRONG, h destroyed by HandleMark destructor.
a61af66fc99e Initial load
duke
parents:
diff changeset
279 //
a61af66fc99e Initial load
duke
parents:
diff changeset
280 // If h has to be preserved, it can be converted to an oop or a local JNI handle
a61af66fc99e Initial load
duke
parents:
diff changeset
281 // across the HandleMark boundary.
a61af66fc99e Initial load
duke
parents:
diff changeset
282
10135
5a9fa2ba85f0 8012907: anti-delta fix for 8010992
dcubed
parents: 10130
diff changeset
283 // The base class of HandleMark should have been StackObj but we also heap allocate
5a9fa2ba85f0 8012907: anti-delta fix for 8010992
dcubed
parents: 10130
diff changeset
284 // a HandleMark when a thread is created.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
285
10135
5a9fa2ba85f0 8012907: anti-delta fix for 8010992
dcubed
parents: 10130
diff changeset
286 class HandleMark {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
287 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
288 Thread *_thread; // thread that owns this mark
a61af66fc99e Initial load
duke
parents:
diff changeset
289 HandleArea *_area; // saved handle area
a61af66fc99e Initial load
duke
parents:
diff changeset
290 Chunk *_chunk; // saved arena chunk
a61af66fc99e Initial load
duke
parents:
diff changeset
291 char *_hwm, *_max; // saved arena info
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 2426
diff changeset
292 size_t _size_in_bytes; // size of handle area
0
a61af66fc99e Initial load
duke
parents:
diff changeset
293 // Link to previous active HandleMark in thread
a61af66fc99e Initial load
duke
parents:
diff changeset
294 HandleMark* _previous_handle_mark;
a61af66fc99e Initial load
duke
parents:
diff changeset
295
10135
5a9fa2ba85f0 8012907: anti-delta fix for 8010992
dcubed
parents: 10130
diff changeset
296 void initialize(Thread* thread); // common code for constructors
0
a61af66fc99e Initial load
duke
parents:
diff changeset
297 void set_previous_handle_mark(HandleMark* mark) { _previous_handle_mark = mark; }
a61af66fc99e Initial load
duke
parents:
diff changeset
298 HandleMark* previous_handle_mark() const { return _previous_handle_mark; }
a61af66fc99e Initial load
duke
parents:
diff changeset
299
6882
716c64bda5ba 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 6867
diff changeset
300 size_t size_in_bytes() const { return _size_in_bytes; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
301 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
302 HandleMark(); // see handles_inline.hpp
a61af66fc99e Initial load
duke
parents:
diff changeset
303 HandleMark(Thread* thread) { initialize(thread); }
a61af66fc99e Initial load
duke
parents:
diff changeset
304 ~HandleMark();
a61af66fc99e Initial load
duke
parents:
diff changeset
305
a61af66fc99e Initial load
duke
parents:
diff changeset
306 // Functions used by HandleMarkCleaner
a61af66fc99e Initial load
duke
parents:
diff changeset
307 // called in the constructor of HandleMarkCleaner
a61af66fc99e Initial load
duke
parents:
diff changeset
308 void push();
a61af66fc99e Initial load
duke
parents:
diff changeset
309 // called in the destructor of HandleMarkCleaner
a61af66fc99e Initial load
duke
parents:
diff changeset
310 void pop_and_restore();
a61af66fc99e Initial load
duke
parents:
diff changeset
311 };
a61af66fc99e Initial load
duke
parents:
diff changeset
312
a61af66fc99e Initial load
duke
parents:
diff changeset
313 //------------------------------------------------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
314 // A NoHandleMark stack object will verify that no handles are allocated
a61af66fc99e Initial load
duke
parents:
diff changeset
315 // in its scope. Enabled in debug mode only.
a61af66fc99e Initial load
duke
parents:
diff changeset
316
a61af66fc99e Initial load
duke
parents:
diff changeset
317 class NoHandleMark: public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
318 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
319 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
320 NoHandleMark();
a61af66fc99e Initial load
duke
parents:
diff changeset
321 ~NoHandleMark();
a61af66fc99e Initial load
duke
parents:
diff changeset
322 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
323 NoHandleMark() {}
a61af66fc99e Initial load
duke
parents:
diff changeset
324 ~NoHandleMark() {}
a61af66fc99e Initial load
duke
parents:
diff changeset
325 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
326 };
a61af66fc99e Initial load
duke
parents:
diff changeset
327
a61af66fc99e Initial load
duke
parents:
diff changeset
328
a61af66fc99e Initial load
duke
parents:
diff changeset
329 class ResetNoHandleMark: public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
330 int _no_handle_mark_nesting;
a61af66fc99e Initial load
duke
parents:
diff changeset
331 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
332 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
333 ResetNoHandleMark();
a61af66fc99e Initial load
duke
parents:
diff changeset
334 ~ResetNoHandleMark();
a61af66fc99e Initial load
duke
parents:
diff changeset
335 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
336 ResetNoHandleMark() {}
a61af66fc99e Initial load
duke
parents:
diff changeset
337 ~ResetNoHandleMark() {}
a61af66fc99e Initial load
duke
parents:
diff changeset
338 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
339 };
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
340
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
341 #endif // SHARE_VM_RUNTIME_HANDLES_HPP