annotate src/share/vm/code/oopRecorder.cpp @ 196:d1605aabd0a1 jdk7-b30

6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
author xdono
date Wed, 02 Jul 2008 12:55:16 -0700
parents a61af66fc99e
children c18cbe5936b8 1a5913bf5e19
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved.
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 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
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 # include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 # include "incls/_oopRecorder.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
29 int OopRecorder::_find_index_calls = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 int OopRecorder::_hit_indexes = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 int OopRecorder::_missed_indexes = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 #endif //ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 OopRecorder::OopRecorder(Arena* arena) {
a61af66fc99e Initial load
duke
parents:
diff changeset
36 _handles = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 _indexes = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 _arena = arena;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 _complete = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 }
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 OopRecorder::IndexCache::IndexCache() {
a61af66fc99e Initial load
duke
parents:
diff changeset
43 assert(first_index > 0, "initial zero state of cache must be invalid index");
a61af66fc99e Initial load
duke
parents:
diff changeset
44 Copy::zero_to_bytes(&_cache[0], sizeof(_cache));
a61af66fc99e Initial load
duke
parents:
diff changeset
45 }
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 int OopRecorder::oop_size() {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 _complete = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 if (_handles == NULL) return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 return _handles->length() * sizeof(oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
51 }
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 void OopRecorder::copy_to(CodeBlob* code) {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 assert(_complete, "must be frozen");
a61af66fc99e Initial load
duke
parents:
diff changeset
55 maybe_initialize(); // get non-null handles, even if we have no oops
a61af66fc99e Initial load
duke
parents:
diff changeset
56 code->copy_oops(_handles);
a61af66fc99e Initial load
duke
parents:
diff changeset
57 }
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 void OopRecorder::maybe_initialize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 if (_handles == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 if (_arena != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 _handles = new(_arena) GrowableArray<jobject>(_arena, 10, 0, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
63 _no_finds = new(_arena) GrowableArray<int>( _arena, 10, 0, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
64 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 _handles = new GrowableArray<jobject>(10, 0, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
66 _no_finds = new GrowableArray<int>( 10, 0, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
67 }
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69 }
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 jobject OopRecorder::handle_at(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 // there is always a NULL virtually present as first object
a61af66fc99e Initial load
duke
parents:
diff changeset
74 if (index == null_index) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 return _handles->at(index - first_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
76 }
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // Local definition. Used only in this module.
a61af66fc99e Initial load
duke
parents:
diff changeset
80 inline bool OopRecorder::is_real_jobject(jobject h) {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 return h != NULL && h != (jobject)Universe::non_oop_word();
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 int OopRecorder::add_handle(jobject h, bool make_findable) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 assert(!_complete, "cannot allocate more elements after size query");
a61af66fc99e Initial load
duke
parents:
diff changeset
87 maybe_initialize();
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // indexing uses 1 as an origin--0 means null
a61af66fc99e Initial load
duke
parents:
diff changeset
89 int index = _handles->length() + first_index;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 _handles->append(h);
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // Support correct operation of find_index().
a61af66fc99e Initial load
duke
parents:
diff changeset
93 assert(!(make_findable && !is_real_jobject(h)), "nulls are not findable");
a61af66fc99e Initial load
duke
parents:
diff changeset
94 if (make_findable) {
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // This index may be returned from find_index().
a61af66fc99e Initial load
duke
parents:
diff changeset
96 if (_indexes != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 int* cloc = _indexes->cache_location(h);
a61af66fc99e Initial load
duke
parents:
diff changeset
98 _indexes->set_cache_location_index(cloc, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
99 } else if (index == index_cache_threshold && _arena != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 _indexes = new(_arena) IndexCache();
a61af66fc99e Initial load
duke
parents:
diff changeset
101 for (int i = 0; i < _handles->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 // Load the cache with pre-existing elements.
a61af66fc99e Initial load
duke
parents:
diff changeset
103 int index0 = i + first_index;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 if (_no_finds->contains(index0)) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 int* cloc = _indexes->cache_location(_handles->at(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
106 _indexes->set_cache_location_index(cloc, index0);
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
109 } else if (is_real_jobject(h)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // Remember that this index is not to be returned from find_index().
a61af66fc99e Initial load
duke
parents:
diff changeset
111 // This case is rare, because most or all uses of allocate_index pass
a61af66fc99e Initial load
duke
parents:
diff changeset
112 // a jobject argument of NULL or Universe::non_oop_word.
a61af66fc99e Initial load
duke
parents:
diff changeset
113 // Thus, the expected length of _no_finds is zero.
a61af66fc99e Initial load
duke
parents:
diff changeset
114 _no_finds->append(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 return index;
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 int OopRecorder::maybe_find_index(jobject h) {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 debug_only(_find_index_calls++);
a61af66fc99e Initial load
duke
parents:
diff changeset
123 assert(!_complete, "cannot allocate more elements after size query");
a61af66fc99e Initial load
duke
parents:
diff changeset
124 maybe_initialize();
a61af66fc99e Initial load
duke
parents:
diff changeset
125 if (h == NULL) return null_index;
a61af66fc99e Initial load
duke
parents:
diff changeset
126 assert(is_real_jobject(h), "must be valid jobject");
a61af66fc99e Initial load
duke
parents:
diff changeset
127 int* cloc = (_indexes == NULL)? NULL: _indexes->cache_location(h);
a61af66fc99e Initial load
duke
parents:
diff changeset
128 if (cloc != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 int cindex = _indexes->cache_location_index(cloc);
a61af66fc99e Initial load
duke
parents:
diff changeset
130 if (cindex == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 return -1; // We know this handle is completely new.
a61af66fc99e Initial load
duke
parents:
diff changeset
132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
133 if (cindex >= first_index && _handles->at(cindex - first_index) == h) {
a61af66fc99e Initial load
duke
parents:
diff changeset
134 debug_only(_hit_indexes++);
a61af66fc99e Initial load
duke
parents:
diff changeset
135 return cindex;
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137 if (!_indexes->cache_location_collision(cloc)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 return -1; // We know the current cache occupant is unique to that cloc.
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 // Not found in cache, due to a cache collision. (Or, no cache at all.)
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // Do a linear search, most recent to oldest.
a61af66fc99e Initial load
duke
parents:
diff changeset
144 for (int i = _handles->length() - 1; i >= 0; i--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 if (_handles->at(i) == h) {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 int findex = i + first_index;
a61af66fc99e Initial load
duke
parents:
diff changeset
147 if (_no_finds->contains(findex)) continue; // oops; skip this one
a61af66fc99e Initial load
duke
parents:
diff changeset
148 if (cloc != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
149 _indexes->set_cache_location_index(cloc, findex);
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151 debug_only(_missed_indexes++);
a61af66fc99e Initial load
duke
parents:
diff changeset
152 return findex;
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
155 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }