Mercurial > hg > graal-compiler
comparison src/share/vm/compiler/oopMap.cpp @ 0:a61af66fc99e jdk7-b24
Initial load
author | duke |
---|---|
date | Sat, 01 Dec 2007 00:00:00 +0000 |
parents | |
children | c5cbd367e4d1 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a61af66fc99e |
---|---|
1 /* | |
2 * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. | |
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 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 # include "incls/_precompiled.incl" | |
26 # include "incls/_oopMap.cpp.incl" | |
27 | |
28 // OopMapStream | |
29 | |
30 OopMapStream::OopMapStream(OopMap* oop_map) { | |
31 if(oop_map->omv_data() == NULL) { | |
32 _stream = new CompressedReadStream(oop_map->write_stream()->buffer()); | |
33 } else { | |
34 _stream = new CompressedReadStream(oop_map->omv_data()); | |
35 } | |
36 _mask = OopMapValue::type_mask_in_place; | |
37 _size = oop_map->omv_count(); | |
38 _position = 0; | |
39 _valid_omv = false; | |
40 } | |
41 | |
42 | |
43 OopMapStream::OopMapStream(OopMap* oop_map, int oop_types_mask) { | |
44 if(oop_map->omv_data() == NULL) { | |
45 _stream = new CompressedReadStream(oop_map->write_stream()->buffer()); | |
46 } else { | |
47 _stream = new CompressedReadStream(oop_map->omv_data()); | |
48 } | |
49 _mask = oop_types_mask; | |
50 _size = oop_map->omv_count(); | |
51 _position = 0; | |
52 _valid_omv = false; | |
53 } | |
54 | |
55 | |
56 void OopMapStream::find_next() { | |
57 while(_position++ < _size) { | |
58 _omv.read_from(_stream); | |
59 if(((int)_omv.type() & _mask) > 0) { | |
60 _valid_omv = true; | |
61 return; | |
62 } | |
63 } | |
64 _valid_omv = false; | |
65 } | |
66 | |
67 | |
68 // OopMap | |
69 | |
70 // frame_size units are stack-slots (4 bytes) NOT intptr_t; we can name odd | |
71 // slots to hold 4-byte values like ints and floats in the LP64 build. | |
72 OopMap::OopMap(int frame_size, int arg_count) { | |
73 // OopMaps are usually quite so small, so pick a small initial size | |
74 set_write_stream(new CompressedWriteStream(32)); | |
75 set_omv_data(NULL); | |
76 set_omv_count(0); | |
77 | |
78 #ifdef ASSERT | |
79 _locs_length = VMRegImpl::stack2reg(0)->value() + frame_size + arg_count; | |
80 _locs_used = NEW_RESOURCE_ARRAY(OopMapValue::oop_types, _locs_length); | |
81 for(int i = 0; i < _locs_length; i++) _locs_used[i] = OopMapValue::unused_value; | |
82 #endif | |
83 } | |
84 | |
85 | |
86 OopMap::OopMap(OopMap::DeepCopyToken, OopMap* source) { | |
87 // This constructor does a deep copy | |
88 // of the source OopMap. | |
89 set_write_stream(new CompressedWriteStream(source->omv_count() * 2)); | |
90 set_omv_data(NULL); | |
91 set_omv_count(0); | |
92 set_offset(source->offset()); | |
93 | |
94 #ifdef ASSERT | |
95 _locs_length = source->_locs_length; | |
96 _locs_used = NEW_RESOURCE_ARRAY(OopMapValue::oop_types, _locs_length); | |
97 for(int i = 0; i < _locs_length; i++) _locs_used[i] = OopMapValue::unused_value; | |
98 #endif | |
99 | |
100 // We need to copy the entries too. | |
101 for (OopMapStream oms(source); !oms.is_done(); oms.next()) { | |
102 OopMapValue omv = oms.current(); | |
103 omv.write_on(write_stream()); | |
104 increment_count(); | |
105 } | |
106 } | |
107 | |
108 | |
109 OopMap* OopMap::deep_copy() { | |
110 return new OopMap(_deep_copy_token, this); | |
111 } | |
112 | |
113 | |
114 void OopMap::copy_to(address addr) { | |
115 memcpy(addr,this,sizeof(OopMap)); | |
116 memcpy(addr + sizeof(OopMap),write_stream()->buffer(),write_stream()->position()); | |
117 OopMap* new_oop = (OopMap*)addr; | |
118 new_oop->set_omv_data_size(write_stream()->position()); | |
119 new_oop->set_omv_data((unsigned char *)(addr + sizeof(OopMap))); | |
120 new_oop->set_write_stream(NULL); | |
121 } | |
122 | |
123 | |
124 int OopMap::heap_size() const { | |
125 int size = sizeof(OopMap); | |
126 int align = sizeof(void *) - 1; | |
127 if(write_stream() != NULL) { | |
128 size += write_stream()->position(); | |
129 } else { | |
130 size += omv_data_size(); | |
131 } | |
132 // Align to a reasonable ending point | |
133 size = ((size+align) & ~align); | |
134 return size; | |
135 } | |
136 | |
137 // frame_size units are stack-slots (4 bytes) NOT intptr_t; we can name odd | |
138 // slots to hold 4-byte values like ints and floats in the LP64 build. | |
139 void OopMap::set_xxx(VMReg reg, OopMapValue::oop_types x, VMReg optional) { | |
140 | |
141 assert(reg->value() < _locs_length, "too big reg value for stack size"); | |
142 assert( _locs_used[reg->value()] == OopMapValue::unused_value, "cannot insert twice" ); | |
143 debug_only( _locs_used[reg->value()] = x; ) | |
144 | |
145 OopMapValue o(reg, x); | |
146 | |
147 if(x == OopMapValue::callee_saved_value) { | |
148 // This can never be a stack location, so we don't need to transform it. | |
149 assert(optional->is_reg(), "Trying to callee save a stack location"); | |
150 o.set_content_reg(optional); | |
151 } else if(x == OopMapValue::derived_oop_value) { | |
152 o.set_content_reg(optional); | |
153 } | |
154 | |
155 o.write_on(write_stream()); | |
156 increment_count(); | |
157 } | |
158 | |
159 | |
160 void OopMap::set_oop(VMReg reg) { | |
161 set_xxx(reg, OopMapValue::oop_value, VMRegImpl::Bad()); | |
162 } | |
163 | |
164 | |
165 void OopMap::set_value(VMReg reg) { | |
166 // At this time, we only need value entries in our OopMap when ZapDeadCompiledLocals is active. | |
167 if (ZapDeadCompiledLocals) | |
168 set_xxx(reg, OopMapValue::value_value, VMRegImpl::Bad()); | |
169 } | |
170 | |
171 | |
172 void OopMap::set_dead(VMReg reg) { | |
173 // At this time, we only need dead entries in our OopMap when ZapDeadCompiledLocals is active. | |
174 if (ZapDeadCompiledLocals) { | |
175 set_xxx(reg, OopMapValue::dead_value, VMRegImpl::Bad()); | |
176 } | |
177 } | |
178 | |
179 | |
180 void OopMap::set_callee_saved(VMReg reg, VMReg caller_machine_register ) { | |
181 set_xxx(reg, OopMapValue::callee_saved_value, caller_machine_register); | |
182 } | |
183 | |
184 | |
185 void OopMap::set_derived_oop(VMReg reg, VMReg derived_from_local_register ) { | |
186 if( reg == derived_from_local_register ) { | |
187 // Actually an oop, derived shares storage with base, | |
188 set_oop(reg); | |
189 } else { | |
190 set_xxx(reg, OopMapValue::derived_oop_value, derived_from_local_register); | |
191 } | |
192 } | |
193 | |
194 void OopMap::set_stack_obj(VMReg reg) { | |
195 set_xxx(reg, OopMapValue::stack_obj, VMRegImpl::Bad()); | |
196 } | |
197 | |
198 // OopMapSet | |
199 | |
200 OopMapSet::OopMapSet() { | |
201 set_om_size(MinOopMapAllocation); | |
202 set_om_count(0); | |
203 OopMap** temp = NEW_RESOURCE_ARRAY(OopMap*, om_size()); | |
204 set_om_data(temp); | |
205 } | |
206 | |
207 | |
208 void OopMapSet::grow_om_data() { | |
209 int new_size = om_size() * 2; | |
210 OopMap** new_data = NEW_RESOURCE_ARRAY(OopMap*, new_size); | |
211 memcpy(new_data,om_data(),om_size() * sizeof(OopMap*)); | |
212 set_om_size(new_size); | |
213 set_om_data(new_data); | |
214 } | |
215 | |
216 | |
217 void OopMapSet::copy_to(address addr) { | |
218 address temp = addr; | |
219 int align = sizeof(void *) - 1; | |
220 // Copy this | |
221 memcpy(addr,this,sizeof(OopMapSet)); | |
222 temp += sizeof(OopMapSet); | |
223 temp = (address)((intptr_t)(temp + align) & ~align); | |
224 // Do the needed fixups to the new OopMapSet | |
225 OopMapSet* new_set = (OopMapSet*)addr; | |
226 new_set->set_om_data((OopMap**)temp); | |
227 // Allow enough space for the OopMap pointers | |
228 temp += (om_count() * sizeof(OopMap*)); | |
229 | |
230 for(int i=0; i < om_count(); i++) { | |
231 OopMap* map = at(i); | |
232 map->copy_to((address)temp); | |
233 new_set->set(i,(OopMap*)temp); | |
234 temp += map->heap_size(); | |
235 } | |
236 // This "locks" the OopMapSet | |
237 new_set->set_om_size(-1); | |
238 } | |
239 | |
240 | |
241 void OopMapSet::add_gc_map(int pc_offset, OopMap *map ) { | |
242 assert(om_size() != -1,"Cannot grow a fixed OopMapSet"); | |
243 | |
244 if(om_count() >= om_size()) { | |
245 grow_om_data(); | |
246 } | |
247 map->set_offset(pc_offset); | |
248 | |
249 #ifdef ASSERT | |
250 if(om_count() > 0) { | |
251 OopMap* last = at(om_count()-1); | |
252 if (last->offset() == map->offset() ) { | |
253 fatal("OopMap inserted twice"); | |
254 } | |
255 if(last->offset() > map->offset()) { | |
256 tty->print_cr( "WARNING, maps not sorted: pc[%d]=%d, pc[%d]=%d", | |
257 om_count(),last->offset(),om_count()+1,map->offset()); | |
258 } | |
259 } | |
260 #endif // ASSERT | |
261 | |
262 set(om_count(),map); | |
263 increment_count(); | |
264 } | |
265 | |
266 | |
267 int OopMapSet::heap_size() const { | |
268 // The space we use | |
269 int size = sizeof(OopMap); | |
270 int align = sizeof(void *) - 1; | |
271 size = ((size+align) & ~align); | |
272 size += om_count() * sizeof(OopMap*); | |
273 | |
274 // Now add in the space needed for the indivdiual OopMaps | |
275 for(int i=0; i < om_count(); i++) { | |
276 size += at(i)->heap_size(); | |
277 } | |
278 // We don't need to align this, it will be naturally pointer aligned | |
279 return size; | |
280 } | |
281 | |
282 | |
283 OopMap* OopMapSet::singular_oop_map() { | |
284 guarantee(om_count() == 1, "Make sure we only have a single gc point"); | |
285 return at(0); | |
286 } | |
287 | |
288 | |
289 OopMap* OopMapSet::find_map_at_offset(int pc_offset) const { | |
290 int i, len = om_count(); | |
291 assert( len > 0, "must have pointer maps" ); | |
292 | |
293 // Scan through oopmaps. Stop when current offset is either equal or greater | |
294 // than the one we are looking for. | |
295 for( i = 0; i < len; i++) { | |
296 if( at(i)->offset() >= pc_offset ) | |
297 break; | |
298 } | |
299 | |
300 assert( i < len, "oopmap not found" ); | |
301 | |
302 OopMap* m = at(i); | |
303 assert( m->offset() == pc_offset, "oopmap not found" ); | |
304 return m; | |
305 } | |
306 | |
307 class DoNothingClosure: public OopClosure { | |
308 public: void do_oop(oop* p) {} | |
309 }; | |
310 static DoNothingClosure do_nothing; | |
311 | |
312 static void add_derived_oop(oop* base, oop* derived) { | |
313 #ifndef TIERED | |
314 COMPILER1_PRESENT(ShouldNotReachHere();) | |
315 #endif // TIERED | |
316 #ifdef COMPILER2 | |
317 DerivedPointerTable::add(derived, base); | |
318 #endif // COMPILER2 | |
319 } | |
320 | |
321 | |
322 #ifndef PRODUCT | |
323 static void trace_codeblob_maps(const frame *fr, const RegisterMap *reg_map) { | |
324 // Print oopmap and regmap | |
325 tty->print_cr("------ "); | |
326 CodeBlob* cb = fr->cb(); | |
327 OopMapSet* maps = cb->oop_maps(); | |
328 OopMap* map = cb->oop_map_for_return_address(fr->pc()); | |
329 map->print(); | |
330 if( cb->is_nmethod() ) { | |
331 nmethod* nm = (nmethod*)cb; | |
332 // native wrappers have no scope data, it is implied | |
333 if (nm->is_native_method()) { | |
334 tty->print("bci: 0 (native)"); | |
335 } else { | |
336 ScopeDesc* scope = nm->scope_desc_at(fr->pc()); | |
337 tty->print("bci: %d ",scope->bci()); | |
338 } | |
339 } | |
340 tty->cr(); | |
341 fr->print_on(tty); | |
342 tty->print(" "); | |
343 cb->print_value_on(tty); tty->cr(); | |
344 reg_map->print(); | |
345 tty->print_cr("------ "); | |
346 | |
347 } | |
348 #endif // PRODUCT | |
349 | |
350 void OopMapSet::oops_do(const frame *fr, const RegisterMap* reg_map, OopClosure* f) { | |
351 // add derived oops to a table | |
352 all_do(fr, reg_map, f, add_derived_oop, &do_nothing, &do_nothing); | |
353 } | |
354 | |
355 | |
356 void OopMapSet::all_do(const frame *fr, const RegisterMap *reg_map, | |
357 OopClosure* oop_fn, void derived_oop_fn(oop*, oop*), | |
358 OopClosure* value_fn, OopClosure* dead_fn) { | |
359 CodeBlob* cb = fr->cb(); | |
360 { | |
361 assert(cb != NULL, "no codeblob"); | |
362 } | |
363 | |
364 NOT_PRODUCT(if (TraceCodeBlobStacks) trace_codeblob_maps(fr, reg_map);) | |
365 | |
366 OopMapSet* maps = cb->oop_maps(); | |
367 OopMap* map = cb->oop_map_for_return_address(fr->pc()); | |
368 assert(map != NULL, " no ptr map found"); | |
369 | |
370 // handle derived pointers first (otherwise base pointer may be | |
371 // changed before derived pointer offset has been collected) | |
372 OopMapValue omv; | |
373 { | |
374 OopMapStream oms(map,OopMapValue::derived_oop_value); | |
375 if (!oms.is_done()) { | |
376 #ifndef TIERED | |
377 COMPILER1_PRESENT(ShouldNotReachHere();) | |
378 #endif // !TIERED | |
379 // Protect the operation on the derived pointers. This | |
380 // protects the addition of derived pointers to the shared | |
381 // derived pointer table in DerivedPointerTable::add(). | |
382 MutexLockerEx x(DerivedPointerTableGC_lock, Mutex::_no_safepoint_check_flag); | |
383 do { | |
384 omv = oms.current(); | |
385 oop* loc = fr->oopmapreg_to_location(omv.reg(),reg_map); | |
386 if ( loc != NULL ) { | |
387 oop *base_loc = fr->oopmapreg_to_location(omv.content_reg(), reg_map); | |
388 oop *derived_loc = loc; | |
389 derived_oop_fn(base_loc, derived_loc); | |
390 } | |
391 oms.next(); | |
392 } while (!oms.is_done()); | |
393 } | |
394 } | |
395 | |
396 // We want dead, value and oop oop_types | |
397 int mask = OopMapValue::oop_value | OopMapValue::value_value | OopMapValue::dead_value; | |
398 { | |
399 for (OopMapStream oms(map,mask); !oms.is_done(); oms.next()) { | |
400 omv = oms.current(); | |
401 oop* loc = fr->oopmapreg_to_location(omv.reg(),reg_map); | |
402 if ( loc != NULL ) { | |
403 if ( omv.type() == OopMapValue::oop_value ) { | |
404 #ifdef ASSERT | |
405 if (COMPILER2_PRESENT(!DoEscapeAnalysis &&) !Universe::heap()->is_in_or_null(*loc)) { | |
406 tty->print_cr("# Found non oop pointer. Dumping state at failure"); | |
407 // try to dump out some helpful debugging information | |
408 trace_codeblob_maps(fr, reg_map); | |
409 omv.print(); | |
410 tty->print_cr("loc = %p *loc = %p\n", loc, (address)*loc); | |
411 // do the real assert. | |
412 assert(Universe::heap()->is_in_or_null(*loc), "found non oop pointer"); | |
413 } | |
414 #endif // ASSERT | |
415 oop_fn->do_oop(loc); | |
416 } else if ( omv.type() == OopMapValue::value_value ) { | |
417 value_fn->do_oop(loc); | |
418 } else if ( omv.type() == OopMapValue::dead_value ) { | |
419 dead_fn->do_oop(loc); | |
420 } | |
421 } | |
422 } | |
423 } | |
424 | |
425 #ifdef COMPILER2 | |
426 if (DoEscapeAnalysis) { | |
427 for (OopMapStream oms(map, OopMapValue::stack_obj); !oms.is_done(); oms.next()) { | |
428 omv = oms.current(); | |
429 assert(omv.is_stack_loc(), "should refer to stack location"); | |
430 oop loc = (oop) fr->oopmapreg_to_location(omv.reg(),reg_map); | |
431 oop_fn->do_oop(&loc); | |
432 } | |
433 } | |
434 #endif // COMPILER2 | |
435 } | |
436 | |
437 | |
438 // Update callee-saved register info for the following frame | |
439 void OopMapSet::update_register_map(const frame *fr, RegisterMap *reg_map) { | |
440 ResourceMark rm; | |
441 CodeBlob* cb = fr->cb(); | |
442 assert(cb != NULL, "no codeblob"); | |
443 | |
444 // Any reg might be saved by a safepoint handler (see generate_handler_blob). | |
445 const int max_saved_on_entry_reg_count = ConcreteRegisterImpl::number_of_registers; | |
446 assert( reg_map->_update_for_id == NULL || fr->is_older(reg_map->_update_for_id), | |
447 "already updated this map; do not 'update' it twice!" ); | |
448 debug_only(reg_map->_update_for_id = fr->id()); | |
449 | |
450 // Check if caller must update oop argument | |
451 assert((reg_map->include_argument_oops() || | |
452 !cb->caller_must_gc_arguments(reg_map->thread())), | |
453 "include_argument_oops should already be set"); | |
454 | |
455 int nof_callee = 0; | |
456 oop* locs[2*max_saved_on_entry_reg_count+1]; | |
457 VMReg regs[2*max_saved_on_entry_reg_count+1]; | |
458 // ("+1" because max_saved_on_entry_reg_count might be zero) | |
459 | |
460 // Scan through oopmap and find location of all callee-saved registers | |
461 // (we do not do update in place, since info could be overwritten) | |
462 | |
463 address pc = fr->pc(); | |
464 | |
465 OopMap* map = cb->oop_map_for_return_address(pc); | |
466 | |
467 assert(map != NULL, " no ptr map found"); | |
468 | |
469 OopMapValue omv; | |
470 for(OopMapStream oms(map,OopMapValue::callee_saved_value); !oms.is_done(); oms.next()) { | |
471 omv = oms.current(); | |
472 assert(nof_callee < 2*max_saved_on_entry_reg_count, "overflow"); | |
473 regs[nof_callee] = omv.content_reg(); | |
474 locs[nof_callee] = fr->oopmapreg_to_location(omv.reg(),reg_map); | |
475 nof_callee++; | |
476 } | |
477 | |
478 // Check that runtime stubs save all callee-saved registers | |
479 #ifdef COMPILER2 | |
480 assert(cb->is_compiled_by_c1() || !cb->is_runtime_stub() || | |
481 (nof_callee >= SAVED_ON_ENTRY_REG_COUNT || nof_callee >= C_SAVED_ON_ENTRY_REG_COUNT), | |
482 "must save all"); | |
483 #endif // COMPILER2 | |
484 | |
485 // Copy found callee-saved register to reg_map | |
486 for(int i = 0; i < nof_callee; i++) { | |
487 reg_map->set_location(regs[i], (address)locs[i]); | |
488 } | |
489 } | |
490 | |
491 //============================================================================= | |
492 // Non-Product code | |
493 | |
494 #ifndef PRODUCT | |
495 | |
496 bool OopMap::has_derived_pointer() const { | |
497 #ifndef TIERED | |
498 COMPILER1_PRESENT(return false); | |
499 #endif // !TIERED | |
500 #ifdef COMPILER2 | |
501 OopMapStream oms((OopMap*)this,OopMapValue::derived_oop_value); | |
502 return oms.is_done(); | |
503 #else | |
504 return false; | |
505 #endif // COMPILER2 | |
506 } | |
507 | |
508 | |
509 void print_register_type(OopMapValue::oop_types x, VMReg optional) { | |
510 switch( x ) { | |
511 case OopMapValue::oop_value: | |
512 tty->print("Oop"); | |
513 break; | |
514 case OopMapValue::value_value: | |
515 tty->print("Value" ); | |
516 break; | |
517 case OopMapValue::dead_value: | |
518 tty->print("Dead" ); | |
519 break; | |
520 case OopMapValue::callee_saved_value: | |
521 tty->print("Callers_" ); | |
522 optional->print(); | |
523 break; | |
524 case OopMapValue::derived_oop_value: | |
525 tty->print("Derived_oop_" ); | |
526 optional->print(); | |
527 break; | |
528 case OopMapValue::stack_obj: | |
529 tty->print("Stack"); | |
530 break; | |
531 default: | |
532 ShouldNotReachHere(); | |
533 } | |
534 } | |
535 | |
536 | |
537 void OopMapValue::print() const { | |
538 reg()->print(); | |
539 tty->print("="); | |
540 print_register_type(type(),content_reg()); | |
541 tty->print(" "); | |
542 } | |
543 | |
544 | |
545 void OopMap::print_on(outputStream* st) const { | |
546 OopMapValue omv; | |
547 for(OopMapStream oms((OopMap*)this); !oms.is_done(); oms.next()) { | |
548 omv = oms.current(); | |
549 omv.print_on(st); | |
550 } | |
551 } | |
552 | |
553 | |
554 void OopMapSet::print_on(outputStream* st) const { | |
555 int i, len = om_count(); | |
556 | |
557 st->print_cr("OopMapSet contains %d OopMaps\n",len); | |
558 | |
559 for( i = 0; i < len; i++) { | |
560 OopMap* m = at(i); | |
561 st->print_cr("OopMap #%d offset:%p",i,m->offset()); | |
562 m->print_on(st); | |
563 st->print_cr("\n"); | |
564 } | |
565 } | |
566 #endif // !PRODUCT | |
567 | |
568 | |
569 //------------------------------DerivedPointerTable--------------------------- | |
570 | |
571 #ifdef COMPILER2 | |
572 | |
573 class DerivedPointerEntry : public CHeapObj { | |
574 private: | |
575 oop* _location; // Location of derived pointer (also pointing to the base) | |
576 intptr_t _offset; // Offset from base pointer | |
577 public: | |
578 DerivedPointerEntry(oop* location, intptr_t offset) { _location = location; _offset = offset; } | |
579 oop* location() { return _location; } | |
580 intptr_t offset() { return _offset; } | |
581 }; | |
582 | |
583 | |
584 GrowableArray<DerivedPointerEntry*>* DerivedPointerTable::_list = NULL; | |
585 bool DerivedPointerTable::_active = false; | |
586 | |
587 | |
588 void DerivedPointerTable::clear() { | |
589 // The first time, we create the list. Otherwise it should be | |
590 // empty. If not, then we have probably forgotton to call | |
591 // update_pointers after last GC/Scavenge. | |
592 assert (!_active, "should not be active"); | |
593 assert(_list == NULL || _list->length() == 0, "table not empty"); | |
594 if (_list == NULL) { | |
595 _list = new (ResourceObj::C_HEAP) GrowableArray<DerivedPointerEntry*>(10, true); // Allocated on C heap | |
596 } | |
597 _active = true; | |
598 } | |
599 | |
600 | |
601 // Returns value of location as an int | |
602 intptr_t value_of_loc(oop *pointer) { return (intptr_t)(*pointer); } | |
603 | |
604 | |
605 void DerivedPointerTable::add(oop *derived_loc, oop *base_loc) { | |
606 assert(Universe::heap()->is_in_or_null(*base_loc), "not an oop"); | |
607 assert(derived_loc != base_loc, "Base and derived in same location"); | |
608 if (_active) { | |
609 assert(*derived_loc != (oop)base_loc, "location already added"); | |
610 assert(_list != NULL, "list must exist"); | |
611 intptr_t offset = value_of_loc(derived_loc) - value_of_loc(base_loc); | |
612 assert(offset >= -1000000, "wrong derived pointer info"); | |
613 | |
614 if (TraceDerivedPointers) { | |
615 tty->print_cr( | |
616 "Add derived pointer@" INTPTR_FORMAT | |
617 " - Derived: " INTPTR_FORMAT | |
618 " Base: " INTPTR_FORMAT " (@" INTPTR_FORMAT ") (Offset: %d)", | |
619 derived_loc, (address)*derived_loc, (address)*base_loc, base_loc, offset | |
620 ); | |
621 } | |
622 // Set derived oop location to point to base. | |
623 *derived_loc = (oop)base_loc; | |
624 assert_lock_strong(DerivedPointerTableGC_lock); | |
625 DerivedPointerEntry *entry = new DerivedPointerEntry(derived_loc, offset); | |
626 _list->append(entry); | |
627 } | |
628 } | |
629 | |
630 | |
631 void DerivedPointerTable::update_pointers() { | |
632 assert(_list != NULL, "list must exist"); | |
633 for(int i = 0; i < _list->length(); i++) { | |
634 DerivedPointerEntry* entry = _list->at(i); | |
635 oop* derived_loc = entry->location(); | |
636 intptr_t offset = entry->offset(); | |
637 // The derived oop was setup to point to location of base | |
638 oop base = **(oop**)derived_loc; | |
639 assert(Universe::heap()->is_in_or_null(base), "must be an oop"); | |
640 | |
641 *derived_loc = (oop)(((address)base) + offset); | |
642 assert(value_of_loc(derived_loc) - value_of_loc(&base) == offset, "sanity check"); | |
643 | |
644 if (TraceDerivedPointers) { | |
645 tty->print_cr("Updating derived pointer@" INTPTR_FORMAT | |
646 " - Derived: " INTPTR_FORMAT " Base: " INTPTR_FORMAT " (Offset: %d)", | |
647 derived_loc, (address)*derived_loc, (address)base, offset); | |
648 } | |
649 | |
650 // Delete entry | |
651 delete entry; | |
652 _list->at_put(i, NULL); | |
653 } | |
654 // Clear list, so it is ready for next traversal (this is an invariant) | |
655 if (TraceDerivedPointers && !_list->is_empty()) { | |
656 tty->print_cr("--------------------------"); | |
657 } | |
658 _list->clear(); | |
659 _active = false; | |
660 } | |
661 | |
662 #endif // COMPILER2 |