annotate src/share/vm/interpreter/oopMapCache.hpp @ 1972:f95d63e2154a

6989984: Use standard include model for Hospot Summary: Replaced MakeDeps and the includeDB files with more standardized solutions. Reviewed-by: coleenp, kvn, kamg
author stefank
date Tue, 23 Nov 2010 13:22:55 -0800
parents c18cbe5936b8
children c760f78e0a53
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: 1552
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: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
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: 0
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_INTERPRETER_OOPMAPCACHE_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #define SHARE_VM_INTERPRETER_OOPMAPCACHE_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/generateOopMap.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29
0
a61af66fc99e Initial load
duke
parents:
diff changeset
30 // A Cache for storing (method, bci) -> oopMap.
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // The memory management system uses the cache when locating object
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // references in an interpreted frame.
a61af66fc99e Initial load
duke
parents:
diff changeset
33 //
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // OopMapCache's are allocated lazily per instanceKlass.
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // The oopMap (InterpreterOopMap) is stored as a bit mask. If the
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // bit_mask can fit into two words it is stored in
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // the _bit_mask array, otherwise it is allocated on the heap.
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // For OopMapCacheEntry the bit_mask is allocated in the C heap
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // because these entries persist between garbage collections.
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // For InterpreterOopMap the bit_mask is allocated in
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // a resource area for better performance. InterpreterOopMap
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // should only be created and deleted during same garbage collection.
a61af66fc99e Initial load
duke
parents:
diff changeset
44 //
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // If ENABBLE_ZAP_DEAD_LOCALS is defined, two bits are used
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // per entry instead of one. In all cases,
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // the first bit is set to indicate oops as opposed to other
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // values. If the second bit is available,
a61af66fc99e Initial load
duke
parents:
diff changeset
49 // it is set for dead values. We get the following encoding:
a61af66fc99e Initial load
duke
parents:
diff changeset
50 //
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // 00 live value
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // 01 live oop
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // 10 dead value
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // 11 <unused> (we cannot distinguish between dead oops or values with the current oop map generator)
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 class OffsetClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
59 virtual void offset_do(int offset) = 0;
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 class InterpreterOopMap: ResourceObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 friend class OopMapCache;
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
67 enum {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 N = 2, // the number of words reserved
a61af66fc99e Initial load
duke
parents:
diff changeset
69 // for inlined mask storage
a61af66fc99e Initial load
duke
parents:
diff changeset
70 small_mask_limit = N * BitsPerWord, // the maximum number of bits
a61af66fc99e Initial load
duke
parents:
diff changeset
71 // available for small masks,
a61af66fc99e Initial load
duke
parents:
diff changeset
72 // small_mask_limit can be set to 0
a61af66fc99e Initial load
duke
parents:
diff changeset
73 // for testing bit_mask allocation
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 #ifdef ENABLE_ZAP_DEAD_LOCALS
a61af66fc99e Initial load
duke
parents:
diff changeset
76 bits_per_entry = 2,
a61af66fc99e Initial load
duke
parents:
diff changeset
77 dead_bit_number = 1,
a61af66fc99e Initial load
duke
parents:
diff changeset
78 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
79 bits_per_entry = 1,
a61af66fc99e Initial load
duke
parents:
diff changeset
80 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
81 oop_bit_number = 0
a61af66fc99e Initial load
duke
parents:
diff changeset
82 };
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
85 methodOop _method; // the method for which the mask is valid
a61af66fc99e Initial load
duke
parents:
diff changeset
86 unsigned short _bci; // the bci for which the mask is valid
a61af66fc99e Initial load
duke
parents:
diff changeset
87 int _mask_size; // the mask size in bits
a61af66fc99e Initial load
duke
parents:
diff changeset
88 int _expression_stack_size; // the size of the expression stack in slots
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
91 intptr_t _bit_mask[N]; // the bit mask if
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // mask_size <= small_mask_limit,
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // ptr to bit mask otherwise
a61af66fc99e Initial load
duke
parents:
diff changeset
94 // "protected" so that sub classes can
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // access it without using trickery in
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // methd bit_mask().
a61af66fc99e Initial load
duke
parents:
diff changeset
97 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
98 bool _resource_allocate_bit_mask;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // access methods
a61af66fc99e Initial load
duke
parents:
diff changeset
102 methodOop method() const { return _method; }
a61af66fc99e Initial load
duke
parents:
diff changeset
103 void set_method(methodOop v) { _method = v; }
a61af66fc99e Initial load
duke
parents:
diff changeset
104 int bci() const { return _bci; }
a61af66fc99e Initial load
duke
parents:
diff changeset
105 void set_bci(int v) { _bci = v; }
a61af66fc99e Initial load
duke
parents:
diff changeset
106 int mask_size() const { return _mask_size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
107 void set_mask_size(int v) { _mask_size = v; }
a61af66fc99e Initial load
duke
parents:
diff changeset
108 int number_of_entries() const { return mask_size() / bits_per_entry; }
a61af66fc99e Initial load
duke
parents:
diff changeset
109 // Test bit mask size and return either the in-line bit mask or allocated
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // bit mask.
a61af66fc99e Initial load
duke
parents:
diff changeset
111 uintptr_t* bit_mask() { return (uintptr_t*)(mask_size() <= small_mask_limit ? (intptr_t)_bit_mask : _bit_mask[0]); }
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 // return the word size of_bit_mask. mask_size() <= 4 * MAX_USHORT
a61af66fc99e Initial load
duke
parents:
diff changeset
114 size_t mask_word_size() {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 return (mask_size() + BitsPerWord - 1) / BitsPerWord;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 uintptr_t entry_at(int offset) { int i = offset * bits_per_entry; return bit_mask()[i / BitsPerWord] >> (i % BitsPerWord); }
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 void set_expression_stack_size(int sz) { _expression_stack_size = sz; }
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 #ifdef ENABLE_ZAP_DEAD_LOCALS
a61af66fc99e Initial load
duke
parents:
diff changeset
123 bool is_dead(int offset) { return (entry_at(offset) & (1 << dead_bit_number)) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
124 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // Lookup
a61af66fc99e Initial load
duke
parents:
diff changeset
127 bool match(methodHandle method, int bci) { return _method == method() && _bci == bci; }
a61af66fc99e Initial load
duke
parents:
diff changeset
128 bool is_empty();
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 // Initialization
a61af66fc99e Initial load
duke
parents:
diff changeset
131 void initialize();
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
134 InterpreterOopMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
135 ~InterpreterOopMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 // Copy the OopMapCacheEntry in parameter "from" into this
a61af66fc99e Initial load
duke
parents:
diff changeset
138 // InterpreterOopMap. If the _bit_mask[0] in "from" points to
a61af66fc99e Initial load
duke
parents:
diff changeset
139 // allocated space (i.e., the bit mask was to large to hold
a61af66fc99e Initial load
duke
parents:
diff changeset
140 // in-line), allocate the space from a Resource area.
a61af66fc99e Initial load
duke
parents:
diff changeset
141 void resource_copy(OopMapCacheEntry* from);
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 void iterate_oop(OffsetClosure* oop_closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
144 void oop_iterate(OopClosure * blk);
a61af66fc99e Initial load
duke
parents:
diff changeset
145 void oop_iterate(OopClosure * blk, MemRegion mr);
a61af66fc99e Initial load
duke
parents:
diff changeset
146 void verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
147 void print();
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149 bool is_oop (int offset) { return (entry_at(offset) & (1 << oop_bit_number )) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 int expression_stack_size() { return _expression_stack_size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
152
a61af66fc99e Initial load
duke
parents:
diff changeset
153 #ifdef ENABLE_ZAP_DEAD_LOCALS
a61af66fc99e Initial load
duke
parents:
diff changeset
154 void iterate_all(OffsetClosure* oop_closure, OffsetClosure* value_closure, OffsetClosure* dead_closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
155 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
156 };
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 class OopMapCache : public CHeapObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
159 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
160 enum { _size = 32, // Use fixed size for now
a61af66fc99e Initial load
duke
parents:
diff changeset
161 _probe_depth = 3 // probe depth in case of collisions
a61af66fc99e Initial load
duke
parents:
diff changeset
162 };
a61af66fc99e Initial load
duke
parents:
diff changeset
163
a61af66fc99e Initial load
duke
parents:
diff changeset
164 OopMapCacheEntry* _array;
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 unsigned int hash_value_for(methodHandle method, int bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
167 OopMapCacheEntry* entry_at(int i) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 Mutex _mut;
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171 void flush();
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
174 OopMapCache();
a61af66fc99e Initial load
duke
parents:
diff changeset
175 ~OopMapCache(); // free up memory
a61af66fc99e Initial load
duke
parents:
diff changeset
176
a61af66fc99e Initial load
duke
parents:
diff changeset
177 // flush cache entry is occupied by an obsolete method
a61af66fc99e Initial load
duke
parents:
diff changeset
178 void flush_obsolete_entries();
a61af66fc99e Initial load
duke
parents:
diff changeset
179
a61af66fc99e Initial load
duke
parents:
diff changeset
180 // Returns the oopMap for (method, bci) in parameter "entry".
a61af66fc99e Initial load
duke
parents:
diff changeset
181 // Returns false if an oop map was not found.
a61af66fc99e Initial load
duke
parents:
diff changeset
182 void lookup(methodHandle method, int bci, InterpreterOopMap* entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
183
a61af66fc99e Initial load
duke
parents:
diff changeset
184 // Compute an oop map without updating the cache or grabbing any locks (for debugging)
a61af66fc99e Initial load
duke
parents:
diff changeset
185 static void compute_one_oop_map(methodHandle method, int bci, InterpreterOopMap* entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 // Helpers
a61af66fc99e Initial load
duke
parents:
diff changeset
188 // Iterate over the entries in the cached OopMapCacheEntry's
a61af66fc99e Initial load
duke
parents:
diff changeset
189 void oop_iterate(OopClosure *blk);
a61af66fc99e Initial load
duke
parents:
diff changeset
190 void oop_iterate(OopClosure *blk, MemRegion mr);
a61af66fc99e Initial load
duke
parents:
diff changeset
191 void verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
192
a61af66fc99e Initial load
duke
parents:
diff changeset
193 // Returns total no. of bytes allocated as part of OopMapCache's
a61af66fc99e Initial load
duke
parents:
diff changeset
194 static long memory_usage() PRODUCT_RETURN0;
a61af66fc99e Initial load
duke
parents:
diff changeset
195 };
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
196
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
197 #endif // SHARE_VM_INTERPRETER_OOPMAPCACHE_HPP