Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/src/share/vm/code/oopRecorder.hpp
+++ new/src/share/vm/code/oopRecorder.hpp
1 1 /*
2 - * Copyright 1998-2005 Sun Microsystems, Inc. All Rights Reserved.
2 + * Copyright 1998-2010 Sun Microsystems, Inc. All Rights Reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation.
8 8 *
9 9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 12 * version 2 for more details (a copy is included in the LICENSE file that
13 13 * accompanied this code).
14 14 *
15 15 * You should have received a copy of the GNU General Public License version
16 16 * 2 along with this work; if not, write to the Free Software Foundation,
17 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 18 *
19 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 21 * have any questions.
22 22 *
23 23 */
24 24
25 25 // Recording and retrieval of oop relocations in compiled code.
26 26
27 27 class CodeBlob;
28 28
29 29 class OopRecorder : public ResourceObj {
30 30 public:
31 31 // A two-way mapping from positive indexes to oop handles.
32 32 // The zero index is reserved for a constant (sharable) null.
33 33 // Indexes may not be negative.
34 34
35 35 // Use the given arena to manage storage, if not NULL.
36 36 // By default, uses the current ResourceArea.
37 37 OopRecorder(Arena* arena = NULL);
38 38
39 39 // Generate a new index on which CodeBlob::oop_addr_at will work.
40 40 // allocate_index and find_index never return the same index,
41 41 // and allocate_index never returns the same index twice.
42 42 // In fact, two successive calls to allocate_index return successive ints.
43 43 int allocate_index(jobject h) {
44 44 return add_handle(h, false);
45 45 }
46 46
47 47 // For a given jobject, this will return the same index repeatedly.
48 48 // The index can later be given to oop_at to retrieve the oop.
49 49 // However, the oop must not be changed via CodeBlob::oop_addr_at.
50 50 int find_index(jobject h) {
51 51 int index = maybe_find_index(h);
52 52 if (index < 0) { // previously unallocated
53 53 index = add_handle(h, true);
54 54 }
55 55 return index;
56 56 }
57 57
58 58 // variant of find_index which does not allocate if not found (yields -1)
59 59 int maybe_find_index(jobject h);
60 60
61 61 // returns the size of the generated oop table, for sizing the CodeBlob.
62 62 // must be called after all oops are allocated!
↓ open down ↓ |
50 lines elided |
↑ open up ↑ |
63 63 int oop_size();
64 64
65 65 // Retrieve the oop handle at a given index.
66 66 jobject handle_at(int index);
67 67
68 68 int element_count() {
69 69 // there is always a NULL virtually present as first object
70 70 return _handles->length() + first_index;
71 71 }
72 72
73 - // copy the generated oop table to CodeBlob
74 - void copy_to(CodeBlob* code); // => code->copy_oops(_handles)
73 + // copy the generated oop table to nmethod
74 + void copy_to(nmethod* nm); // => nm->copy_oops(_handles)
75 75
76 76 bool is_unused() { return _handles == NULL && !_complete; }
77 77 #ifdef ASSERT
78 78 bool is_complete() { return _complete; }
79 79 #endif
80 80
81 81 private:
82 82 // leaky hash table of handle => index, to help detect duplicate insertion
83 83 class IndexCache: public ResourceObj {
84 84 // This class is only used by the OopRecorder class.
85 85 friend class OopRecorder;
86 86 enum {
87 87 _log_cache_size = 9,
88 88 _cache_size = (1<<_log_cache_size),
89 89 // Index entries are ints. The LSBit is a collision indicator.
90 90 _collision_bit_shift = 0,
91 91 _collision_bit = 1,
92 92 _index_shift = _collision_bit_shift+1
93 93 };
94 94 int _cache[_cache_size];
95 95 static juint cache_index(jobject handle) {
96 96 juint ci = (int) (intptr_t) handle;
97 97 ci ^= ci >> (BitsPerByte*2);
98 98 ci += ci >> (BitsPerByte*1);
99 99 return ci & (_cache_size-1);
100 100 }
101 101 int* cache_location(jobject handle) {
102 102 return &_cache[ cache_index(handle) ];
103 103 }
104 104 static bool cache_location_collision(int* cloc) {
105 105 return ((*cloc) & _collision_bit) != 0;
106 106 }
107 107 static int cache_location_index(int* cloc) {
108 108 return (*cloc) >> _index_shift;
109 109 }
110 110 static void set_cache_location_index(int* cloc, int index) {
111 111 int cval0 = (*cloc);
112 112 int cval1 = (index << _index_shift);
113 113 if (cval0 != 0 && cval1 != cval0) cval1 += _collision_bit;
114 114 (*cloc) = cval1;
115 115 }
116 116 IndexCache();
117 117 };
118 118
119 119 // Helper function; returns false for NULL or Universe::non_oop_word().
120 120 inline bool is_real_jobject(jobject h);
121 121
122 122 void maybe_initialize();
123 123 int add_handle(jobject h, bool make_findable);
124 124
125 125 enum { null_index = 0, first_index = 1, index_cache_threshold = 20 };
126 126
127 127 GrowableArray<jobject>* _handles; // ordered list (first is always NULL)
128 128 GrowableArray<int>* _no_finds; // all unfindable indexes; usually empty
129 129 IndexCache* _indexes; // map: jobject -> its probable index
130 130 Arena* _arena;
131 131 bool _complete;
132 132
133 133 #ifdef ASSERT
134 134 static int _find_index_calls, _hit_indexes, _missed_indexes;
135 135 #endif
136 136 };
↓ open down ↓ |
52 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX