Mon, 11 Oct 2010 04:18:58 -0700
6829194: JSR 292 needs to support compressed oops
Reviewed-by: kvn, jrose
duke@435 | 1 | /* |
twisti@2142 | 2 | * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | // A frame represents a physical stack frame (an activation). Frames can be |
duke@435 | 26 | // C or Java frames, and the Java frames can be interpreted or compiled. |
duke@435 | 27 | // In contrast, vframes represent source-level activations, so that one physical frame |
duke@435 | 28 | // can correspond to multiple source level frames because of inlining. |
duke@435 | 29 | // A frame is comprised of {pc, sp, younger_sp} |
duke@435 | 30 | |
duke@435 | 31 | |
duke@435 | 32 | // Layout of asm interpreter frame: |
duke@435 | 33 | // |
duke@435 | 34 | // 0xfffffff |
duke@435 | 35 | // ...... |
duke@435 | 36 | // [last extra incoming arg, (local # Nargs > 6 ? Nargs-1 : undef)] |
duke@435 | 37 | // .. Note: incoming args are copied to local frame area upon entry |
duke@435 | 38 | // [first extra incoming arg, (local # Nargs > 6 ? 6 : undef)] |
duke@435 | 39 | // [6 words for C-arg storage (unused)] Are this and next one really needed? |
duke@435 | 40 | // [C-aggregate-word (unused)] Yes, if want extra params to be in same place as C convention |
duke@435 | 41 | // [16 words for register saving] <--- FP |
duke@435 | 42 | // [interpreter_frame_vm_locals ] (see below) |
duke@435 | 43 | |
duke@435 | 44 | // Note: Llocals is always double-word aligned |
duke@435 | 45 | // [first local i.e. local # 0] <-- Llocals |
duke@435 | 46 | // ... |
duke@435 | 47 | // [last local, i.e. local # Nlocals-1] |
duke@435 | 48 | |
duke@435 | 49 | // [monitors ] |
duke@435 | 50 | // .... |
duke@435 | 51 | // [monitors ] <-- Lmonitors (same as Llocals + 6*4 if none) |
duke@435 | 52 | // (must be double-word aligned because |
duke@435 | 53 | // monitor element size is constrained to |
duke@435 | 54 | // doubleword) |
duke@435 | 55 | // |
duke@435 | 56 | // <-- Lesp (points 1 past TOS) |
duke@435 | 57 | // [bottom word used for stack ] |
duke@435 | 58 | // ... |
duke@435 | 59 | // [top word used for stack] (first word of stack is double-word aligned) |
duke@435 | 60 | |
duke@435 | 61 | // [space for outgoing args (conservatively allocated as max_stack - 6 + interpreter_frame_extra_outgoing_argument_words)] |
duke@435 | 62 | // [6 words for C-arg storage] |
duke@435 | 63 | // [C-aggregate-word (unused)] |
duke@435 | 64 | // [16 words for register saving] <--- SP |
duke@435 | 65 | // ... |
duke@435 | 66 | // 0x0000000 |
duke@435 | 67 | // |
duke@435 | 68 | // The in registers and local registers are preserved in a block at SP. |
duke@435 | 69 | // |
duke@435 | 70 | // The first six in registers (I0..I5) hold the first six locals. |
duke@435 | 71 | // The locals are used as follows: |
duke@435 | 72 | // Lesp first free element of expression stack |
duke@435 | 73 | // (which grows towards __higher__ addresses) |
duke@435 | 74 | // Lbcp is set to address of bytecode to execute |
duke@435 | 75 | // It is accessed in the frame under the name "bcx". |
duke@435 | 76 | // It may at times (during GC) be an index instead. |
duke@435 | 77 | // Lmethod the method being interpreted |
duke@435 | 78 | // Llocals the base pointer for accessing the locals array |
duke@435 | 79 | // (lower-numbered locals have lower addresses) |
duke@435 | 80 | // Lmonitors the base pointer for accessing active monitors |
duke@435 | 81 | // Lcache a saved pointer to the method's constant pool cache |
duke@435 | 82 | // |
duke@435 | 83 | // |
duke@435 | 84 | // When calling out to another method, |
duke@435 | 85 | // G5_method is set to method to call, G5_inline_cache_klass may be set, |
duke@435 | 86 | // parameters are put in O registers, and also extra parameters |
duke@435 | 87 | // must be cleverly copied from the top of stack to the outgoing param area in the frame, |
duke@435 | 88 | // ------------------------------ C++ interpreter ---------------------------------------- |
duke@435 | 89 | // Layout of C++ interpreter frame: |
duke@435 | 90 | // |
duke@435 | 91 | |
duke@435 | 92 | |
duke@435 | 93 | |
duke@435 | 94 | // All frames: |
duke@435 | 95 | |
duke@435 | 96 | public: |
duke@435 | 97 | |
duke@435 | 98 | enum { |
duke@435 | 99 | // normal return address is 2 words past PC |
duke@435 | 100 | pc_return_offset = 2 * BytesPerInstWord, |
duke@435 | 101 | |
duke@435 | 102 | // size of each block, in order of increasing address: |
duke@435 | 103 | register_save_words = 16, |
duke@435 | 104 | #ifdef _LP64 |
duke@435 | 105 | callee_aggregate_return_pointer_words = 0, |
duke@435 | 106 | #else |
duke@435 | 107 | callee_aggregate_return_pointer_words = 1, |
duke@435 | 108 | #endif |
duke@435 | 109 | callee_register_argument_save_area_words = 6, |
duke@435 | 110 | // memory_parameter_words = <arbitrary>, |
duke@435 | 111 | |
duke@435 | 112 | // offset of each block, in order of increasing address: |
duke@435 | 113 | // (note: callee_register_argument_save_area_words == Assembler::n_register_parameters) |
duke@435 | 114 | register_save_words_sp_offset = 0, |
duke@435 | 115 | callee_aggregate_return_pointer_sp_offset = register_save_words_sp_offset + register_save_words, |
duke@435 | 116 | callee_register_argument_save_area_sp_offset = callee_aggregate_return_pointer_sp_offset + callee_aggregate_return_pointer_words, |
duke@435 | 117 | memory_parameter_word_sp_offset = callee_register_argument_save_area_sp_offset + callee_register_argument_save_area_words, |
duke@435 | 118 | varargs_offset = memory_parameter_word_sp_offset |
duke@435 | 119 | }; |
duke@435 | 120 | |
duke@435 | 121 | private: |
duke@435 | 122 | intptr_t* _younger_sp; // optional SP of callee (used to locate O7) |
duke@435 | 123 | int _sp_adjustment_by_callee; // adjustment in words to SP by callee for making locals contiguous |
duke@435 | 124 | |
duke@435 | 125 | // Note: On SPARC, unlike Intel, the saved PC for a stack frame |
duke@435 | 126 | // is stored at a __variable__ distance from that frame's SP. |
duke@435 | 127 | // (In fact, it may be in the register save area of the callee frame, |
duke@435 | 128 | // but that fact need not bother us.) Thus, we must store the |
duke@435 | 129 | // address of that saved PC explicitly. On the other hand, SPARC |
duke@435 | 130 | // stores the FP for a frame at a fixed offset from the frame's SP, |
duke@435 | 131 | // so there is no need for a separate "frame::_fp" field. |
duke@435 | 132 | |
duke@435 | 133 | public: |
duke@435 | 134 | // Accessors |
duke@435 | 135 | |
duke@435 | 136 | intptr_t* younger_sp() const { |
duke@435 | 137 | assert(_younger_sp != NULL, "frame must possess a younger_sp"); |
duke@435 | 138 | return _younger_sp; |
duke@435 | 139 | } |
duke@435 | 140 | |
duke@435 | 141 | int callee_sp_adjustment() const { return _sp_adjustment_by_callee; } |
duke@435 | 142 | void set_sp_adjustment_by_callee(int number_of_words) { _sp_adjustment_by_callee = number_of_words; } |
duke@435 | 143 | |
duke@435 | 144 | // Constructors |
duke@435 | 145 | |
duke@435 | 146 | // This constructor relies on the fact that the creator of a frame |
duke@435 | 147 | // has flushed register windows which the frame will refer to, and |
duke@435 | 148 | // that those register windows will not be reloaded until the frame is |
duke@435 | 149 | // done reading and writing the stack. Moreover, if the "younger_sp" |
duke@435 | 150 | // argument points into the register save area of the next younger |
duke@435 | 151 | // frame (though it need not), the register window for that next |
duke@435 | 152 | // younger frame must also stay flushed. (The caller is responsible |
duke@435 | 153 | // for ensuring this.) |
duke@435 | 154 | |
duke@435 | 155 | frame(intptr_t* sp, intptr_t* younger_sp, bool younger_frame_adjusted_stack = false); |
duke@435 | 156 | |
duke@435 | 157 | // make a deficient frame which doesn't know where its PC is: |
duke@435 | 158 | enum unpatchable_t { unpatchable }; |
duke@435 | 159 | frame(intptr_t* sp, unpatchable_t, address pc = NULL, CodeBlob* cb = NULL); |
duke@435 | 160 | |
duke@435 | 161 | // Walk from sp outward looking for old_sp, and return old_sp's predecessor |
duke@435 | 162 | // (i.e. return the sp from the frame where old_sp is the fp). |
duke@435 | 163 | // Register windows are assumed to be flushed for the stack in question. |
duke@435 | 164 | |
duke@435 | 165 | static intptr_t* next_younger_sp_or_null(intptr_t* old_sp, intptr_t* sp); |
duke@435 | 166 | |
duke@435 | 167 | // Return true if sp is a younger sp in the stack described by valid_sp. |
duke@435 | 168 | static bool is_valid_stack_pointer(intptr_t* valid_sp, intptr_t* sp); |
duke@435 | 169 | |
duke@435 | 170 | public: |
duke@435 | 171 | // accessors for the instance variables |
duke@435 | 172 | intptr_t* fp() const { return (intptr_t*) ((intptr_t)(sp()[FP->sp_offset_in_saved_window()]) + STACK_BIAS ); } |
duke@435 | 173 | |
duke@435 | 174 | // All frames |
duke@435 | 175 | |
duke@435 | 176 | intptr_t* fp_addr_at(int index) const { return &fp()[index]; } |
duke@435 | 177 | intptr_t* sp_addr_at(int index) const { return &sp()[index]; } |
duke@435 | 178 | intptr_t fp_at( int index) const { return *fp_addr_at(index); } |
duke@435 | 179 | intptr_t sp_at( int index) const { return *sp_addr_at(index); } |
duke@435 | 180 | |
duke@435 | 181 | private: |
duke@435 | 182 | inline address* I7_addr() const; |
duke@435 | 183 | inline address* O7_addr() const; |
duke@435 | 184 | |
duke@435 | 185 | inline address* I0_addr() const; |
duke@435 | 186 | inline address* O0_addr() const; |
duke@435 | 187 | intptr_t* younger_sp_addr_at(int index) const { return &younger_sp()[index]; } |
duke@435 | 188 | |
duke@435 | 189 | public: |
duke@435 | 190 | // access to SPARC arguments and argument registers |
duke@435 | 191 | |
duke@435 | 192 | // Assumes reg is an in/local register |
duke@435 | 193 | intptr_t* register_addr(Register reg) const { |
duke@435 | 194 | return sp_addr_at(reg->sp_offset_in_saved_window()); |
duke@435 | 195 | } |
duke@435 | 196 | |
duke@435 | 197 | // Assumes reg is an out register |
duke@435 | 198 | intptr_t* out_register_addr(Register reg) const { |
duke@435 | 199 | return younger_sp_addr_at(reg->after_save()->sp_offset_in_saved_window()); |
duke@435 | 200 | } |
duke@435 | 201 | intptr_t* memory_param_addr(int param_ix, bool is_in) const { |
duke@435 | 202 | int offset = callee_register_argument_save_area_sp_offset + param_ix; |
duke@435 | 203 | if (is_in) |
duke@435 | 204 | return fp_addr_at(offset); |
duke@435 | 205 | else |
duke@435 | 206 | return sp_addr_at(offset); |
duke@435 | 207 | } |
duke@435 | 208 | intptr_t* param_addr(int param_ix, bool is_in) const { |
duke@435 | 209 | if (param_ix >= callee_register_argument_save_area_words) |
duke@435 | 210 | return memory_param_addr(param_ix, is_in); |
duke@435 | 211 | else if (is_in) |
duke@435 | 212 | return register_addr(Argument(param_ix, true).as_register()); |
duke@435 | 213 | else { |
duke@435 | 214 | // the registers are stored in the next younger frame |
duke@435 | 215 | // %%% is this really necessary? |
duke@435 | 216 | ShouldNotReachHere(); |
duke@435 | 217 | return NULL; |
duke@435 | 218 | } |
duke@435 | 219 | } |
duke@435 | 220 | |
duke@435 | 221 | |
duke@435 | 222 | // Interpreter frames |
duke@435 | 223 | |
duke@435 | 224 | public: |
duke@435 | 225 | // Asm interpreter |
duke@435 | 226 | #ifndef CC_INTERP |
duke@435 | 227 | enum interpreter_frame_vm_locals { |
duke@435 | 228 | // 2 words, also used to save float regs across calls to C |
duke@435 | 229 | interpreter_frame_d_scratch_fp_offset = -2, |
duke@435 | 230 | interpreter_frame_l_scratch_fp_offset = -4, |
duke@435 | 231 | interpreter_frame_padding_offset = -5, // for native calls only |
duke@435 | 232 | interpreter_frame_oop_temp_offset = -6, // for native calls only |
duke@435 | 233 | interpreter_frame_vm_locals_fp_offset = -6, // should be same as above, and should be zero mod 8 |
duke@435 | 234 | |
duke@435 | 235 | interpreter_frame_vm_local_words = -interpreter_frame_vm_locals_fp_offset, |
duke@435 | 236 | |
duke@435 | 237 | |
duke@435 | 238 | // interpreter frame set-up needs to save 2 extra words in outgoing param area |
duke@435 | 239 | // for class and jnienv arguments for native stubs (see nativeStubGen_sparc.cpp_ |
duke@435 | 240 | |
duke@435 | 241 | interpreter_frame_extra_outgoing_argument_words = 2 |
duke@435 | 242 | }; |
duke@435 | 243 | #else |
duke@435 | 244 | enum interpreter_frame_vm_locals { |
duke@435 | 245 | // 2 words, also used to save float regs across calls to C |
duke@435 | 246 | interpreter_state_ptr_offset = 0, // Is in L0 (Lstate) in save area |
duke@435 | 247 | interpreter_frame_mirror_offset = 1, // Is in L1 (Lmirror) in save area (for native calls only) |
duke@435 | 248 | |
duke@435 | 249 | // interpreter frame set-up needs to save 2 extra words in outgoing param area |
duke@435 | 250 | // for class and jnienv arguments for native stubs (see nativeStubGen_sparc.cpp_ |
duke@435 | 251 | |
duke@435 | 252 | interpreter_frame_extra_outgoing_argument_words = 2 |
duke@435 | 253 | }; |
duke@435 | 254 | #endif /* CC_INTERP */ |
duke@435 | 255 | |
duke@435 | 256 | // the compiler frame has many of the same fields as the interpreter frame |
duke@435 | 257 | // %%%%% factor out declarations of the shared fields |
duke@435 | 258 | enum compiler_frame_fixed_locals { |
duke@435 | 259 | compiler_frame_d_scratch_fp_offset = -2, |
duke@435 | 260 | compiler_frame_vm_locals_fp_offset = -2, // should be same as above |
duke@435 | 261 | |
duke@435 | 262 | compiler_frame_vm_local_words = -compiler_frame_vm_locals_fp_offset |
duke@435 | 263 | }; |
duke@435 | 264 | |
duke@435 | 265 | private: |
twisti@2142 | 266 | constantPoolCacheOop* interpreter_frame_cpoolcache_addr() const; |
duke@435 | 267 | |
duke@435 | 268 | #ifndef CC_INTERP |
duke@435 | 269 | |
duke@435 | 270 | // where Lmonitors is saved: |
duke@435 | 271 | BasicObjectLock** interpreter_frame_monitors_addr() const { |
duke@435 | 272 | return (BasicObjectLock**) sp_addr_at(Lmonitors->sp_offset_in_saved_window()); |
duke@435 | 273 | } |
duke@435 | 274 | intptr_t** interpreter_frame_esp_addr() const { |
duke@435 | 275 | return (intptr_t**)sp_addr_at(Lesp->sp_offset_in_saved_window()); |
duke@435 | 276 | } |
duke@435 | 277 | |
duke@435 | 278 | inline void interpreter_frame_set_tos_address(intptr_t* x); |
duke@435 | 279 | |
duke@435 | 280 | |
duke@435 | 281 | // %%%%% Another idea: instead of defining 3 fns per item, just define one returning a ref |
duke@435 | 282 | |
duke@435 | 283 | // monitors: |
duke@435 | 284 | |
duke@435 | 285 | // next two fns read and write Lmonitors value, |
duke@435 | 286 | private: |
duke@435 | 287 | BasicObjectLock* interpreter_frame_monitors() const { return *interpreter_frame_monitors_addr(); } |
duke@435 | 288 | void interpreter_frame_set_monitors(BasicObjectLock* monitors) { *interpreter_frame_monitors_addr() = monitors; } |
duke@435 | 289 | #else |
duke@435 | 290 | public: |
duke@435 | 291 | inline interpreterState get_interpreterState() const { |
duke@435 | 292 | return ((interpreterState)sp_at(interpreter_state_ptr_offset)); |
duke@435 | 293 | } |
duke@435 | 294 | |
duke@435 | 295 | |
duke@435 | 296 | #endif /* CC_INTERP */ |
duke@435 | 297 | |
duke@435 | 298 | |
duke@435 | 299 | |
duke@435 | 300 | // Compiled frames |
duke@435 | 301 | |
duke@435 | 302 | public: |
duke@435 | 303 | // Tells if this register can hold 64 bits on V9 (really, V8+). |
duke@435 | 304 | static bool holds_a_doubleword(Register reg) { |
duke@435 | 305 | #ifdef _LP64 |
duke@435 | 306 | // return true; |
duke@435 | 307 | return reg->is_out() || reg->is_global(); |
duke@435 | 308 | #else |
duke@435 | 309 | return reg->is_out() || reg->is_global(); |
duke@435 | 310 | #endif |
duke@435 | 311 | } |