author | sspitsyn |
Thu, 10 Jul 2014 17:46:35 -0700 | |
changeset 25626 | 362d0c3a7651 |
parent 25473 | 185aff4215a4 |
child 33063 | 9e222337a81e |
permissions | -rw-r--r-- |
1 | 1 |
/* |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
2 |
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#ifndef SHARE_VM_INTERPRETER_OOPMAPCACHE_HPP |
26 |
#define SHARE_VM_INTERPRETER_OOPMAPCACHE_HPP |
|
27 |
||
28 |
#include "oops/generateOopMap.hpp" |
|
7408
c04a5c989f26
7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents:
7397
diff
changeset
|
29 |
#include "runtime/mutex.hpp" |
7397 | 30 |
|
1 | 31 |
// A Cache for storing (method, bci) -> oopMap. |
32 |
// The memory management system uses the cache when locating object |
|
33 |
// references in an interpreted frame. |
|
34 |
// |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
35 |
// OopMapCache's are allocated lazily per InstanceKlass. |
1 | 36 |
|
37 |
// The oopMap (InterpreterOopMap) is stored as a bit mask. If the |
|
38 |
// bit_mask can fit into two words it is stored in |
|
39 |
// the _bit_mask array, otherwise it is allocated on the heap. |
|
40 |
// For OopMapCacheEntry the bit_mask is allocated in the C heap |
|
41 |
// because these entries persist between garbage collections. |
|
42 |
// For InterpreterOopMap the bit_mask is allocated in |
|
43 |
// a resource area for better performance. InterpreterOopMap |
|
44 |
// should only be created and deleted during same garbage collection. |
|
45 |
// |
|
46 |
// If ENABBLE_ZAP_DEAD_LOCALS is defined, two bits are used |
|
47 |
// per entry instead of one. In all cases, |
|
48 |
// the first bit is set to indicate oops as opposed to other |
|
49 |
// values. If the second bit is available, |
|
50 |
// it is set for dead values. We get the following encoding: |
|
51 |
// |
|
52 |
// 00 live value |
|
53 |
// 01 live oop |
|
54 |
// 10 dead value |
|
55 |
// 11 <unused> (we cannot distinguish between dead oops or values with the current oop map generator) |
|
56 |
||
57 |
||
58 |
class OffsetClosure { |
|
59 |
public: |
|
60 |
virtual void offset_do(int offset) = 0; |
|
61 |
}; |
|
62 |
||
63 |
||
64 |
class InterpreterOopMap: ResourceObj { |
|
65 |
friend class OopMapCache; |
|
66 |
||
67 |
public: |
|
68 |
enum { |
|
25626
362d0c3a7651
8013942: JSR 292: assert(type() == T_OBJECT) failed: type check
sspitsyn
parents:
25473
diff
changeset
|
69 |
N = 4, // the number of words reserved |
1 | 70 |
// for inlined mask storage |
71 |
small_mask_limit = N * BitsPerWord, // the maximum number of bits |
|
72 |
// available for small masks, |
|
73 |
// small_mask_limit can be set to 0 |
|
74 |
// for testing bit_mask allocation |
|
75 |
||
76 |
bits_per_entry = 2, |
|
77 |
dead_bit_number = 1, |
|
78 |
oop_bit_number = 0 |
|
79 |
}; |
|
80 |
||
81 |
private: |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
82 |
Method* _method; // the method for which the mask is valid |
1 | 83 |
unsigned short _bci; // the bci for which the mask is valid |
84 |
int _mask_size; // the mask size in bits |
|
85 |
int _expression_stack_size; // the size of the expression stack in slots |
|
86 |
||
87 |
protected: |
|
88 |
intptr_t _bit_mask[N]; // the bit mask if |
|
89 |
// mask_size <= small_mask_limit, |
|
90 |
// ptr to bit mask otherwise |
|
91 |
// "protected" so that sub classes can |
|
92 |
// access it without using trickery in |
|
93 |
// methd bit_mask(). |
|
94 |
#ifdef ASSERT |
|
95 |
bool _resource_allocate_bit_mask; |
|
96 |
#endif |
|
97 |
||
98 |
// access methods |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
99 |
Method* method() const { return _method; } |
25473
185aff4215a4
8039905: heapdump/OnOOMToFile and heapdump/OnOOMToPath fail with "assert(fr().interpreter_frame_expression_stack_size() >= length) failed: error in expression stack!"
mgronlun
parents:
13728
diff
changeset
|
100 |
void set_method(Method* v) { _method = v; } |
1 | 101 |
int bci() const { return _bci; } |
102 |
void set_bci(int v) { _bci = v; } |
|
103 |
int mask_size() const { return _mask_size; } |
|
104 |
void set_mask_size(int v) { _mask_size = v; } |
|
105 |
// Test bit mask size and return either the in-line bit mask or allocated |
|
106 |
// bit mask. |
|
25473
185aff4215a4
8039905: heapdump/OnOOMToFile and heapdump/OnOOMToPath fail with "assert(fr().interpreter_frame_expression_stack_size() >= length) failed: error in expression stack!"
mgronlun
parents:
13728
diff
changeset
|
107 |
uintptr_t* bit_mask() const { return (uintptr_t*)(mask_size() <= small_mask_limit ? (intptr_t)_bit_mask : _bit_mask[0]); } |
1 | 108 |
|
109 |
// return the word size of_bit_mask. mask_size() <= 4 * MAX_USHORT |
|
25473
185aff4215a4
8039905: heapdump/OnOOMToFile and heapdump/OnOOMToPath fail with "assert(fr().interpreter_frame_expression_stack_size() >= length) failed: error in expression stack!"
mgronlun
parents:
13728
diff
changeset
|
110 |
size_t mask_word_size() const { |
1 | 111 |
return (mask_size() + BitsPerWord - 1) / BitsPerWord; |
112 |
} |
|
113 |
||
25473
185aff4215a4
8039905: heapdump/OnOOMToFile and heapdump/OnOOMToPath fail with "assert(fr().interpreter_frame_expression_stack_size() >= length) failed: error in expression stack!"
mgronlun
parents:
13728
diff
changeset
|
114 |
uintptr_t entry_at(int offset) const { int i = offset * bits_per_entry; return bit_mask()[i / BitsPerWord] >> (i % BitsPerWord); } |
1 | 115 |
|
25473
185aff4215a4
8039905: heapdump/OnOOMToFile and heapdump/OnOOMToPath fail with "assert(fr().interpreter_frame_expression_stack_size() >= length) failed: error in expression stack!"
mgronlun
parents:
13728
diff
changeset
|
116 |
void set_expression_stack_size(int sz) { _expression_stack_size = sz; } |
1 | 117 |
|
118 |
// Lookup |
|
25473
185aff4215a4
8039905: heapdump/OnOOMToFile and heapdump/OnOOMToPath fail with "assert(fr().interpreter_frame_expression_stack_size() >= length) failed: error in expression stack!"
mgronlun
parents:
13728
diff
changeset
|
119 |
bool match(methodHandle method, int bci) const { return _method == method() && _bci == bci; } |
185aff4215a4
8039905: heapdump/OnOOMToFile and heapdump/OnOOMToPath fail with "assert(fr().interpreter_frame_expression_stack_size() >= length) failed: error in expression stack!"
mgronlun
parents:
13728
diff
changeset
|
120 |
bool is_empty() const; |
1 | 121 |
|
122 |
// Initialization |
|
123 |
void initialize(); |
|
124 |
||
125 |
public: |
|
126 |
InterpreterOopMap(); |
|
127 |
~InterpreterOopMap(); |
|
128 |
||
129 |
// Copy the OopMapCacheEntry in parameter "from" into this |
|
130 |
// InterpreterOopMap. If the _bit_mask[0] in "from" points to |
|
131 |
// allocated space (i.e., the bit mask was to large to hold |
|
132 |
// in-line), allocate the space from a Resource area. |
|
133 |
void resource_copy(OopMapCacheEntry* from); |
|
134 |
||
25473
185aff4215a4
8039905: heapdump/OnOOMToFile and heapdump/OnOOMToPath fail with "assert(fr().interpreter_frame_expression_stack_size() >= length) failed: error in expression stack!"
mgronlun
parents:
13728
diff
changeset
|
135 |
void iterate_oop(OffsetClosure* oop_closure) const; |
185aff4215a4
8039905: heapdump/OnOOMToFile and heapdump/OnOOMToPath fail with "assert(fr().interpreter_frame_expression_stack_size() >= length) failed: error in expression stack!"
mgronlun
parents:
13728
diff
changeset
|
136 |
void print() const; |
1 | 137 |
|
25473
185aff4215a4
8039905: heapdump/OnOOMToFile and heapdump/OnOOMToPath fail with "assert(fr().interpreter_frame_expression_stack_size() >= length) failed: error in expression stack!"
mgronlun
parents:
13728
diff
changeset
|
138 |
int number_of_entries() const { return mask_size() / bits_per_entry; } |
25626
362d0c3a7651
8013942: JSR 292: assert(type() == T_OBJECT) failed: type check
sspitsyn
parents:
25473
diff
changeset
|
139 |
bool is_dead(int offset) const { return (entry_at(offset) & (1 << dead_bit_number)) != 0; } |
25473
185aff4215a4
8039905: heapdump/OnOOMToFile and heapdump/OnOOMToPath fail with "assert(fr().interpreter_frame_expression_stack_size() >= length) failed: error in expression stack!"
mgronlun
parents:
13728
diff
changeset
|
140 |
bool is_oop (int offset) const { return (entry_at(offset) & (1 << oop_bit_number )) != 0; } |
1 | 141 |
|
25473
185aff4215a4
8039905: heapdump/OnOOMToFile and heapdump/OnOOMToPath fail with "assert(fr().interpreter_frame_expression_stack_size() >= length) failed: error in expression stack!"
mgronlun
parents:
13728
diff
changeset
|
142 |
int expression_stack_size() const { return _expression_stack_size; } |
1 | 143 |
|
144 |
#ifdef ENABLE_ZAP_DEAD_LOCALS |
|
145 |
void iterate_all(OffsetClosure* oop_closure, OffsetClosure* value_closure, OffsetClosure* dead_closure); |
|
146 |
#endif |
|
147 |
}; |
|
148 |
||
13195 | 149 |
class OopMapCache : public CHeapObj<mtClass> { |
1 | 150 |
private: |
151 |
enum { _size = 32, // Use fixed size for now |
|
152 |
_probe_depth = 3 // probe depth in case of collisions |
|
153 |
}; |
|
154 |
||
155 |
OopMapCacheEntry* _array; |
|
156 |
||
25473
185aff4215a4
8039905: heapdump/OnOOMToFile and heapdump/OnOOMToPath fail with "assert(fr().interpreter_frame_expression_stack_size() >= length) failed: error in expression stack!"
mgronlun
parents:
13728
diff
changeset
|
157 |
unsigned int hash_value_for(methodHandle method, int bci) const; |
1 | 158 |
OopMapCacheEntry* entry_at(int i) const; |
159 |
||
25473
185aff4215a4
8039905: heapdump/OnOOMToFile and heapdump/OnOOMToPath fail with "assert(fr().interpreter_frame_expression_stack_size() >= length) failed: error in expression stack!"
mgronlun
parents:
13728
diff
changeset
|
160 |
mutable Mutex _mut; |
1 | 161 |
|
162 |
void flush(); |
|
163 |
||
164 |
public: |
|
165 |
OopMapCache(); |
|
166 |
~OopMapCache(); // free up memory |
|
167 |
||
168 |
// flush cache entry is occupied by an obsolete method |
|
169 |
void flush_obsolete_entries(); |
|
170 |
||
171 |
// Returns the oopMap for (method, bci) in parameter "entry". |
|
172 |
// Returns false if an oop map was not found. |
|
25473
185aff4215a4
8039905: heapdump/OnOOMToFile and heapdump/OnOOMToPath fail with "assert(fr().interpreter_frame_expression_stack_size() >= length) failed: error in expression stack!"
mgronlun
parents:
13728
diff
changeset
|
173 |
void lookup(methodHandle method, int bci, InterpreterOopMap* entry) const; |
1 | 174 |
|
175 |
// Compute an oop map without updating the cache or grabbing any locks (for debugging) |
|
176 |
static void compute_one_oop_map(methodHandle method, int bci, InterpreterOopMap* entry); |
|
177 |
||
178 |
// Returns total no. of bytes allocated as part of OopMapCache's |
|
179 |
static long memory_usage() PRODUCT_RETURN0; |
|
180 |
}; |
|
7397 | 181 |
|
182 |
#endif // SHARE_VM_INTERPRETER_OOPMAPCACHE_HPP |