annotate src/share/vm/interpreter/oopMapCache.cpp @ 4181:319860ae697a

Simplify FrameMap: make offsets of spill slots and outgoing parameters independent so that they can be allocated at the same time, eliminating the separate phases. This makes the separate StackBlock unnecesary. Change CiStackSlot to use byte offsets instead of spill slot index. This makes CiTarget.spillSlotSize unnecessary.
author Christian Wimmer <Christian.Wimmer@Oracle.com>
date Mon, 02 Jan 2012 14:16:08 -0800
parents f95d63e2154a
children d2a62e0f25eb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1681
diff changeset
2 * Copyright (c) 1997, 2010, 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: 1489
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1489
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: 1489
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: 1681
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1681
diff changeset
26 #include "interpreter/oopMapCache.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1681
diff changeset
27 #include "memory/allocation.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1681
diff changeset
28 #include "memory/resourceArea.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1681
diff changeset
29 #include "oops/oop.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1681
diff changeset
30 #include "prims/jvmtiRedefineClassesTrace.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1681
diff changeset
31 #include "runtime/handles.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1681
diff changeset
32 #include "runtime/signature.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34 class OopMapCacheEntry: private InterpreterOopMap {
a61af66fc99e Initial load
duke
parents:
diff changeset
35 friend class InterpreterOopMap;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 friend class OopMapForCacheEntry;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 friend class OopMapCache;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 friend class VerifyClosure;
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // Initialization
a61af66fc99e Initial load
duke
parents:
diff changeset
42 void fill(methodHandle method, int bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // fills the bit mask for native calls
a61af66fc99e Initial load
duke
parents:
diff changeset
44 void fill_for_native(methodHandle method);
a61af66fc99e Initial load
duke
parents:
diff changeset
45 void set_mask(CellTypeState* vars, CellTypeState* stack, int stack_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // Deallocate bit masks and initialize fields
a61af66fc99e Initial load
duke
parents:
diff changeset
48 void flush();
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
51 void allocate_bit_mask(); // allocates the bit mask on C heap f necessary
a61af66fc99e Initial load
duke
parents:
diff changeset
52 void deallocate_bit_mask(); // allocates the bit mask on C heap f necessary
a61af66fc99e Initial load
duke
parents:
diff changeset
53 bool verify_mask(CellTypeState *vars, CellTypeState *stack, int max_locals, int stack_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
56 OopMapCacheEntry() : InterpreterOopMap() {
a61af66fc99e Initial load
duke
parents:
diff changeset
57 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
58 _resource_allocate_bit_mask = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
60 }
a61af66fc99e Initial load
duke
parents:
diff changeset
61 };
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // Implementation of OopMapForCacheEntry
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // (subclass of GenerateOopMap, initializes an OopMapCacheEntry for a given method and bci)
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 class OopMapForCacheEntry: public GenerateOopMap {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 OopMapCacheEntry *_entry;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 int _bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 int _stack_top;
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 virtual bool report_results() const { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
73 virtual bool possible_gc_point (BytecodeStream *bcs);
a61af66fc99e Initial load
duke
parents:
diff changeset
74 virtual void fill_stackmap_prolog (int nof_gc_points);
a61af66fc99e Initial load
duke
parents:
diff changeset
75 virtual void fill_stackmap_epilog ();
a61af66fc99e Initial load
duke
parents:
diff changeset
76 virtual void fill_stackmap_for_opcodes (BytecodeStream *bcs,
a61af66fc99e Initial load
duke
parents:
diff changeset
77 CellTypeState* vars,
a61af66fc99e Initial load
duke
parents:
diff changeset
78 CellTypeState* stack,
a61af66fc99e Initial load
duke
parents:
diff changeset
79 int stack_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
80 virtual void fill_init_vars (GrowableArray<intptr_t> *init_vars);
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
83 OopMapForCacheEntry(methodHandle method, int bci, OopMapCacheEntry *entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // Computes stack map for (method,bci) and initialize entry
a61af66fc99e Initial load
duke
parents:
diff changeset
86 void compute_map(TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
87 int size();
a61af66fc99e Initial load
duke
parents:
diff changeset
88 };
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 OopMapForCacheEntry::OopMapForCacheEntry(methodHandle method, int bci, OopMapCacheEntry* entry) : GenerateOopMap(method) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 _bci = bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 _entry = entry;
a61af66fc99e Initial load
duke
parents:
diff changeset
94 _stack_top = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97
a61af66fc99e Initial load
duke
parents:
diff changeset
98 void OopMapForCacheEntry::compute_map(TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
99 assert(!method()->is_native(), "cannot compute oop map for native methods");
a61af66fc99e Initial load
duke
parents:
diff changeset
100 // First check if it is a method where the stackmap is always empty
a61af66fc99e Initial load
duke
parents:
diff changeset
101 if (method()->code_size() == 0 || method()->max_locals() + method()->max_stack() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 _entry->set_mask_size(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
103 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 GenerateOopMap::compute_map(CATCH);
a61af66fc99e Initial load
duke
parents:
diff changeset
106 result_for_basicblock(_bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 bool OopMapForCacheEntry::possible_gc_point(BytecodeStream *bcs) {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 return false; // We are not reporting any result. We call result_for_basicblock directly
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116 void OopMapForCacheEntry::fill_stackmap_prolog(int nof_gc_points) {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 // Do nothing
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 void OopMapForCacheEntry::fill_stackmap_epilog() {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 // Do nothing
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 void OopMapForCacheEntry::fill_init_vars(GrowableArray<intptr_t> *init_vars) {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 // Do nothing
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 void OopMapForCacheEntry::fill_stackmap_for_opcodes(BytecodeStream *bcs,
a61af66fc99e Initial load
duke
parents:
diff changeset
132 CellTypeState* vars,
a61af66fc99e Initial load
duke
parents:
diff changeset
133 CellTypeState* stack,
a61af66fc99e Initial load
duke
parents:
diff changeset
134 int stack_top) {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 // Only interested in one specific bci
a61af66fc99e Initial load
duke
parents:
diff changeset
136 if (bcs->bci() == _bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 _entry->set_mask(vars, stack, stack_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
138 _stack_top = stack_top;
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 int OopMapForCacheEntry::size() {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 assert(_stack_top != -1, "compute_map must be called first");
a61af66fc99e Initial load
duke
parents:
diff changeset
145 return ((method()->is_static()) ? 0 : 1) + method()->max_locals() + _stack_top;
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149 // Implementation of InterpreterOopMap and OopMapCacheEntry
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 class VerifyClosure : public OffsetClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
153 OopMapCacheEntry* _entry;
a61af66fc99e Initial load
duke
parents:
diff changeset
154 bool _failed;
a61af66fc99e Initial load
duke
parents:
diff changeset
155
a61af66fc99e Initial load
duke
parents:
diff changeset
156 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
157 VerifyClosure(OopMapCacheEntry* entry) { _entry = entry; _failed = false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
158 void offset_do(int offset) { if (!_entry->is_oop(offset)) _failed = true; }
a61af66fc99e Initial load
duke
parents:
diff changeset
159 bool failed() const { return _failed; }
a61af66fc99e Initial load
duke
parents:
diff changeset
160 };
a61af66fc99e Initial load
duke
parents:
diff changeset
161
a61af66fc99e Initial load
duke
parents:
diff changeset
162 InterpreterOopMap::InterpreterOopMap() {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 initialize();
a61af66fc99e Initial load
duke
parents:
diff changeset
164 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
165 _resource_allocate_bit_mask = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
166 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 InterpreterOopMap::~InterpreterOopMap() {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 // The expection is that the bit mask was allocated
a61af66fc99e Initial load
duke
parents:
diff changeset
171 // last in this resource area. That would make the free of the
a61af66fc99e Initial load
duke
parents:
diff changeset
172 // bit_mask effective (see how FREE_RESOURCE_ARRAY does a free).
a61af66fc99e Initial load
duke
parents:
diff changeset
173 // If it was not allocated last, there is not a correctness problem
a61af66fc99e Initial load
duke
parents:
diff changeset
174 // but the space for the bit_mask is not freed.
a61af66fc99e Initial load
duke
parents:
diff changeset
175 assert(_resource_allocate_bit_mask, "Trying to free C heap space");
a61af66fc99e Initial load
duke
parents:
diff changeset
176 if (mask_size() > small_mask_limit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 FREE_RESOURCE_ARRAY(uintptr_t, _bit_mask[0], mask_word_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
178 }
a61af66fc99e Initial load
duke
parents:
diff changeset
179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
180
a61af66fc99e Initial load
duke
parents:
diff changeset
181 bool InterpreterOopMap::is_empty() {
a61af66fc99e Initial load
duke
parents:
diff changeset
182 bool result = _method == NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
183 assert(_method != NULL || (_bci == 0 &&
a61af66fc99e Initial load
duke
parents:
diff changeset
184 (_mask_size == 0 || _mask_size == USHRT_MAX) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
185 _bit_mask[0] == 0), "Should be completely empty");
a61af66fc99e Initial load
duke
parents:
diff changeset
186 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
187 }
a61af66fc99e Initial load
duke
parents:
diff changeset
188
a61af66fc99e Initial load
duke
parents:
diff changeset
189 void InterpreterOopMap::initialize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 _method = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
191 _mask_size = USHRT_MAX; // This value should cause a failure quickly
a61af66fc99e Initial load
duke
parents:
diff changeset
192 _bci = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
193 _expression_stack_size = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
194 for (int i = 0; i < N; i++) _bit_mask[i] = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
195 }
a61af66fc99e Initial load
duke
parents:
diff changeset
196
a61af66fc99e Initial load
duke
parents:
diff changeset
197
a61af66fc99e Initial load
duke
parents:
diff changeset
198 void InterpreterOopMap::oop_iterate(OopClosure *blk) {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 if (method() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
200 blk->do_oop((oop*) &_method);
a61af66fc99e Initial load
duke
parents:
diff changeset
201 }
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203
a61af66fc99e Initial load
duke
parents:
diff changeset
204 void InterpreterOopMap::oop_iterate(OopClosure *blk, MemRegion mr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
205 if (method() != NULL && mr.contains(&_method)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
206 blk->do_oop((oop*) &_method);
a61af66fc99e Initial load
duke
parents:
diff changeset
207 }
a61af66fc99e Initial load
duke
parents:
diff changeset
208 }
a61af66fc99e Initial load
duke
parents:
diff changeset
209
a61af66fc99e Initial load
duke
parents:
diff changeset
210
a61af66fc99e Initial load
duke
parents:
diff changeset
211
a61af66fc99e Initial load
duke
parents:
diff changeset
212 void InterpreterOopMap::iterate_oop(OffsetClosure* oop_closure) {
a61af66fc99e Initial load
duke
parents:
diff changeset
213 int n = number_of_entries();
a61af66fc99e Initial load
duke
parents:
diff changeset
214 int word_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
215 uintptr_t value = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
216 uintptr_t mask = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
217 // iterate over entries
a61af66fc99e Initial load
duke
parents:
diff changeset
218 for (int i = 0; i < n; i++, mask <<= bits_per_entry) {
a61af66fc99e Initial load
duke
parents:
diff changeset
219 // get current word
a61af66fc99e Initial load
duke
parents:
diff changeset
220 if (mask == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
221 value = bit_mask()[word_index++];
a61af66fc99e Initial load
duke
parents:
diff changeset
222 mask = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
223 }
a61af66fc99e Initial load
duke
parents:
diff changeset
224 // test for oop
a61af66fc99e Initial load
duke
parents:
diff changeset
225 if ((value & (mask << oop_bit_number)) != 0) oop_closure->offset_do(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
226 }
a61af66fc99e Initial load
duke
parents:
diff changeset
227 }
a61af66fc99e Initial load
duke
parents:
diff changeset
228
a61af66fc99e Initial load
duke
parents:
diff changeset
229 void InterpreterOopMap::verify() {
a61af66fc99e Initial load
duke
parents:
diff changeset
230 // If we are doing mark sweep _method may not have a valid header
a61af66fc99e Initial load
duke
parents:
diff changeset
231 // $$$ This used to happen only for m/s collections; we might want to
a61af66fc99e Initial load
duke
parents:
diff changeset
232 // think of an appropriate generalization of this distinction.
1489
cff162798819 6888953: some calls to function-like macros are missing semicolons
jcoomes
parents: 1010
diff changeset
233 guarantee(Universe::heap()->is_gc_active() || _method->is_oop_or_null(),
cff162798819 6888953: some calls to function-like macros are missing semicolons
jcoomes
parents: 1010
diff changeset
234 "invalid oop in oopMapCache");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
235 }
a61af66fc99e Initial load
duke
parents:
diff changeset
236
a61af66fc99e Initial load
duke
parents:
diff changeset
237 #ifdef ENABLE_ZAP_DEAD_LOCALS
a61af66fc99e Initial load
duke
parents:
diff changeset
238
a61af66fc99e Initial load
duke
parents:
diff changeset
239 void InterpreterOopMap::iterate_all(OffsetClosure* oop_closure, OffsetClosure* value_closure, OffsetClosure* dead_closure) {
a61af66fc99e Initial load
duke
parents:
diff changeset
240 int n = number_of_entries();
a61af66fc99e Initial load
duke
parents:
diff changeset
241 int word_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
242 uintptr_t value = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
243 uintptr_t mask = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
244 // iterate over entries
a61af66fc99e Initial load
duke
parents:
diff changeset
245 for (int i = 0; i < n; i++, mask <<= bits_per_entry) {
a61af66fc99e Initial load
duke
parents:
diff changeset
246 // get current word
a61af66fc99e Initial load
duke
parents:
diff changeset
247 if (mask == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
248 value = bit_mask()[word_index++];
a61af66fc99e Initial load
duke
parents:
diff changeset
249 mask = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
250 }
a61af66fc99e Initial load
duke
parents:
diff changeset
251 // test for dead values & oops, and for live values
a61af66fc99e Initial load
duke
parents:
diff changeset
252 if ((value & (mask << dead_bit_number)) != 0) dead_closure->offset_do(i); // call this for all dead values or oops
a61af66fc99e Initial load
duke
parents:
diff changeset
253 else if ((value & (mask << oop_bit_number)) != 0) oop_closure->offset_do(i); // call this for all live oops
a61af66fc99e Initial load
duke
parents:
diff changeset
254 else value_closure->offset_do(i); // call this for all live values
a61af66fc99e Initial load
duke
parents:
diff changeset
255 }
a61af66fc99e Initial load
duke
parents:
diff changeset
256 }
a61af66fc99e Initial load
duke
parents:
diff changeset
257
a61af66fc99e Initial load
duke
parents:
diff changeset
258 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
259
a61af66fc99e Initial load
duke
parents:
diff changeset
260
a61af66fc99e Initial load
duke
parents:
diff changeset
261 void InterpreterOopMap::print() {
a61af66fc99e Initial load
duke
parents:
diff changeset
262 int n = number_of_entries();
a61af66fc99e Initial load
duke
parents:
diff changeset
263 tty->print("oop map for ");
a61af66fc99e Initial load
duke
parents:
diff changeset
264 method()->print_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
265 tty->print(" @ %d = [%d] { ", bci(), n);
a61af66fc99e Initial load
duke
parents:
diff changeset
266 for (int i = 0; i < n; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
267 #ifdef ENABLE_ZAP_DEAD_LOCALS
a61af66fc99e Initial load
duke
parents:
diff changeset
268 if (is_dead(i)) tty->print("%d+ ", i);
a61af66fc99e Initial load
duke
parents:
diff changeset
269 else
a61af66fc99e Initial load
duke
parents:
diff changeset
270 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
271 if (is_oop(i)) tty->print("%d ", i);
a61af66fc99e Initial load
duke
parents:
diff changeset
272 }
a61af66fc99e Initial load
duke
parents:
diff changeset
273 tty->print_cr("}");
a61af66fc99e Initial load
duke
parents:
diff changeset
274 }
a61af66fc99e Initial load
duke
parents:
diff changeset
275
a61af66fc99e Initial load
duke
parents:
diff changeset
276 class MaskFillerForNative: public NativeSignatureIterator {
a61af66fc99e Initial load
duke
parents:
diff changeset
277 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
278 uintptr_t * _mask; // the bit mask to be filled
a61af66fc99e Initial load
duke
parents:
diff changeset
279 int _size; // the mask size in bits
a61af66fc99e Initial load
duke
parents:
diff changeset
280
a61af66fc99e Initial load
duke
parents:
diff changeset
281 void set_one(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
282 i *= InterpreterOopMap::bits_per_entry;
a61af66fc99e Initial load
duke
parents:
diff changeset
283 assert(0 <= i && i < _size, "offset out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
284 _mask[i / BitsPerWord] |= (((uintptr_t) 1 << InterpreterOopMap::oop_bit_number) << (i % BitsPerWord));
a61af66fc99e Initial load
duke
parents:
diff changeset
285 }
a61af66fc99e Initial load
duke
parents:
diff changeset
286
a61af66fc99e Initial load
duke
parents:
diff changeset
287 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
288 void pass_int() { /* ignore */ }
a61af66fc99e Initial load
duke
parents:
diff changeset
289 void pass_long() { /* ignore */ }
a61af66fc99e Initial load
duke
parents:
diff changeset
290 void pass_float() { /* ignore */ }
a61af66fc99e Initial load
duke
parents:
diff changeset
291 void pass_double() { /* ignore */ }
a61af66fc99e Initial load
duke
parents:
diff changeset
292 void pass_object() { set_one(offset()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
293
a61af66fc99e Initial load
duke
parents:
diff changeset
294 MaskFillerForNative(methodHandle method, uintptr_t* mask, int size) : NativeSignatureIterator(method) {
a61af66fc99e Initial load
duke
parents:
diff changeset
295 _mask = mask;
a61af66fc99e Initial load
duke
parents:
diff changeset
296 _size = size;
a61af66fc99e Initial load
duke
parents:
diff changeset
297 // initialize with 0
a61af66fc99e Initial load
duke
parents:
diff changeset
298 int i = (size + BitsPerWord - 1) / BitsPerWord;
a61af66fc99e Initial load
duke
parents:
diff changeset
299 while (i-- > 0) _mask[i] = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
300 }
a61af66fc99e Initial load
duke
parents:
diff changeset
301
a61af66fc99e Initial load
duke
parents:
diff changeset
302 void generate() {
a61af66fc99e Initial load
duke
parents:
diff changeset
303 NativeSignatureIterator::iterate();
a61af66fc99e Initial load
duke
parents:
diff changeset
304 }
a61af66fc99e Initial load
duke
parents:
diff changeset
305 };
a61af66fc99e Initial load
duke
parents:
diff changeset
306
a61af66fc99e Initial load
duke
parents:
diff changeset
307 bool OopMapCacheEntry::verify_mask(CellTypeState* vars, CellTypeState* stack, int max_locals, int stack_top) {
a61af66fc99e Initial load
duke
parents:
diff changeset
308 // Check mask includes map
a61af66fc99e Initial load
duke
parents:
diff changeset
309 VerifyClosure blk(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
310 iterate_oop(&blk);
a61af66fc99e Initial load
duke
parents:
diff changeset
311 if (blk.failed()) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
312
a61af66fc99e Initial load
duke
parents:
diff changeset
313 // Check if map is generated correctly
a61af66fc99e Initial load
duke
parents:
diff changeset
314 // (Use ?: operator to make sure all 'true' & 'false' are represented exactly the same so we can use == afterwards)
a61af66fc99e Initial load
duke
parents:
diff changeset
315 if (TraceOopMapGeneration && Verbose) tty->print("Locals (%d): ", max_locals);
a61af66fc99e Initial load
duke
parents:
diff changeset
316
a61af66fc99e Initial load
duke
parents:
diff changeset
317 for(int i = 0; i < max_locals; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
318 bool v1 = is_oop(i) ? true : false;
a61af66fc99e Initial load
duke
parents:
diff changeset
319 bool v2 = vars[i].is_reference() ? true : false;
a61af66fc99e Initial load
duke
parents:
diff changeset
320 assert(v1 == v2, "locals oop mask generation error");
a61af66fc99e Initial load
duke
parents:
diff changeset
321 if (TraceOopMapGeneration && Verbose) tty->print("%d", v1 ? 1 : 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
322 #ifdef ENABLE_ZAP_DEAD_LOCALS
a61af66fc99e Initial load
duke
parents:
diff changeset
323 bool v3 = is_dead(i) ? true : false;
a61af66fc99e Initial load
duke
parents:
diff changeset
324 bool v4 = !vars[i].is_live() ? true : false;
a61af66fc99e Initial load
duke
parents:
diff changeset
325 assert(v3 == v4, "locals live mask generation error");
a61af66fc99e Initial load
duke
parents:
diff changeset
326 assert(!(v1 && v3), "dead value marked as oop");
a61af66fc99e Initial load
duke
parents:
diff changeset
327 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
328 }
a61af66fc99e Initial load
duke
parents:
diff changeset
329
a61af66fc99e Initial load
duke
parents:
diff changeset
330 if (TraceOopMapGeneration && Verbose) { tty->cr(); tty->print("Stack (%d): ", stack_top); }
a61af66fc99e Initial load
duke
parents:
diff changeset
331 for(int j = 0; j < stack_top; j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
332 bool v1 = is_oop(max_locals + j) ? true : false;
a61af66fc99e Initial load
duke
parents:
diff changeset
333 bool v2 = stack[j].is_reference() ? true : false;
a61af66fc99e Initial load
duke
parents:
diff changeset
334 assert(v1 == v2, "stack oop mask generation error");
a61af66fc99e Initial load
duke
parents:
diff changeset
335 if (TraceOopMapGeneration && Verbose) tty->print("%d", v1 ? 1 : 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
336 #ifdef ENABLE_ZAP_DEAD_LOCALS
a61af66fc99e Initial load
duke
parents:
diff changeset
337 bool v3 = is_dead(max_locals + j) ? true : false;
a61af66fc99e Initial load
duke
parents:
diff changeset
338 bool v4 = !stack[j].is_live() ? true : false;
a61af66fc99e Initial load
duke
parents:
diff changeset
339 assert(v3 == v4, "stack live mask generation error");
a61af66fc99e Initial load
duke
parents:
diff changeset
340 assert(!(v1 && v3), "dead value marked as oop");
a61af66fc99e Initial load
duke
parents:
diff changeset
341 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
342 }
a61af66fc99e Initial load
duke
parents:
diff changeset
343 if (TraceOopMapGeneration && Verbose) tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
344 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
345 }
a61af66fc99e Initial load
duke
parents:
diff changeset
346
a61af66fc99e Initial load
duke
parents:
diff changeset
347 void OopMapCacheEntry::allocate_bit_mask() {
a61af66fc99e Initial load
duke
parents:
diff changeset
348 if (mask_size() > small_mask_limit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
349 assert(_bit_mask[0] == 0, "bit mask should be new or just flushed");
a61af66fc99e Initial load
duke
parents:
diff changeset
350 _bit_mask[0] = (intptr_t)
a61af66fc99e Initial load
duke
parents:
diff changeset
351 NEW_C_HEAP_ARRAY(uintptr_t, mask_word_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
352 }
a61af66fc99e Initial load
duke
parents:
diff changeset
353 }
a61af66fc99e Initial load
duke
parents:
diff changeset
354
a61af66fc99e Initial load
duke
parents:
diff changeset
355 void OopMapCacheEntry::deallocate_bit_mask() {
a61af66fc99e Initial load
duke
parents:
diff changeset
356 if (mask_size() > small_mask_limit && _bit_mask[0] != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
357 assert(!Thread::current()->resource_area()->contains((void*)_bit_mask[0]),
a61af66fc99e Initial load
duke
parents:
diff changeset
358 "This bit mask should not be in the resource area");
a61af66fc99e Initial load
duke
parents:
diff changeset
359 FREE_C_HEAP_ARRAY(uintptr_t, _bit_mask[0]);
a61af66fc99e Initial load
duke
parents:
diff changeset
360 debug_only(_bit_mask[0] = 0;)
a61af66fc99e Initial load
duke
parents:
diff changeset
361 }
a61af66fc99e Initial load
duke
parents:
diff changeset
362 }
a61af66fc99e Initial load
duke
parents:
diff changeset
363
a61af66fc99e Initial load
duke
parents:
diff changeset
364
a61af66fc99e Initial load
duke
parents:
diff changeset
365 void OopMapCacheEntry::fill_for_native(methodHandle mh) {
a61af66fc99e Initial load
duke
parents:
diff changeset
366 assert(mh->is_native(), "method must be native method");
a61af66fc99e Initial load
duke
parents:
diff changeset
367 set_mask_size(mh->size_of_parameters() * bits_per_entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
368 allocate_bit_mask();
a61af66fc99e Initial load
duke
parents:
diff changeset
369 // fill mask for parameters
a61af66fc99e Initial load
duke
parents:
diff changeset
370 MaskFillerForNative mf(mh, bit_mask(), mask_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
371 mf.generate();
a61af66fc99e Initial load
duke
parents:
diff changeset
372 }
a61af66fc99e Initial load
duke
parents:
diff changeset
373
a61af66fc99e Initial load
duke
parents:
diff changeset
374
a61af66fc99e Initial load
duke
parents:
diff changeset
375 void OopMapCacheEntry::fill(methodHandle method, int bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
376 HandleMark hm;
a61af66fc99e Initial load
duke
parents:
diff changeset
377 // Flush entry to deallocate an existing entry
a61af66fc99e Initial load
duke
parents:
diff changeset
378 flush();
a61af66fc99e Initial load
duke
parents:
diff changeset
379 set_method(method());
a61af66fc99e Initial load
duke
parents:
diff changeset
380 set_bci(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
381 if (method->is_native()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
382 // Native method activations have oops only among the parameters and one
a61af66fc99e Initial load
duke
parents:
diff changeset
383 // extra oop following the parameters (the mirror for static native methods).
a61af66fc99e Initial load
duke
parents:
diff changeset
384 fill_for_native(method);
a61af66fc99e Initial load
duke
parents:
diff changeset
385 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
386 EXCEPTION_MARK;
a61af66fc99e Initial load
duke
parents:
diff changeset
387 OopMapForCacheEntry gen(method, bci, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
388 gen.compute_map(CATCH);
a61af66fc99e Initial load
duke
parents:
diff changeset
389 }
a61af66fc99e Initial load
duke
parents:
diff changeset
390 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
391 verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
392 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
393 }
a61af66fc99e Initial load
duke
parents:
diff changeset
394
a61af66fc99e Initial load
duke
parents:
diff changeset
395
a61af66fc99e Initial load
duke
parents:
diff changeset
396 void OopMapCacheEntry::set_mask(CellTypeState *vars, CellTypeState *stack, int stack_top) {
a61af66fc99e Initial load
duke
parents:
diff changeset
397 // compute bit mask size
a61af66fc99e Initial load
duke
parents:
diff changeset
398 int max_locals = method()->max_locals();
a61af66fc99e Initial load
duke
parents:
diff changeset
399 int n_entries = max_locals + stack_top;
a61af66fc99e Initial load
duke
parents:
diff changeset
400 set_mask_size(n_entries * bits_per_entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
401 allocate_bit_mask();
a61af66fc99e Initial load
duke
parents:
diff changeset
402 set_expression_stack_size(stack_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
403
a61af66fc99e Initial load
duke
parents:
diff changeset
404 // compute bits
a61af66fc99e Initial load
duke
parents:
diff changeset
405 int word_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
406 uintptr_t value = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
407 uintptr_t mask = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
408
a61af66fc99e Initial load
duke
parents:
diff changeset
409 CellTypeState* cell = vars;
a61af66fc99e Initial load
duke
parents:
diff changeset
410 for (int entry_index = 0; entry_index < n_entries; entry_index++, mask <<= bits_per_entry, cell++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
411 // store last word
a61af66fc99e Initial load
duke
parents:
diff changeset
412 if (mask == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
413 bit_mask()[word_index++] = value;
a61af66fc99e Initial load
duke
parents:
diff changeset
414 value = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
415 mask = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
416 }
a61af66fc99e Initial load
duke
parents:
diff changeset
417
a61af66fc99e Initial load
duke
parents:
diff changeset
418 // switch to stack when done with locals
a61af66fc99e Initial load
duke
parents:
diff changeset
419 if (entry_index == max_locals) {
a61af66fc99e Initial load
duke
parents:
diff changeset
420 cell = stack;
a61af66fc99e Initial load
duke
parents:
diff changeset
421 }
a61af66fc99e Initial load
duke
parents:
diff changeset
422
a61af66fc99e Initial load
duke
parents:
diff changeset
423 // set oop bit
a61af66fc99e Initial load
duke
parents:
diff changeset
424 if ( cell->is_reference()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
425 value |= (mask << oop_bit_number );
a61af66fc99e Initial load
duke
parents:
diff changeset
426 }
a61af66fc99e Initial load
duke
parents:
diff changeset
427
a61af66fc99e Initial load
duke
parents:
diff changeset
428 #ifdef ENABLE_ZAP_DEAD_LOCALS
a61af66fc99e Initial load
duke
parents:
diff changeset
429 // set dead bit
a61af66fc99e Initial load
duke
parents:
diff changeset
430 if (!cell->is_live()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
431 value |= (mask << dead_bit_number);
a61af66fc99e Initial load
duke
parents:
diff changeset
432 assert(!cell->is_reference(), "dead value marked as oop");
a61af66fc99e Initial load
duke
parents:
diff changeset
433 }
a61af66fc99e Initial load
duke
parents:
diff changeset
434 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
435 }
a61af66fc99e Initial load
duke
parents:
diff changeset
436
a61af66fc99e Initial load
duke
parents:
diff changeset
437 // make sure last word is stored
a61af66fc99e Initial load
duke
parents:
diff changeset
438 bit_mask()[word_index] = value;
a61af66fc99e Initial load
duke
parents:
diff changeset
439
a61af66fc99e Initial load
duke
parents:
diff changeset
440 // verify bit mask
a61af66fc99e Initial load
duke
parents:
diff changeset
441 assert(verify_mask(vars, stack, max_locals, stack_top), "mask could not be verified");
a61af66fc99e Initial load
duke
parents:
diff changeset
442
a61af66fc99e Initial load
duke
parents:
diff changeset
443
a61af66fc99e Initial load
duke
parents:
diff changeset
444 }
a61af66fc99e Initial load
duke
parents:
diff changeset
445
a61af66fc99e Initial load
duke
parents:
diff changeset
446 void OopMapCacheEntry::flush() {
a61af66fc99e Initial load
duke
parents:
diff changeset
447 deallocate_bit_mask();
a61af66fc99e Initial load
duke
parents:
diff changeset
448 initialize();
a61af66fc99e Initial load
duke
parents:
diff changeset
449 }
a61af66fc99e Initial load
duke
parents:
diff changeset
450
a61af66fc99e Initial load
duke
parents:
diff changeset
451
a61af66fc99e Initial load
duke
parents:
diff changeset
452 // Implementation of OopMapCache
a61af66fc99e Initial load
duke
parents:
diff changeset
453
a61af66fc99e Initial load
duke
parents:
diff changeset
454 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
455
a61af66fc99e Initial load
duke
parents:
diff changeset
456 static long _total_memory_usage = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
457
a61af66fc99e Initial load
duke
parents:
diff changeset
458 long OopMapCache::memory_usage() {
a61af66fc99e Initial load
duke
parents:
diff changeset
459 return _total_memory_usage;
a61af66fc99e Initial load
duke
parents:
diff changeset
460 }
a61af66fc99e Initial load
duke
parents:
diff changeset
461
a61af66fc99e Initial load
duke
parents:
diff changeset
462 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
463
a61af66fc99e Initial load
duke
parents:
diff changeset
464 void InterpreterOopMap::resource_copy(OopMapCacheEntry* from) {
a61af66fc99e Initial load
duke
parents:
diff changeset
465 assert(_resource_allocate_bit_mask,
a61af66fc99e Initial load
duke
parents:
diff changeset
466 "Should not resource allocate the _bit_mask");
a61af66fc99e Initial load
duke
parents:
diff changeset
467 assert(from->method()->is_oop(), "MethodOop is bad");
a61af66fc99e Initial load
duke
parents:
diff changeset
468
a61af66fc99e Initial load
duke
parents:
diff changeset
469 set_method(from->method());
a61af66fc99e Initial load
duke
parents:
diff changeset
470 set_bci(from->bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
471 set_mask_size(from->mask_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
472 set_expression_stack_size(from->expression_stack_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
473
a61af66fc99e Initial load
duke
parents:
diff changeset
474 // Is the bit mask contained in the entry?
a61af66fc99e Initial load
duke
parents:
diff changeset
475 if (from->mask_size() <= small_mask_limit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
476 memcpy((void *)_bit_mask, (void *)from->_bit_mask,
a61af66fc99e Initial load
duke
parents:
diff changeset
477 mask_word_size() * BytesPerWord);
a61af66fc99e Initial load
duke
parents:
diff changeset
478 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
479 // The expectation is that this InterpreterOopMap is a recently created
a61af66fc99e Initial load
duke
parents:
diff changeset
480 // and empty. It is used to get a copy of a cached entry.
a61af66fc99e Initial load
duke
parents:
diff changeset
481 // If the bit mask has a value, it should be in the
a61af66fc99e Initial load
duke
parents:
diff changeset
482 // resource area.
a61af66fc99e Initial load
duke
parents:
diff changeset
483 assert(_bit_mask[0] == 0 ||
a61af66fc99e Initial load
duke
parents:
diff changeset
484 Thread::current()->resource_area()->contains((void*)_bit_mask[0]),
a61af66fc99e Initial load
duke
parents:
diff changeset
485 "The bit mask should have been allocated from a resource area");
a61af66fc99e Initial load
duke
parents:
diff changeset
486 // Allocate the bit_mask from a Resource area for performance. Allocating
a61af66fc99e Initial load
duke
parents:
diff changeset
487 // from the C heap as is done for OopMapCache has a significant
a61af66fc99e Initial load
duke
parents:
diff changeset
488 // performance impact.
a61af66fc99e Initial load
duke
parents:
diff changeset
489 _bit_mask[0] = (uintptr_t) NEW_RESOURCE_ARRAY(uintptr_t, mask_word_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
490 assert(_bit_mask[0] != 0, "bit mask was not allocated");
a61af66fc99e Initial load
duke
parents:
diff changeset
491 memcpy((void*) _bit_mask[0], (void*) from->_bit_mask[0],
a61af66fc99e Initial load
duke
parents:
diff changeset
492 mask_word_size() * BytesPerWord);
a61af66fc99e Initial load
duke
parents:
diff changeset
493 }
a61af66fc99e Initial load
duke
parents:
diff changeset
494 }
a61af66fc99e Initial load
duke
parents:
diff changeset
495
a61af66fc99e Initial load
duke
parents:
diff changeset
496 inline unsigned int OopMapCache::hash_value_for(methodHandle method, int bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
497 // We use method->code_size() rather than method->identity_hash() below since
a61af66fc99e Initial load
duke
parents:
diff changeset
498 // the mark may not be present if a pointer to the method is already reversed.
a61af66fc99e Initial load
duke
parents:
diff changeset
499 return ((unsigned int) bci)
a61af66fc99e Initial load
duke
parents:
diff changeset
500 ^ ((unsigned int) method->max_locals() << 2)
a61af66fc99e Initial load
duke
parents:
diff changeset
501 ^ ((unsigned int) method->code_size() << 4)
a61af66fc99e Initial load
duke
parents:
diff changeset
502 ^ ((unsigned int) method->size_of_parameters() << 6);
a61af66fc99e Initial load
duke
parents:
diff changeset
503 }
a61af66fc99e Initial load
duke
parents:
diff changeset
504
a61af66fc99e Initial load
duke
parents:
diff changeset
505
a61af66fc99e Initial load
duke
parents:
diff changeset
506 OopMapCache::OopMapCache() :
a61af66fc99e Initial load
duke
parents:
diff changeset
507 _mut(Mutex::leaf, "An OopMapCache lock", true)
a61af66fc99e Initial load
duke
parents:
diff changeset
508 {
a61af66fc99e Initial load
duke
parents:
diff changeset
509 _array = NEW_C_HEAP_ARRAY(OopMapCacheEntry, _size);
a61af66fc99e Initial load
duke
parents:
diff changeset
510 // Cannot call flush for initialization, since flush
a61af66fc99e Initial load
duke
parents:
diff changeset
511 // will check if memory should be deallocated
a61af66fc99e Initial load
duke
parents:
diff changeset
512 for(int i = 0; i < _size; i++) _array[i].initialize();
a61af66fc99e Initial load
duke
parents:
diff changeset
513 NOT_PRODUCT(_total_memory_usage += sizeof(OopMapCache) + (sizeof(OopMapCacheEntry) * _size);)
a61af66fc99e Initial load
duke
parents:
diff changeset
514 }
a61af66fc99e Initial load
duke
parents:
diff changeset
515
a61af66fc99e Initial load
duke
parents:
diff changeset
516
a61af66fc99e Initial load
duke
parents:
diff changeset
517 OopMapCache::~OopMapCache() {
a61af66fc99e Initial load
duke
parents:
diff changeset
518 assert(_array != NULL, "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
519 // Deallocate oop maps that are allocated out-of-line
a61af66fc99e Initial load
duke
parents:
diff changeset
520 flush();
a61af66fc99e Initial load
duke
parents:
diff changeset
521 // Deallocate array
a61af66fc99e Initial load
duke
parents:
diff changeset
522 NOT_PRODUCT(_total_memory_usage -= sizeof(OopMapCache) + (sizeof(OopMapCacheEntry) * _size);)
a61af66fc99e Initial load
duke
parents:
diff changeset
523 FREE_C_HEAP_ARRAY(OopMapCacheEntry, _array);
a61af66fc99e Initial load
duke
parents:
diff changeset
524 }
a61af66fc99e Initial load
duke
parents:
diff changeset
525
a61af66fc99e Initial load
duke
parents:
diff changeset
526 OopMapCacheEntry* OopMapCache::entry_at(int i) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
527 return &_array[i % _size];
a61af66fc99e Initial load
duke
parents:
diff changeset
528 }
a61af66fc99e Initial load
duke
parents:
diff changeset
529
a61af66fc99e Initial load
duke
parents:
diff changeset
530 void OopMapCache::flush() {
a61af66fc99e Initial load
duke
parents:
diff changeset
531 for (int i = 0; i < _size; i++) _array[i].flush();
a61af66fc99e Initial load
duke
parents:
diff changeset
532 }
a61af66fc99e Initial load
duke
parents:
diff changeset
533
a61af66fc99e Initial load
duke
parents:
diff changeset
534 void OopMapCache::flush_obsolete_entries() {
a61af66fc99e Initial load
duke
parents:
diff changeset
535 for (int i = 0; i < _size; i++)
a61af66fc99e Initial load
duke
parents:
diff changeset
536 if (!_array[i].is_empty() && _array[i].method()->is_old()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
537 // Cache entry is occupied by an old redefined method and we don't want
a61af66fc99e Initial load
duke
parents:
diff changeset
538 // to pin it down so flush the entry.
48
d8b3ef7ee3e5 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 0
diff changeset
539 RC_TRACE(0x08000000, ("flush: %s(%s): cached entry @%d",
d8b3ef7ee3e5 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 0
diff changeset
540 _array[i].method()->name()->as_C_string(),
d8b3ef7ee3e5 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 0
diff changeset
541 _array[i].method()->signature()->as_C_string(), i));
d8b3ef7ee3e5 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 0
diff changeset
542
0
a61af66fc99e Initial load
duke
parents:
diff changeset
543 _array[i].flush();
a61af66fc99e Initial load
duke
parents:
diff changeset
544 }
a61af66fc99e Initial load
duke
parents:
diff changeset
545 }
a61af66fc99e Initial load
duke
parents:
diff changeset
546
a61af66fc99e Initial load
duke
parents:
diff changeset
547 void OopMapCache::oop_iterate(OopClosure *blk) {
a61af66fc99e Initial load
duke
parents:
diff changeset
548 for (int i = 0; i < _size; i++) _array[i].oop_iterate(blk);
a61af66fc99e Initial load
duke
parents:
diff changeset
549 }
a61af66fc99e Initial load
duke
parents:
diff changeset
550
a61af66fc99e Initial load
duke
parents:
diff changeset
551 void OopMapCache::oop_iterate(OopClosure *blk, MemRegion mr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
552 for (int i = 0; i < _size; i++) _array[i].oop_iterate(blk, mr);
a61af66fc99e Initial load
duke
parents:
diff changeset
553 }
a61af66fc99e Initial load
duke
parents:
diff changeset
554
a61af66fc99e Initial load
duke
parents:
diff changeset
555 void OopMapCache::verify() {
a61af66fc99e Initial load
duke
parents:
diff changeset
556 for (int i = 0; i < _size; i++) _array[i].verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
557 }
a61af66fc99e Initial load
duke
parents:
diff changeset
558
a61af66fc99e Initial load
duke
parents:
diff changeset
559 void OopMapCache::lookup(methodHandle method,
a61af66fc99e Initial load
duke
parents:
diff changeset
560 int bci,
a61af66fc99e Initial load
duke
parents:
diff changeset
561 InterpreterOopMap* entry_for) {
a61af66fc99e Initial load
duke
parents:
diff changeset
562 MutexLocker x(&_mut);
a61af66fc99e Initial load
duke
parents:
diff changeset
563
a61af66fc99e Initial load
duke
parents:
diff changeset
564 OopMapCacheEntry* entry = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
565 int probe = hash_value_for(method, bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
566
a61af66fc99e Initial load
duke
parents:
diff changeset
567 // Search hashtable for match
a61af66fc99e Initial load
duke
parents:
diff changeset
568 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
569 for(i = 0; i < _probe_depth; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
570 entry = entry_at(probe + i);
a61af66fc99e Initial load
duke
parents:
diff changeset
571 if (entry->match(method, bci)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
572 entry_for->resource_copy(entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
573 assert(!entry_for->is_empty(), "A non-empty oop map should be returned");
a61af66fc99e Initial load
duke
parents:
diff changeset
574 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
575 }
a61af66fc99e Initial load
duke
parents:
diff changeset
576 }
a61af66fc99e Initial load
duke
parents:
diff changeset
577
a61af66fc99e Initial load
duke
parents:
diff changeset
578 if (TraceOopMapGeneration) {
a61af66fc99e Initial load
duke
parents:
diff changeset
579 static int count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
580 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
581 tty->print("%d - Computing oopmap at bci %d for ", ++count, bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
582 method->print_value(); tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
583 }
a61af66fc99e Initial load
duke
parents:
diff changeset
584
a61af66fc99e Initial load
duke
parents:
diff changeset
585 // Entry is not in hashtable.
a61af66fc99e Initial load
duke
parents:
diff changeset
586 // Compute entry and return it
a61af66fc99e Initial load
duke
parents:
diff changeset
587
48
d8b3ef7ee3e5 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 0
diff changeset
588 if (method->should_not_be_cached()) {
d8b3ef7ee3e5 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 0
diff changeset
589 // It is either not safe or not a good idea to cache this methodOop
d8b3ef7ee3e5 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 0
diff changeset
590 // at this time. We give the caller of lookup() a copy of the
d8b3ef7ee3e5 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 0
diff changeset
591 // interesting info via parameter entry_for, but we don't add it to
d8b3ef7ee3e5 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 0
diff changeset
592 // the cache. See the gory details in methodOop.cpp.
d8b3ef7ee3e5 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 0
diff changeset
593 compute_one_oop_map(method, bci, entry_for);
d8b3ef7ee3e5 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 0
diff changeset
594 return;
d8b3ef7ee3e5 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 0
diff changeset
595 }
d8b3ef7ee3e5 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 0
diff changeset
596
0
a61af66fc99e Initial load
duke
parents:
diff changeset
597 // First search for an empty slot
a61af66fc99e Initial load
duke
parents:
diff changeset
598 for(i = 0; i < _probe_depth; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
599 entry = entry_at(probe + i);
a61af66fc99e Initial load
duke
parents:
diff changeset
600 if (entry->is_empty()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
601 entry->fill(method, bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
602 entry_for->resource_copy(entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
603 assert(!entry_for->is_empty(), "A non-empty oop map should be returned");
a61af66fc99e Initial load
duke
parents:
diff changeset
604 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
605 }
a61af66fc99e Initial load
duke
parents:
diff changeset
606 }
a61af66fc99e Initial load
duke
parents:
diff changeset
607
a61af66fc99e Initial load
duke
parents:
diff changeset
608 if (TraceOopMapGeneration) {
a61af66fc99e Initial load
duke
parents:
diff changeset
609 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
610 tty->print_cr("*** collision in oopmap cache - flushing item ***");
a61af66fc99e Initial load
duke
parents:
diff changeset
611 }
a61af66fc99e Initial load
duke
parents:
diff changeset
612
a61af66fc99e Initial load
duke
parents:
diff changeset
613 // No empty slot (uncommon case). Use (some approximation of a) LRU algorithm
a61af66fc99e Initial load
duke
parents:
diff changeset
614 //entry_at(probe + _probe_depth - 1)->flush();
a61af66fc99e Initial load
duke
parents:
diff changeset
615 //for(i = _probe_depth - 1; i > 0; i--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
616 // // Coping entry[i] = entry[i-1];
a61af66fc99e Initial load
duke
parents:
diff changeset
617 // OopMapCacheEntry *to = entry_at(probe + i);
a61af66fc99e Initial load
duke
parents:
diff changeset
618 // OopMapCacheEntry *from = entry_at(probe + i - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
619 // to->copy(from);
a61af66fc99e Initial load
duke
parents:
diff changeset
620 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
621
a61af66fc99e Initial load
duke
parents:
diff changeset
622 assert(method->is_method(), "gaga");
a61af66fc99e Initial load
duke
parents:
diff changeset
623
a61af66fc99e Initial load
duke
parents:
diff changeset
624 entry = entry_at(probe + 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
625 entry->fill(method, bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
626
a61af66fc99e Initial load
duke
parents:
diff changeset
627 // Copy the newly cached entry to input parameter
a61af66fc99e Initial load
duke
parents:
diff changeset
628 entry_for->resource_copy(entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
629
a61af66fc99e Initial load
duke
parents:
diff changeset
630 if (TraceOopMapGeneration) {
a61af66fc99e Initial load
duke
parents:
diff changeset
631 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
632 tty->print("Done with ");
a61af66fc99e Initial load
duke
parents:
diff changeset
633 method->print_value(); tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
634 }
a61af66fc99e Initial load
duke
parents:
diff changeset
635 assert(!entry_for->is_empty(), "A non-empty oop map should be returned");
a61af66fc99e Initial load
duke
parents:
diff changeset
636
a61af66fc99e Initial load
duke
parents:
diff changeset
637 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
638 }
a61af66fc99e Initial load
duke
parents:
diff changeset
639
a61af66fc99e Initial load
duke
parents:
diff changeset
640 void OopMapCache::compute_one_oop_map(methodHandle method, int bci, InterpreterOopMap* entry) {
a61af66fc99e Initial load
duke
parents:
diff changeset
641 // Due to the invariants above it's tricky to allocate a temporary OopMapCacheEntry on the stack
a61af66fc99e Initial load
duke
parents:
diff changeset
642 OopMapCacheEntry* tmp = NEW_C_HEAP_ARRAY(OopMapCacheEntry, 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
643 tmp->initialize();
a61af66fc99e Initial load
duke
parents:
diff changeset
644 tmp->fill(method, bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
645 entry->resource_copy(tmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
646 FREE_C_HEAP_ARRAY(OopMapCacheEntry, tmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
647 }