1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/compiler/oopMap.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,315 @@ 1.4 +/* 1.5 + * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +// Interface for generating the frame map for compiled code. A frame map 1.29 +// describes for a specific pc whether each register and frame stack slot is: 1.30 +// Oop - A GC root for current frame 1.31 +// Value - Live non-oop, non-float value: int, either half of double 1.32 +// Dead - Dead; can be Zapped for debugging 1.33 +// CalleeXX - Callee saved; also describes which caller register is saved 1.34 +// DerivedXX - A derived oop; original oop is described. 1.35 +// 1.36 +// OopMapValue describes a single OopMap entry 1.37 + 1.38 +class frame; 1.39 +class RegisterMap; 1.40 +class DerivedPointerEntry; 1.41 + 1.42 +class OopMapValue: public StackObj { 1.43 + friend class VMStructs; 1.44 +private: 1.45 + short _value; 1.46 + int value() const { return _value; } 1.47 + void set_value(int value) { _value = value; } 1.48 + short _content_reg; 1.49 + 1.50 +public: 1.51 + // Constants 1.52 + enum { type_bits = 6, 1.53 + register_bits = BitsPerShort - type_bits }; 1.54 + 1.55 + enum { type_shift = 0, 1.56 + register_shift = type_bits }; 1.57 + 1.58 + enum { type_mask = right_n_bits(type_bits), 1.59 + type_mask_in_place = type_mask << type_shift, 1.60 + register_mask = right_n_bits(register_bits), 1.61 + register_mask_in_place = register_mask << register_shift }; 1.62 + 1.63 + enum oop_types { // must fit in type_bits 1.64 + unused_value =0, // powers of 2, for masking OopMapStream 1.65 + oop_value = 1, 1.66 + value_value = 2, 1.67 + dead_value = 4, 1.68 + callee_saved_value = 8, 1.69 + derived_oop_value= 16, 1.70 + stack_obj = 32 }; 1.71 + 1.72 + // Constructors 1.73 + OopMapValue () { set_value(0); set_content_reg(VMRegImpl::Bad()); } 1.74 + OopMapValue (VMReg reg, oop_types t) { set_reg_type(reg,t); } 1.75 + OopMapValue (VMReg reg, oop_types t, VMReg reg2) { set_reg_type(reg,t); set_content_reg(reg2); } 1.76 + OopMapValue (CompressedReadStream* stream) { read_from(stream); } 1.77 + 1.78 + // Archiving 1.79 + void write_on(CompressedWriteStream* stream) { 1.80 + stream->write_int(value()); 1.81 + if(is_callee_saved() || is_derived_oop()) { 1.82 + stream->write_int(content_reg()->value()); 1.83 + } 1.84 + } 1.85 + 1.86 + void read_from(CompressedReadStream* stream) { 1.87 + set_value(stream->read_int()); 1.88 + if(is_callee_saved() || is_derived_oop()) { 1.89 + set_content_reg(VMRegImpl::as_VMReg(stream->read_int(), true)); 1.90 + } 1.91 + } 1.92 + 1.93 + // Querying 1.94 + bool is_oop() { return mask_bits(value(), type_mask_in_place) == oop_value; } 1.95 + bool is_value() { return mask_bits(value(), type_mask_in_place) == value_value; } 1.96 + bool is_dead() { return mask_bits(value(), type_mask_in_place) == dead_value; } 1.97 + bool is_callee_saved() { return mask_bits(value(), type_mask_in_place) == callee_saved_value; } 1.98 + bool is_derived_oop() { return mask_bits(value(), type_mask_in_place) == derived_oop_value; } 1.99 + bool is_stack_obj() { return mask_bits(value(), type_mask_in_place) == stack_obj; } 1.100 + 1.101 + void set_oop() { set_value((value() & register_mask_in_place) | oop_value); } 1.102 + void set_value() { set_value((value() & register_mask_in_place) | value_value); } 1.103 + void set_dead() { set_value((value() & register_mask_in_place) | dead_value); } 1.104 + void set_callee_saved() { set_value((value() & register_mask_in_place) | callee_saved_value); } 1.105 + void set_derived_oop() { set_value((value() & register_mask_in_place) | derived_oop_value); } 1.106 + void set_stack_obj() { set_value((value() & register_mask_in_place) | stack_obj); } 1.107 + 1.108 + VMReg reg() const { return VMRegImpl::as_VMReg(mask_bits(value(), register_mask_in_place) >> register_shift); } 1.109 + oop_types type() const { return (oop_types)mask_bits(value(), type_mask_in_place); } 1.110 + 1.111 + static bool legal_vm_reg_name(VMReg p) { 1.112 + return (p->value() == (p->value() & register_mask)); 1.113 + } 1.114 + 1.115 + void set_reg_type(VMReg p, oop_types t) { 1.116 + set_value((p->value() << register_shift) | t); 1.117 + assert(reg() == p, "sanity check" ); 1.118 + assert(type() == t, "sanity check" ); 1.119 + } 1.120 + 1.121 + 1.122 + VMReg content_reg() const { return VMRegImpl::as_VMReg(_content_reg, true); } 1.123 + void set_content_reg(VMReg r) { _content_reg = r->value(); } 1.124 + 1.125 + // Physical location queries 1.126 + bool is_register_loc() { return reg()->is_reg(); } 1.127 + bool is_stack_loc() { return reg()->is_stack(); } 1.128 + 1.129 + // Returns offset from sp. 1.130 + int stack_offset() { 1.131 + assert(is_stack_loc(), "must be stack location"); 1.132 + return reg()->reg2stack(); 1.133 + } 1.134 + 1.135 + void print( ) const PRODUCT_RETURN; 1.136 +}; 1.137 + 1.138 + 1.139 +class OopMap: public ResourceObj { 1.140 + friend class OopMapStream; 1.141 + friend class VMStructs; 1.142 + private: 1.143 + int _pc_offset; 1.144 + int _omv_count; 1.145 + int _omv_data_size; 1.146 + unsigned char* _omv_data; 1.147 + CompressedWriteStream* _write_stream; 1.148 + 1.149 + debug_only( OopMapValue::oop_types* _locs_used; int _locs_length;) 1.150 + 1.151 + // Accessors 1.152 + unsigned char* omv_data() const { return _omv_data; } 1.153 + void set_omv_data(unsigned char* value) { _omv_data = value; } 1.154 + int omv_data_size() const { return _omv_data_size; } 1.155 + void set_omv_data_size(int value) { _omv_data_size = value; } 1.156 + int omv_count() const { return _omv_count; } 1.157 + void set_omv_count(int value) { _omv_count = value; } 1.158 + void increment_count() { _omv_count++; } 1.159 + CompressedWriteStream* write_stream() const { return _write_stream; } 1.160 + void set_write_stream(CompressedWriteStream* value) { _write_stream = value; } 1.161 + 1.162 + private: 1.163 + enum DeepCopyToken { _deep_copy_token }; 1.164 + OopMap(DeepCopyToken, OopMap* source); // used only by deep_copy 1.165 + 1.166 + public: 1.167 + OopMap(int frame_size, int arg_count); 1.168 + 1.169 + // pc-offset handling 1.170 + int offset() const { return _pc_offset; } 1.171 + void set_offset(int o) { _pc_offset = o; } 1.172 + 1.173 + // Check to avoid double insertion 1.174 + debug_only(OopMapValue::oop_types locs_used( int indx ) { return _locs_used[indx]; }) 1.175 + 1.176 + // Construction 1.177 + // frame_size units are stack-slots (4 bytes) NOT intptr_t; we can name odd 1.178 + // slots to hold 4-byte values like ints and floats in the LP64 build. 1.179 + void set_oop ( VMReg local); 1.180 + void set_value( VMReg local); 1.181 + void set_dead ( VMReg local); 1.182 + void set_callee_saved( VMReg local, VMReg caller_machine_register ); 1.183 + void set_derived_oop ( VMReg local, VMReg derived_from_local_register ); 1.184 + void set_stack_obj( VMReg local); 1.185 + void set_xxx(VMReg reg, OopMapValue::oop_types x, VMReg optional); 1.186 + 1.187 + int heap_size() const; 1.188 + void copy_to(address addr); 1.189 + OopMap* deep_copy(); 1.190 + 1.191 + bool has_derived_pointer() const PRODUCT_RETURN0; 1.192 + 1.193 + bool legal_vm_reg_name(VMReg local) { 1.194 + return OopMapValue::legal_vm_reg_name(local); 1.195 + } 1.196 + 1.197 + // Printing 1.198 + void print_on(outputStream* st) const PRODUCT_RETURN; 1.199 + void print() const { print_on(tty); } 1.200 +}; 1.201 + 1.202 + 1.203 +class OopMapSet : public ResourceObj { 1.204 + friend class VMStructs; 1.205 + private: 1.206 + int _om_count; 1.207 + int _om_size; 1.208 + OopMap** _om_data; 1.209 + 1.210 + int om_count() const { return _om_count; } 1.211 + void set_om_count(int value) { _om_count = value; } 1.212 + void increment_count() { _om_count++; } 1.213 + int om_size() const { return _om_size; } 1.214 + void set_om_size(int value) { _om_size = value; } 1.215 + OopMap** om_data() const { return _om_data; } 1.216 + void set_om_data(OopMap** value) { _om_data = value; } 1.217 + void grow_om_data(); 1.218 + void set(int index,OopMap* value) { assert((index == 0) || ((index > 0) && (index < om_size())),"bad index"); _om_data[index] = value; } 1.219 + 1.220 + public: 1.221 + OopMapSet(); 1.222 + 1.223 + // returns the number of OopMaps in this OopMapSet 1.224 + int size() const { return _om_count; } 1.225 + // returns the OopMap at a given index 1.226 + OopMap* at(int index) const { assert((index >= 0) && (index <= om_count()),"bad index"); return _om_data[index]; } 1.227 + 1.228 + // Collect OopMaps. 1.229 + void add_gc_map(int pc, OopMap* map); 1.230 + 1.231 + // Returns the only oop map. Used for reconstructing 1.232 + // Adapter frames during deoptimization 1.233 + OopMap* singular_oop_map(); 1.234 + 1.235 + // returns OopMap in that is anchored to the pc 1.236 + OopMap* find_map_at_offset(int pc_offset) const; 1.237 + 1.238 + int heap_size() const; 1.239 + void copy_to(address addr); 1.240 + 1.241 + // Iterates through frame for a compiled method 1.242 + static void oops_do (const frame* fr, 1.243 + const RegisterMap* reg_map, OopClosure* f); 1.244 + static void update_register_map(const frame* fr, RegisterMap *reg_map); 1.245 + 1.246 + // Iterates through frame for a compiled method for dead ones and values, too 1.247 + static void all_do(const frame* fr, const RegisterMap* reg_map, 1.248 + OopClosure* oop_fn, 1.249 + void derived_oop_fn(oop* base, oop* derived), 1.250 + OopClosure* value_fn, OopClosure* dead_fn); 1.251 + 1.252 + // Printing 1.253 + void print_on(outputStream* st) const PRODUCT_RETURN; 1.254 + void print() const { print_on(tty); } 1.255 +}; 1.256 + 1.257 + 1.258 +class OopMapStream : public StackObj { 1.259 + private: 1.260 + CompressedReadStream* _stream; 1.261 + int _mask; 1.262 + int _size; 1.263 + int _position; 1.264 + bool _valid_omv; 1.265 + OopMapValue _omv; 1.266 + void find_next(); 1.267 + 1.268 + public: 1.269 + OopMapStream(OopMap* oop_map); 1.270 + OopMapStream(OopMap* oop_map, int oop_types_mask); 1.271 + bool is_done() { if(!_valid_omv) { find_next(); } return !_valid_omv; } 1.272 + void next() { find_next(); } 1.273 + OopMapValue current() { return _omv; } 1.274 +}; 1.275 + 1.276 + 1.277 +// Derived pointer support. This table keeps track of all derived points on a 1.278 +// stack. It is cleared before each scavenge/GC. During the traversal of all 1.279 +// oops, it is filled in with references to all locations that contains a 1.280 +// derived oop (assumed to be very few). When the GC is complete, the derived 1.281 +// pointers are updated based on their base pointers new value and an offset. 1.282 +#ifdef COMPILER2 1.283 +class DerivedPointerTable : public AllStatic { 1.284 + friend class VMStructs; 1.285 + private: 1.286 + static GrowableArray<DerivedPointerEntry*>* _list; 1.287 + static bool _active; // do not record pointers for verify pass etc. 1.288 + public: 1.289 + static void clear(); // Called before scavenge/GC 1.290 + static void add(oop *derived, oop *base); // Called during scavenge/GC 1.291 + static void update_pointers(); // Called after scavenge/GC 1.292 + static bool is_empty() { return _list == NULL || _list->is_empty(); } 1.293 + static bool is_active() { return _active; } 1.294 + static void set_active(bool value) { _active = value; } 1.295 +}; 1.296 + 1.297 +// A utility class to temporarily "deactivate" the DerivedPointerTable. 1.298 +// (Note: clients are responsible for any MT-safety issues) 1.299 +class DerivedPointerTableDeactivate: public StackObj { 1.300 + private: 1.301 + bool _active; 1.302 + public: 1.303 + DerivedPointerTableDeactivate() { 1.304 + _active = DerivedPointerTable::is_active(); 1.305 + if (_active) { 1.306 + DerivedPointerTable::set_active(false); 1.307 + } 1.308 + } 1.309 + 1.310 + ~DerivedPointerTableDeactivate() { 1.311 + assert(!DerivedPointerTable::is_active(), 1.312 + "Inconsistency: not MT-safe"); 1.313 + if (_active) { 1.314 + DerivedPointerTable::set_active(true); 1.315 + } 1.316 + } 1.317 +}; 1.318 +#endif // COMPILER2