annotate src/share/vm/code/oopRecorder.hpp @ 1721:413ad0331a0c

6977924: Changes for 6975078 produce build error with certain gcc versions Summary: The changes introduced for 6975078 assign badHeapOopVal to the _allocation field in the ResourceObj class. In 32 bit linux builds with certain versions of gcc this assignment will be flagged as an error while compiling allocation.cpp. In 32 bit builds the constant value badHeapOopVal (which is cast to an intptr_t) is negative. The _allocation field is typed as an unsigned intptr_t and gcc catches this as an error. Reviewed-by: jcoomes, ysr, phh
author johnc
date Wed, 18 Aug 2010 10:59:06 -0700
parents e9ff18c4ace7
children f95d63e2154a
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
a61af66fc99e Initial load
duke
parents:
diff changeset
25 // Recording and retrieval of oop relocations in compiled code.
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 class CodeBlob;
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 class OopRecorder : public ResourceObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
30 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // A two-way mapping from positive indexes to oop handles.
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // The zero index is reserved for a constant (sharable) null.
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // Indexes may not be negative.
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // Use the given arena to manage storage, if not NULL.
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // By default, uses the current ResourceArea.
a61af66fc99e Initial load
duke
parents:
diff changeset
37 OopRecorder(Arena* arena = NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // Generate a new index on which CodeBlob::oop_addr_at will work.
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // allocate_index and find_index never return the same index,
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // and allocate_index never returns the same index twice.
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // In fact, two successive calls to allocate_index return successive ints.
a61af66fc99e Initial load
duke
parents:
diff changeset
43 int allocate_index(jobject h) {
a61af66fc99e Initial load
duke
parents:
diff changeset
44 return add_handle(h, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
45 }
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // For a given jobject, this will return the same index repeatedly.
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // The index can later be given to oop_at to retrieve the oop.
a61af66fc99e Initial load
duke
parents:
diff changeset
49 // However, the oop must not be changed via CodeBlob::oop_addr_at.
a61af66fc99e Initial load
duke
parents:
diff changeset
50 int find_index(jobject h) {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 int index = maybe_find_index(h);
a61af66fc99e Initial load
duke
parents:
diff changeset
52 if (index < 0) { // previously unallocated
a61af66fc99e Initial load
duke
parents:
diff changeset
53 index = add_handle(h, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
54 }
a61af66fc99e Initial load
duke
parents:
diff changeset
55 return index;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 }
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 // variant of find_index which does not allocate if not found (yields -1)
a61af66fc99e Initial load
duke
parents:
diff changeset
59 int maybe_find_index(jobject h);
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 // returns the size of the generated oop table, for sizing the CodeBlob.
a61af66fc99e Initial load
duke
parents:
diff changeset
62 // must be called after all oops are allocated!
a61af66fc99e Initial load
duke
parents:
diff changeset
63 int oop_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // Retrieve the oop handle at a given index.
a61af66fc99e Initial load
duke
parents:
diff changeset
66 jobject handle_at(int index);
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 int element_count() {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 // there is always a NULL virtually present as first object
a61af66fc99e Initial load
duke
parents:
diff changeset
70 return _handles->length() + first_index;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72
1563
1a5913bf5e19 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 0
diff changeset
73 // copy the generated oop table to nmethod
1a5913bf5e19 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 0
diff changeset
74 void copy_to(nmethod* nm); // => nm->copy_oops(_handles)
0
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 bool is_unused() { return _handles == NULL && !_complete; }
a61af66fc99e Initial load
duke
parents:
diff changeset
77 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
78 bool is_complete() { return _complete; }
a61af66fc99e Initial load
duke
parents:
diff changeset
79 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
82 // leaky hash table of handle => index, to help detect duplicate insertion
a61af66fc99e Initial load
duke
parents:
diff changeset
83 class IndexCache: public ResourceObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // This class is only used by the OopRecorder class.
a61af66fc99e Initial load
duke
parents:
diff changeset
85 friend class OopRecorder;
a61af66fc99e Initial load
duke
parents:
diff changeset
86 enum {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 _log_cache_size = 9,
a61af66fc99e Initial load
duke
parents:
diff changeset
88 _cache_size = (1<<_log_cache_size),
a61af66fc99e Initial load
duke
parents:
diff changeset
89 // Index entries are ints. The LSBit is a collision indicator.
a61af66fc99e Initial load
duke
parents:
diff changeset
90 _collision_bit_shift = 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
91 _collision_bit = 1,
a61af66fc99e Initial load
duke
parents:
diff changeset
92 _index_shift = _collision_bit_shift+1
a61af66fc99e Initial load
duke
parents:
diff changeset
93 };
a61af66fc99e Initial load
duke
parents:
diff changeset
94 int _cache[_cache_size];
a61af66fc99e Initial load
duke
parents:
diff changeset
95 static juint cache_index(jobject handle) {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 juint ci = (int) (intptr_t) handle;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 ci ^= ci >> (BitsPerByte*2);
a61af66fc99e Initial load
duke
parents:
diff changeset
98 ci += ci >> (BitsPerByte*1);
a61af66fc99e Initial load
duke
parents:
diff changeset
99 return ci & (_cache_size-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101 int* cache_location(jobject handle) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 return &_cache[ cache_index(handle) ];
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104 static bool cache_location_collision(int* cloc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 return ((*cloc) & _collision_bit) != 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107 static int cache_location_index(int* cloc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 return (*cloc) >> _index_shift;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110 static void set_cache_location_index(int* cloc, int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 int cval0 = (*cloc);
a61af66fc99e Initial load
duke
parents:
diff changeset
112 int cval1 = (index << _index_shift);
a61af66fc99e Initial load
duke
parents:
diff changeset
113 if (cval0 != 0 && cval1 != cval0) cval1 += _collision_bit;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 (*cloc) = cval1;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116 IndexCache();
a61af66fc99e Initial load
duke
parents:
diff changeset
117 };
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // Helper function; returns false for NULL or Universe::non_oop_word().
a61af66fc99e Initial load
duke
parents:
diff changeset
120 inline bool is_real_jobject(jobject h);
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 void maybe_initialize();
a61af66fc99e Initial load
duke
parents:
diff changeset
123 int add_handle(jobject h, bool make_findable);
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 enum { null_index = 0, first_index = 1, index_cache_threshold = 20 };
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 GrowableArray<jobject>* _handles; // ordered list (first is always NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
128 GrowableArray<int>* _no_finds; // all unfindable indexes; usually empty
a61af66fc99e Initial load
duke
parents:
diff changeset
129 IndexCache* _indexes; // map: jobject -> its probable index
a61af66fc99e Initial load
duke
parents:
diff changeset
130 Arena* _arena;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 bool _complete;
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
134 static int _find_index_calls, _hit_indexes, _missed_indexes;
a61af66fc99e Initial load
duke
parents:
diff changeset
135 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
136 };