annotate src/share/vm/code/oopRecorder.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 e9ff18c4ace7
children da91efe96a93
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1579
jrose
parents: 1552 1563
diff changeset
2 * Copyright (c) 1998, 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: 1579
diff changeset
25 #ifndef SHARE_VM_CODE_OOPRECORDER_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1579
diff changeset
26 #define SHARE_VM_CODE_OOPRECORDER_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1579
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1579
diff changeset
28 #include "runtime/handles.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1579
diff changeset
29 #include "utilities/growableArray.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1579
diff changeset
30
0
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // Recording and retrieval of oop relocations in compiled code.
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 class CodeBlob;
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 class OopRecorder : public ResourceObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
36 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // A two-way mapping from positive indexes to oop handles.
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // The zero index is reserved for a constant (sharable) null.
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // Indexes may not be negative.
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // Use the given arena to manage storage, if not NULL.
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // By default, uses the current ResourceArea.
a61af66fc99e Initial load
duke
parents:
diff changeset
43 OopRecorder(Arena* arena = NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // Generate a new index on which CodeBlob::oop_addr_at will work.
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // allocate_index and find_index never return the same index,
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // and allocate_index never returns the same index twice.
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // In fact, two successive calls to allocate_index return successive ints.
a61af66fc99e Initial load
duke
parents:
diff changeset
49 int allocate_index(jobject h) {
a61af66fc99e Initial load
duke
parents:
diff changeset
50 return add_handle(h, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
51 }
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // For a given jobject, this will return the same index repeatedly.
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // The index can later be given to oop_at to retrieve the oop.
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // However, the oop must not be changed via CodeBlob::oop_addr_at.
a61af66fc99e Initial load
duke
parents:
diff changeset
56 int find_index(jobject h) {
a61af66fc99e Initial load
duke
parents:
diff changeset
57 int index = maybe_find_index(h);
a61af66fc99e Initial load
duke
parents:
diff changeset
58 if (index < 0) { // previously unallocated
a61af66fc99e Initial load
duke
parents:
diff changeset
59 index = add_handle(h, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
60 }
a61af66fc99e Initial load
duke
parents:
diff changeset
61 return index;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 }
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // variant of find_index which does not allocate if not found (yields -1)
a61af66fc99e Initial load
duke
parents:
diff changeset
65 int maybe_find_index(jobject h);
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 // returns the size of the generated oop table, for sizing the CodeBlob.
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // must be called after all oops are allocated!
a61af66fc99e Initial load
duke
parents:
diff changeset
69 int oop_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 // Retrieve the oop handle at a given index.
a61af66fc99e Initial load
duke
parents:
diff changeset
72 jobject handle_at(int index);
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 int element_count() {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 // there is always a NULL virtually present as first object
a61af66fc99e Initial load
duke
parents:
diff changeset
76 return _handles->length() + first_index;
a61af66fc99e Initial load
duke
parents:
diff changeset
77 }
a61af66fc99e Initial load
duke
parents:
diff changeset
78
1563
1a5913bf5e19 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 0
diff changeset
79 // copy the generated oop table to nmethod
1a5913bf5e19 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 0
diff changeset
80 void copy_to(nmethod* nm); // => nm->copy_oops(_handles)
0
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 bool is_unused() { return _handles == NULL && !_complete; }
a61af66fc99e Initial load
duke
parents:
diff changeset
83 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
84 bool is_complete() { return _complete; }
a61af66fc99e Initial load
duke
parents:
diff changeset
85 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // leaky hash table of handle => index, to help detect duplicate insertion
a61af66fc99e Initial load
duke
parents:
diff changeset
89 class IndexCache: public ResourceObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 // This class is only used by the OopRecorder class.
a61af66fc99e Initial load
duke
parents:
diff changeset
91 friend class OopRecorder;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 enum {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 _log_cache_size = 9,
a61af66fc99e Initial load
duke
parents:
diff changeset
94 _cache_size = (1<<_log_cache_size),
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // Index entries are ints. The LSBit is a collision indicator.
a61af66fc99e Initial load
duke
parents:
diff changeset
96 _collision_bit_shift = 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
97 _collision_bit = 1,
a61af66fc99e Initial load
duke
parents:
diff changeset
98 _index_shift = _collision_bit_shift+1
a61af66fc99e Initial load
duke
parents:
diff changeset
99 };
a61af66fc99e Initial load
duke
parents:
diff changeset
100 int _cache[_cache_size];
a61af66fc99e Initial load
duke
parents:
diff changeset
101 static juint cache_index(jobject handle) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 juint ci = (int) (intptr_t) handle;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 ci ^= ci >> (BitsPerByte*2);
a61af66fc99e Initial load
duke
parents:
diff changeset
104 ci += ci >> (BitsPerByte*1);
a61af66fc99e Initial load
duke
parents:
diff changeset
105 return ci & (_cache_size-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107 int* cache_location(jobject handle) {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 return &_cache[ cache_index(handle) ];
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110 static bool cache_location_collision(int* cloc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 return ((*cloc) & _collision_bit) != 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 static int cache_location_index(int* cloc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 return (*cloc) >> _index_shift;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116 static void set_cache_location_index(int* cloc, int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 int cval0 = (*cloc);
a61af66fc99e Initial load
duke
parents:
diff changeset
118 int cval1 = (index << _index_shift);
a61af66fc99e Initial load
duke
parents:
diff changeset
119 if (cval0 != 0 && cval1 != cval0) cval1 += _collision_bit;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 (*cloc) = cval1;
a61af66fc99e Initial load
duke
parents:
diff changeset
121 }
a61af66fc99e Initial load
duke
parents:
diff changeset
122 IndexCache();
a61af66fc99e Initial load
duke
parents:
diff changeset
123 };
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // Helper function; returns false for NULL or Universe::non_oop_word().
a61af66fc99e Initial load
duke
parents:
diff changeset
126 inline bool is_real_jobject(jobject h);
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 void maybe_initialize();
a61af66fc99e Initial load
duke
parents:
diff changeset
129 int add_handle(jobject h, bool make_findable);
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 enum { null_index = 0, first_index = 1, index_cache_threshold = 20 };
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 GrowableArray<jobject>* _handles; // ordered list (first is always NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
134 GrowableArray<int>* _no_finds; // all unfindable indexes; usually empty
a61af66fc99e Initial load
duke
parents:
diff changeset
135 IndexCache* _indexes; // map: jobject -> its probable index
a61af66fc99e Initial load
duke
parents:
diff changeset
136 Arena* _arena;
a61af66fc99e Initial load
duke
parents:
diff changeset
137 bool _complete;
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
140 static int _find_index_calls, _hit_indexes, _missed_indexes;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
142 };
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1579
diff changeset
143
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1579
diff changeset
144 #endif // SHARE_VM_CODE_OOPRECORDER_HPP