src/cpu/mips/vm/sharedRuntime_mips_64.cpp

Mon, 13 Nov 2017 15:49:42 +0800

author
aoqi
date
Mon, 13 Nov 2017 15:49:42 +0800
changeset 8009
0477693968a6
parent 7997
6cbff0651f1a
child 9043
7519f4bf92b5
permissions
-rw-r--r--

#5963 wrong frame offset (SP) in StackOverflowError handler
Summary: push/pop before/after bang_stack_with_offset is removed. compiler/6865265/StackOverflowBug.java passed.
This patch also includes code cleanup and code style fix.

aoqi@1 1 /*
aoqi@1 2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@1 3 * Copyright (c) 2015, 2016, Loongson Technology. All rights reserved.
aoqi@1 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@1 5 *
aoqi@1 6 * This code is free software; you can redistribute it and/or modify it
aoqi@1 7 * under the terms of the GNU General Public License version 2 only, as
aoqi@1 8 * published by the Free Software Foundation.
aoqi@1 9 *
aoqi@1 10 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@1 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@1 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@1 13 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@1 14 * accompanied this code).
aoqi@1 15 *
aoqi@1 16 * You should have received a copy of the GNU General Public License version
aoqi@1 17 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@1 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@1 19 *
aoqi@1 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@1 21 * or visit www.oracle.com if you need additional information or have any
aoqi@1 22 * questions.
aoqi@1 23 *
aoqi@1 24 */
aoqi@1 25
aoqi@1 26 #include "precompiled.hpp"
aoqi@1 27 #include "asm/macroAssembler.hpp"
aoqi@1 28 #include "asm/macroAssembler.inline.hpp"
aoqi@1 29 #include "code/debugInfoRec.hpp"
aoqi@1 30 #include "code/icBuffer.hpp"
aoqi@1 31 #include "code/vtableStubs.hpp"
aoqi@1 32 #include "interpreter/interpreter.hpp"
aoqi@1 33 #include "oops/compiledICHolder.hpp"
aoqi@1 34 #include "prims/jvmtiRedefineClassesTrace.hpp"
aoqi@1 35 #include "runtime/sharedRuntime.hpp"
aoqi@1 36 #include "runtime/vframeArray.hpp"
aoqi@1 37 #include "vmreg_mips.inline.hpp"
aoqi@1 38 #ifdef COMPILER1
aoqi@1 39 #include "c1/c1_Runtime1.hpp"
aoqi@1 40 #endif
aoqi@1 41 #ifdef COMPILER2
aoqi@1 42 #include "opto/runtime.hpp"
aoqi@1 43 #endif
aoqi@1 44
aoqi@1 45 #define __ masm->
aoqi@6880 46
aoqi@1 47 const int StackAlignmentInSlots = StackAlignmentInBytes / VMRegImpl::stack_slot_size;
aoqi@1 48
aoqi@1 49 class RegisterSaver {
aoqi@6880 50 enum { FPU_regs_live = 32 };
aoqi@6880 51 // Capture info about frame layout
aoqi@6880 52 enum layout {
aoqi@1 53 #define DEF_LAYOUT_OFFS(regname) regname ## _off, regname ## H_off,
aoqi@6880 54 DEF_LAYOUT_OFFS(for_16_bytes_aligned)
aoqi@6880 55 DEF_LAYOUT_OFFS(fpr0)
aoqi@6880 56 DEF_LAYOUT_OFFS(fpr1)
aoqi@6880 57 DEF_LAYOUT_OFFS(fpr2)
aoqi@6880 58 DEF_LAYOUT_OFFS(fpr3)
aoqi@6880 59 DEF_LAYOUT_OFFS(fpr4)
aoqi@6880 60 DEF_LAYOUT_OFFS(fpr5)
aoqi@6880 61 DEF_LAYOUT_OFFS(fpr6)
aoqi@6880 62 DEF_LAYOUT_OFFS(fpr7)
aoqi@6880 63 DEF_LAYOUT_OFFS(fpr8)
aoqi@6880 64 DEF_LAYOUT_OFFS(fpr9)
aoqi@6880 65 DEF_LAYOUT_OFFS(fpr10)
aoqi@6880 66 DEF_LAYOUT_OFFS(fpr11)
aoqi@6880 67 DEF_LAYOUT_OFFS(fpr12)
aoqi@6880 68 DEF_LAYOUT_OFFS(fpr13)
aoqi@6880 69 DEF_LAYOUT_OFFS(fpr14)
aoqi@6880 70 DEF_LAYOUT_OFFS(fpr15)
aoqi@6880 71 DEF_LAYOUT_OFFS(fpr16)
aoqi@6880 72 DEF_LAYOUT_OFFS(fpr17)
aoqi@6880 73 DEF_LAYOUT_OFFS(fpr18)
aoqi@6880 74 DEF_LAYOUT_OFFS(fpr19)
aoqi@6880 75 DEF_LAYOUT_OFFS(fpr20)
aoqi@6880 76 DEF_LAYOUT_OFFS(fpr21)
aoqi@6880 77 DEF_LAYOUT_OFFS(fpr22)
aoqi@6880 78 DEF_LAYOUT_OFFS(fpr23)
aoqi@6880 79 DEF_LAYOUT_OFFS(fpr24)
aoqi@6880 80 DEF_LAYOUT_OFFS(fpr25)
aoqi@6880 81 DEF_LAYOUT_OFFS(fpr26)
aoqi@6880 82 DEF_LAYOUT_OFFS(fpr27)
aoqi@6880 83 DEF_LAYOUT_OFFS(fpr28)
aoqi@6880 84 DEF_LAYOUT_OFFS(fpr29)
aoqi@6880 85 DEF_LAYOUT_OFFS(fpr30)
aoqi@6880 86 DEF_LAYOUT_OFFS(fpr31)
aoqi@6880 87
aoqi@6880 88 DEF_LAYOUT_OFFS(v0)
aoqi@6880 89 DEF_LAYOUT_OFFS(v1)
aoqi@6880 90 DEF_LAYOUT_OFFS(a0)
aoqi@6880 91 DEF_LAYOUT_OFFS(a1)
aoqi@6880 92 DEF_LAYOUT_OFFS(a2)
aoqi@6880 93 DEF_LAYOUT_OFFS(a3)
aoqi@6880 94 DEF_LAYOUT_OFFS(a4)
aoqi@6880 95 DEF_LAYOUT_OFFS(a5)
aoqi@6880 96 DEF_LAYOUT_OFFS(a6)
aoqi@6880 97 DEF_LAYOUT_OFFS(a7)
aoqi@6880 98 DEF_LAYOUT_OFFS(t0)
aoqi@6880 99 DEF_LAYOUT_OFFS(t1)
aoqi@6880 100 DEF_LAYOUT_OFFS(t2)
aoqi@6880 101 DEF_LAYOUT_OFFS(t3)
aoqi@6880 102 DEF_LAYOUT_OFFS(s0)
aoqi@6880 103 DEF_LAYOUT_OFFS(s1)
aoqi@6880 104 DEF_LAYOUT_OFFS(s2)
aoqi@6880 105 DEF_LAYOUT_OFFS(s3)
aoqi@6880 106 DEF_LAYOUT_OFFS(s4)
aoqi@6880 107 DEF_LAYOUT_OFFS(s5)
aoqi@6880 108 DEF_LAYOUT_OFFS(s6)
aoqi@6880 109 DEF_LAYOUT_OFFS(s7)
aoqi@6880 110 DEF_LAYOUT_OFFS(t8)
aoqi@6880 111 DEF_LAYOUT_OFFS(t9)
aoqi@6880 112
aoqi@6880 113 DEF_LAYOUT_OFFS(gp)
aoqi@6880 114 DEF_LAYOUT_OFFS(fp)
aoqi@6880 115 DEF_LAYOUT_OFFS(return)
aoqi@6880 116 reg_save_size
aoqi@6880 117 };
aoqi@1 118
aoqi@1 119 public:
aoqi@1 120
aoqi@6880 121 static OopMap* save_live_registers(MacroAssembler* masm, int additional_frame_words, int* total_frame_words, bool save_vectors =false );
aoqi@6880 122 static void restore_live_registers(MacroAssembler* masm, bool restore_vectors = false);
aoqi@6880 123 static int raOffset(void) { return return_off / 2; }
aoqi@6880 124 //Rmethod
aoqi@6880 125 static int methodOffset(void) { return s3_off / 2; }
aoqi@6880 126
aoqi@6880 127 static int v0Offset(void) { return v0_off / 2; }
aoqi@6880 128 static int v1Offset(void) { return v1_off / 2; }
aoqi@6880 129
aoqi@6880 130 static int fpResultOffset(void) { return fpr0_off / 2; }
aoqi@6880 131
aoqi@6880 132 // During deoptimization only the result register need to be restored
aoqi@6880 133 // all the other values have already been extracted.
aoqi@6880 134 static void restore_result_registers(MacroAssembler* masm);
aoqi@1 135 };
aoqi@1 136
aoqi@1 137 OopMap* RegisterSaver::save_live_registers(MacroAssembler* masm, int additional_frame_words, int* total_frame_words, bool save_vectors ) {
aoqi@1 138
aoqi@1 139 /*
aoqi@1 140 int frame_words = reg_save_size + additional_frame_words;
aoqi@1 141 int frame_size_in_bytes = frame_words * wordSize;
aoqi@1 142 *total_frame_words = frame_words;
aoqi@1 143 */
aoqi@1 144 // Always make the frame size 16-byte aligned
aoqi@1 145 int frame_size_in_bytes = round_to(additional_frame_words*wordSize +
aoqi@1 146 reg_save_size*BytesPerInt, 16);
aoqi@1 147 // OopMap frame size is in compiler stack slots (jint's) not bytes or words
aoqi@1 148 int frame_size_in_slots = frame_size_in_bytes / BytesPerInt;
aoqi@1 149 // The caller will allocate additional_frame_words
aoqi@1 150 int additional_frame_slots = additional_frame_words*wordSize / BytesPerInt;
aoqi@1 151 // CodeBlob frame size is in words.
aoqi@1 152 int frame_size_in_words = frame_size_in_bytes / wordSize;
aoqi@1 153 *total_frame_words = frame_size_in_words;
aoqi@1 154
aoqi@6880 155 // save registers, fpu state, and flags
aoqi@1 156 // We assume caller has already has return address slot on the stack
aoqi@1 157 // We push epb twice in this sequence because we want the real ebp
aoqi@1 158 // to be under the return like a normal enter and we want to use pushad
aoqi@1 159 // We push by hand instead of pusing push
aoqi@1 160
aoqi@1 161 __ daddiu(SP, SP, - reg_save_size * jintSize);
aoqi@1 162
aoqi@1 163 __ sdc1(F0, SP, fpr0_off * jintSize); __ sdc1(F1, SP, fpr1_off * jintSize);
aoqi@1 164 __ sdc1(F2, SP, fpr2_off * jintSize); __ sdc1(F3, SP, fpr3_off * jintSize);
aoqi@1 165 __ sdc1(F4, SP, fpr4_off * jintSize); __ sdc1(F5, SP, fpr5_off * jintSize);
aoqi@6880 166 __ sdc1(F6, SP, fpr6_off * jintSize); __ sdc1(F7, SP, fpr7_off * jintSize);
aoqi@6880 167 __ sdc1(F8, SP, fpr8_off * jintSize); __ sdc1(F9, SP, fpr9_off * jintSize);
aoqi@6880 168 __ sdc1(F10, SP, fpr10_off * jintSize); __ sdc1(F11, SP, fpr11_off * jintSize);
aoqi@6880 169 __ sdc1(F12, SP, fpr12_off * jintSize); __ sdc1(F13, SP, fpr13_off * jintSize);
aoqi@6880 170 __ sdc1(F14, SP, fpr14_off * jintSize); __ sdc1(F15, SP, fpr15_off * jintSize);
aoqi@6880 171 __ sdc1(F16, SP, fpr16_off * jintSize); __ sdc1(F17, SP, fpr17_off * jintSize);
aoqi@6880 172 __ sdc1(F18, SP, fpr18_off * jintSize); __ sdc1(F19, SP, fpr19_off * jintSize);
aoqi@6880 173 __ sdc1(F20, SP, fpr20_off * jintSize); __ sdc1(F21, SP, fpr21_off * jintSize);
aoqi@6880 174 __ sdc1(F22, SP, fpr22_off * jintSize); __ sdc1(F23, SP, fpr23_off * jintSize);
aoqi@6880 175 __ sdc1(F24, SP, fpr24_off * jintSize); __ sdc1(F25, SP, fpr25_off * jintSize);
aoqi@6880 176 __ sdc1(F26, SP, fpr26_off * jintSize); __ sdc1(F27, SP, fpr27_off * jintSize);
aoqi@6880 177 __ sdc1(F28, SP, fpr28_off * jintSize); __ sdc1(F29, SP, fpr29_off * jintSize);
aoqi@6880 178 __ sdc1(F30, SP, fpr30_off * jintSize); __ sdc1(F31, SP, fpr31_off * jintSize);
aoqi@6880 179 __ sd(V0, SP, v0_off * jintSize); __ sd(V1, SP, v1_off * jintSize);
aoqi@6880 180 __ sd(A0, SP, a0_off * jintSize); __ sd(A1, SP, a1_off * jintSize);
aoqi@6880 181 __ sd(A2, SP, a2_off * jintSize); __ sd(A3, SP, a3_off * jintSize);
aoqi@6880 182 __ sd(A4, SP, a4_off * jintSize); __ sd(A5, SP, a5_off * jintSize);
aoqi@6880 183 __ sd(A6, SP, a6_off * jintSize); __ sd(A7, SP, a7_off * jintSize);
aoqi@1 184 __ sd(T0, SP, t0_off * jintSize);
aoqi@1 185 __ sd(T1, SP, t1_off * jintSize);
aoqi@1 186 __ sd(T2, SP, t2_off * jintSize);
aoqi@1 187 __ sd(T3, SP, t3_off * jintSize);
aoqi@1 188 __ sd(S0, SP, s0_off * jintSize);
aoqi@1 189 __ sd(S1, SP, s1_off * jintSize);
aoqi@1 190 __ sd(S2, SP, s2_off * jintSize);
aoqi@1 191 __ sd(S3, SP, s3_off * jintSize);
aoqi@1 192 __ sd(S4, SP, s4_off * jintSize);
aoqi@1 193 __ sd(S5, SP, s5_off * jintSize);
aoqi@1 194 __ sd(S6, SP, s6_off * jintSize);
aoqi@1 195 __ sd(S7, SP, s7_off * jintSize);
aoqi@1 196
aoqi@1 197 __ sd(T8, SP, t8_off * jintSize);
aoqi@1 198 __ sd(T9, SP, t9_off * jintSize);
aoqi@1 199
aoqi@1 200 __ sd(GP, SP, gp_off * jintSize);
aoqi@1 201 __ sd(FP, SP, fp_off * jintSize);
aoqi@1 202 __ sd(RA, SP, return_off * jintSize);
aoqi@1 203 __ daddi(FP, SP, fp_off * jintSize);
aoqi@1 204
aoqi@1 205 OopMapSet *oop_maps = new OopMapSet();
aoqi@6880 206 //OopMap* map = new OopMap( frame_words, 0 );
aoqi@6880 207 OopMap* map = new OopMap( frame_size_in_slots, 0 );
aoqi@1 208
aoqi@1 209
aoqi@1 210 //#define STACK_OFFSET(x) VMRegImpl::stack2reg((x) + additional_frame_words)
aoqi@1 211 #define STACK_OFFSET(x) VMRegImpl::stack2reg((x) + additional_frame_slots)
aoqi@1 212 map->set_callee_saved(STACK_OFFSET( v0_off), V0->as_VMReg());
aoqi@1 213 map->set_callee_saved(STACK_OFFSET( v1_off), V1->as_VMReg());
aoqi@1 214 map->set_callee_saved(STACK_OFFSET( a0_off), A0->as_VMReg());
aoqi@1 215 map->set_callee_saved(STACK_OFFSET( a1_off), A1->as_VMReg());
aoqi@1 216 map->set_callee_saved(STACK_OFFSET( a2_off), A2->as_VMReg());
aoqi@1 217 map->set_callee_saved(STACK_OFFSET( a3_off), A3->as_VMReg());
aoqi@1 218 map->set_callee_saved(STACK_OFFSET( a4_off), A4->as_VMReg());
aoqi@1 219 map->set_callee_saved(STACK_OFFSET( a5_off), A5->as_VMReg());
aoqi@1 220 map->set_callee_saved(STACK_OFFSET( a6_off), A6->as_VMReg());
aoqi@1 221 map->set_callee_saved(STACK_OFFSET( a7_off), A7->as_VMReg());
aoqi@1 222 map->set_callee_saved(STACK_OFFSET( t0_off), T0->as_VMReg());
aoqi@1 223 map->set_callee_saved(STACK_OFFSET( t1_off), T1->as_VMReg());
aoqi@1 224 map->set_callee_saved(STACK_OFFSET( t2_off), T2->as_VMReg());
aoqi@1 225 map->set_callee_saved(STACK_OFFSET( t3_off), T3->as_VMReg());
aoqi@1 226 map->set_callee_saved(STACK_OFFSET( s0_off), S0->as_VMReg());
aoqi@1 227 map->set_callee_saved(STACK_OFFSET( s1_off), S1->as_VMReg());
aoqi@1 228 map->set_callee_saved(STACK_OFFSET( s2_off), S2->as_VMReg());
aoqi@1 229 map->set_callee_saved(STACK_OFFSET( s3_off), S3->as_VMReg());
aoqi@1 230 map->set_callee_saved(STACK_OFFSET( s4_off), S4->as_VMReg());
aoqi@1 231 map->set_callee_saved(STACK_OFFSET( s5_off), S5->as_VMReg());
aoqi@1 232 map->set_callee_saved(STACK_OFFSET( s6_off), S6->as_VMReg());
aoqi@1 233 map->set_callee_saved(STACK_OFFSET( s7_off), S7->as_VMReg());
aoqi@1 234 map->set_callee_saved(STACK_OFFSET( t8_off), T8->as_VMReg());
aoqi@1 235 map->set_callee_saved(STACK_OFFSET( t9_off), T9->as_VMReg());
aoqi@1 236 map->set_callee_saved(STACK_OFFSET( gp_off), GP->as_VMReg());
aoqi@1 237 map->set_callee_saved(STACK_OFFSET( fp_off), FP->as_VMReg());
aoqi@1 238 map->set_callee_saved(STACK_OFFSET( return_off), RA->as_VMReg());
aoqi@1 239
aoqi@1 240 map->set_callee_saved(STACK_OFFSET( fpr0_off), F0->as_VMReg());
aoqi@1 241 map->set_callee_saved(STACK_OFFSET( fpr1_off), F1->as_VMReg());
aoqi@1 242 map->set_callee_saved(STACK_OFFSET( fpr2_off), F2->as_VMReg());
aoqi@1 243 map->set_callee_saved(STACK_OFFSET( fpr3_off), F3->as_VMReg());
aoqi@1 244 map->set_callee_saved(STACK_OFFSET( fpr4_off), F4->as_VMReg());
aoqi@1 245 map->set_callee_saved(STACK_OFFSET( fpr5_off), F5->as_VMReg());
aoqi@1 246 map->set_callee_saved(STACK_OFFSET( fpr6_off), F6->as_VMReg());
aoqi@1 247 map->set_callee_saved(STACK_OFFSET( fpr7_off), F7->as_VMReg());
aoqi@1 248 map->set_callee_saved(STACK_OFFSET( fpr8_off), F8->as_VMReg());
aoqi@1 249 map->set_callee_saved(STACK_OFFSET( fpr9_off), F9->as_VMReg());
aoqi@1 250 map->set_callee_saved(STACK_OFFSET( fpr10_off), F10->as_VMReg());
aoqi@1 251 map->set_callee_saved(STACK_OFFSET( fpr11_off), F11->as_VMReg());
aoqi@1 252 map->set_callee_saved(STACK_OFFSET( fpr12_off), F12->as_VMReg());
aoqi@1 253 map->set_callee_saved(STACK_OFFSET( fpr13_off), F13->as_VMReg());
aoqi@1 254 map->set_callee_saved(STACK_OFFSET( fpr14_off), F14->as_VMReg());
aoqi@1 255 map->set_callee_saved(STACK_OFFSET( fpr15_off), F15->as_VMReg());
aoqi@1 256 map->set_callee_saved(STACK_OFFSET( fpr16_off), F16->as_VMReg());
aoqi@1 257 map->set_callee_saved(STACK_OFFSET( fpr17_off), F17->as_VMReg());
aoqi@1 258 map->set_callee_saved(STACK_OFFSET( fpr18_off), F18->as_VMReg());
aoqi@1 259 map->set_callee_saved(STACK_OFFSET( fpr19_off), F19->as_VMReg());
aoqi@1 260 map->set_callee_saved(STACK_OFFSET( fpr20_off), F20->as_VMReg());
aoqi@1 261 map->set_callee_saved(STACK_OFFSET( fpr21_off), F21->as_VMReg());
aoqi@1 262 map->set_callee_saved(STACK_OFFSET( fpr22_off), F22->as_VMReg());
aoqi@1 263 map->set_callee_saved(STACK_OFFSET( fpr23_off), F23->as_VMReg());
aoqi@1 264 map->set_callee_saved(STACK_OFFSET( fpr24_off), F24->as_VMReg());
aoqi@1 265 map->set_callee_saved(STACK_OFFSET( fpr25_off), F25->as_VMReg());
aoqi@1 266 map->set_callee_saved(STACK_OFFSET( fpr26_off), F26->as_VMReg());
aoqi@1 267 map->set_callee_saved(STACK_OFFSET( fpr27_off), F27->as_VMReg());
aoqi@1 268 map->set_callee_saved(STACK_OFFSET( fpr28_off), F28->as_VMReg());
aoqi@1 269 map->set_callee_saved(STACK_OFFSET( fpr29_off), F29->as_VMReg());
aoqi@1 270 map->set_callee_saved(STACK_OFFSET( fpr30_off), F30->as_VMReg());
aoqi@1 271 map->set_callee_saved(STACK_OFFSET( fpr31_off), F31->as_VMReg());
aoqi@1 272
aoqi@1 273 #undef STACK_OFFSET
aoqi@1 274 return map;
aoqi@1 275 }
aoqi@1 276
aoqi@1 277
aoqi@1 278 // Pop the current frame and restore all the registers that we
aoqi@1 279 // saved.
aoqi@1 280 void RegisterSaver::restore_live_registers(MacroAssembler* masm, bool restore_vectors) {
aoqi@1 281 __ ldc1(F0, SP, fpr0_off * jintSize); __ ldc1(F1, SP, fpr1_off * jintSize);
aoqi@1 282 __ ldc1(F2, SP, fpr2_off * jintSize); __ ldc1(F3, SP, fpr3_off * jintSize);
aoqi@1 283 __ ldc1(F4, SP, fpr4_off * jintSize); __ ldc1(F5, SP, fpr5_off * jintSize);
aoqi@6880 284 __ ldc1(F6, SP, fpr6_off * jintSize); __ ldc1(F7, SP, fpr7_off * jintSize);
aoqi@6880 285 __ ldc1(F8, SP, fpr8_off * jintSize); __ ldc1(F9, SP, fpr9_off * jintSize);
aoqi@6880 286 __ ldc1(F10, SP, fpr10_off * jintSize); __ ldc1(F11, SP, fpr11_off * jintSize);
aoqi@6880 287 __ ldc1(F12, SP, fpr12_off * jintSize); __ ldc1(F13, SP, fpr13_off * jintSize);
aoqi@6880 288 __ ldc1(F14, SP, fpr14_off * jintSize); __ ldc1(F15, SP, fpr15_off * jintSize);
aoqi@6880 289 __ ldc1(F16, SP, fpr16_off * jintSize); __ ldc1(F17, SP, fpr17_off * jintSize);
aoqi@6880 290 __ ldc1(F18, SP, fpr18_off * jintSize); __ ldc1(F19, SP, fpr19_off * jintSize);
aoqi@6880 291 __ ldc1(F20, SP, fpr20_off * jintSize); __ ldc1(F21, SP, fpr21_off * jintSize);
aoqi@6880 292 __ ldc1(F22, SP, fpr22_off * jintSize); __ ldc1(F23, SP, fpr23_off * jintSize);
aoqi@6880 293 __ ldc1(F24, SP, fpr24_off * jintSize); __ ldc1(F25, SP, fpr25_off * jintSize);
aoqi@6880 294 __ ldc1(F26, SP, fpr26_off * jintSize); __ ldc1(F27, SP, fpr27_off * jintSize);
aoqi@6880 295 __ ldc1(F28, SP, fpr28_off * jintSize); __ ldc1(F29, SP, fpr29_off * jintSize);
aoqi@6880 296 __ ldc1(F30, SP, fpr30_off * jintSize); __ ldc1(F31, SP, fpr31_off * jintSize);
aoqi@6880 297
aoqi@6880 298 __ ld(V0, SP, v0_off * jintSize); __ ld(V1, SP, v1_off * jintSize);
aoqi@6880 299 __ ld(A0, SP, a0_off * jintSize); __ ld(A1, SP, a1_off * jintSize);
aoqi@6880 300 __ ld(A2, SP, a2_off * jintSize); __ ld(A3, SP, a3_off * jintSize);
aoqi@6880 301 __ ld(A4, SP, a4_off * jintSize); __ ld(A5, SP, a5_off * jintSize);
aoqi@6880 302 __ ld(A6, SP, a6_off * jintSize); __ ld(A7, SP, a7_off * jintSize);
aoqi@1 303 __ ld(T0, SP, t0_off * jintSize);
aoqi@1 304 __ ld(T1, SP, t1_off * jintSize);
aoqi@1 305 __ ld(T2, SP, t2_off * jintSize);
aoqi@1 306 __ ld(T3, SP, t3_off * jintSize);
aoqi@1 307 __ ld(S0, SP, s0_off * jintSize);
aoqi@1 308 __ ld(S1, SP, s1_off * jintSize);
aoqi@1 309 __ ld(S2, SP, s2_off * jintSize);
aoqi@1 310 __ ld(S3, SP, s3_off * jintSize);
aoqi@1 311 __ ld(S4, SP, s4_off * jintSize);
aoqi@1 312 __ ld(S5, SP, s5_off * jintSize);
aoqi@1 313 __ ld(S6, SP, s6_off * jintSize);
aoqi@1 314 __ ld(S7, SP, s7_off * jintSize);
aoqi@1 315
aoqi@1 316 __ ld(T8, SP, t8_off * jintSize);
aoqi@1 317 __ ld(T9, SP, t9_off * jintSize);
aoqi@1 318
aoqi@1 319 __ ld(GP, SP, gp_off * jintSize);
aoqi@1 320 __ ld(FP, SP, fp_off * jintSize);
aoqi@1 321 __ ld(RA, SP, return_off * jintSize);
aoqi@1 322
aoqi@1 323 __ addiu(SP, SP, reg_save_size * jintSize);
aoqi@1 324 }
aoqi@1 325
aoqi@1 326 // Pop the current frame and restore the registers that might be holding
aoqi@1 327 // a result.
aoqi@1 328 // FIXME, if the result is float?
aoqi@1 329 void RegisterSaver::restore_result_registers(MacroAssembler* masm) {
aoqi@6880 330
aoqi@1 331 // Just restore result register. Only used by deoptimization. By
aoqi@1 332 // now any callee save register that needs to be restore to a c2
aoqi@1 333 // caller of the deoptee has been extracted into the vframeArray
aoqi@1 334 // and will be stuffed into the c2i adapter we create for later
aoqi@1 335 // restoration so only result registers need to be restored here.
aoqi@6880 336
aoqi@1 337 __ ld(V0, SP, v0_off * jintSize);
aoqi@1 338 __ ld(V1, SP, v1_off * jintSize);
aoqi@6880 339 __ addiu(SP, SP, return_off * jintSize);
aoqi@1 340 }
aoqi@1 341
aoqi@6880 342 // Is vector's size (in bytes) bigger than a size saved by default?
aoqi@6880 343 // 16 bytes XMM registers are saved by default using fxsave/fxrstor instructions.
aoqi@6880 344 bool SharedRuntime::is_wide_vector(int size) {
aoqi@6880 345 return size > 16;
aoqi@6880 346 }
aoqi@1 347
aoqi@1 348 // The java_calling_convention describes stack locations as ideal slots on
aoqi@1 349 // a frame with no abi restrictions. Since we must observe abi restrictions
aoqi@1 350 // (like the placement of the register window) the slots must be biased by
aoqi@1 351 // the following value.
aoqi@1 352
aoqi@6880 353 static int reg2offset_in(VMReg r) {
aoqi@6880 354 // Account for saved ebp and return address
aoqi@6880 355 // This should really be in_preserve_stack_slots
aoqi@6880 356 return (r->reg2stack() + 2 * VMRegImpl::slots_per_word) * VMRegImpl::stack_slot_size; // + 2 * VMRegImpl::stack_slot_size);
aoqi@1 357 }
aoqi@1 358
aoqi@6880 359 static int reg2offset_out(VMReg r) {
aoqi@6880 360 return (r->reg2stack() + SharedRuntime::out_preserve_stack_slots()) * VMRegImpl::stack_slot_size;
aoqi@1 361 }
aoqi@1 362
aoqi@1 363 // ---------------------------------------------------------------------------
aoqi@1 364 // Read the array of BasicTypes from a signature, and compute where the
aoqi@1 365 // arguments should go. Values in the VMRegPair regs array refer to 4-byte
aoqi@1 366 // quantities. Values less than SharedInfo::stack0 are registers, those above
aoqi@1 367 // refer to 4-byte stack slots. All stack slots are based off of the stack pointer
aoqi@1 368 // as framesizes are fixed.
aoqi@1 369 // VMRegImpl::stack0 refers to the first slot 0(sp).
aoqi@1 370 // and VMRegImpl::stack0+1 refers to the memory word 4-byes higher. Register
aoqi@1 371 // up to RegisterImpl::number_of_registers) are the 32-bit
aoqi@1 372 // integer registers.
aoqi@1 373
aoqi@1 374 // Pass first five oop/int args in registers T0, A0 - A3.
aoqi@1 375 // Pass float/double/long args in stack.
aoqi@1 376 // Doubles have precedence, so if you pass a mix of floats and doubles
aoqi@1 377 // the doubles will grab the registers before the floats will.
aoqi@1 378
aoqi@1 379 // Note: the INPUTS in sig_bt are in units of Java argument words, which are
aoqi@1 380 // either 32-bit or 64-bit depending on the build. The OUTPUTS are in 32-bit
aoqi@1 381 // units regardless of build. Of course for i486 there is no 64 bit build
aoqi@1 382
aoqi@1 383
aoqi@1 384 // ---------------------------------------------------------------------------
aoqi@1 385 // The compiled Java calling convention.
aoqi@1 386 // Pass first five oop/int args in registers T0, A0 - A3.
aoqi@1 387 // Pass float/double/long args in stack.
aoqi@1 388 // Doubles have precedence, so if you pass a mix of floats and doubles
aoqi@1 389 // the doubles will grab the registers before the floats will.
aoqi@1 390
aoqi@1 391 int SharedRuntime::java_calling_convention(const BasicType *sig_bt,
aoqi@1 392 VMRegPair *regs,
aoqi@1 393 int total_args_passed,
aoqi@1 394 int is_outgoing) {
aoqi@1 395
aoqi@1 396 // Create the mapping between argument positions and
aoqi@1 397 // registers.
aoqi@1 398 //static const Register INT_ArgReg[Argument::n_int_register_parameters_j] = {
aoqi@1 399 static const Register INT_ArgReg[Argument::n_register_parameters + 1] = {
aoqi@1 400 T0, A0, A1, A2, A3, A4, A5, A6, A7
aoqi@1 401 };
aoqi@1 402 //static const FloatRegister FP_ArgReg[Argument::n_float_register_parameters_j] = {
aoqi@1 403 static const FloatRegister FP_ArgReg[Argument::n_float_register_parameters] = {
aoqi@1 404 F12, F13, F14, F15, F16, F17, F18, F19
aoqi@1 405 };
aoqi@1 406
aoqi@1 407
aoqi@1 408 uint args = 0;
aoqi@1 409 uint stk_args = 0; // inc by 2 each time
aoqi@1 410
aoqi@1 411 for (int i = 0; i < total_args_passed; i++) {
aoqi@1 412 switch (sig_bt[i]) {
aoqi@1 413 case T_VOID:
aoqi@1 414 // halves of T_LONG or T_DOUBLE
aoqi@1 415 assert(i != 0 && (sig_bt[i - 1] == T_LONG || sig_bt[i - 1] == T_DOUBLE), "expecting half");
aoqi@1 416 regs[i].set_bad();
aoqi@1 417 break;
aoqi@1 418 case T_BOOLEAN:
aoqi@1 419 case T_CHAR:
aoqi@1 420 case T_BYTE:
aoqi@1 421 case T_SHORT:
aoqi@1 422 case T_INT:
aoqi@1 423 if (args < Argument::n_register_parameters) {
aoqi@1 424 regs[i].set1(INT_ArgReg[args++]->as_VMReg());
aoqi@1 425 } else {
aoqi@1 426 regs[i].set1(VMRegImpl::stack2reg(stk_args));
aoqi@1 427 stk_args += 2;
aoqi@1 428 }
aoqi@1 429 break;
aoqi@1 430 case T_LONG:
aoqi@1 431 assert(sig_bt[i + 1] == T_VOID, "expecting half");
aoqi@1 432 // fall through
aoqi@1 433 case T_OBJECT:
aoqi@1 434 case T_ARRAY:
aoqi@1 435 case T_ADDRESS:
aoqi@1 436 if (args < Argument::n_register_parameters) {
aoqi@1 437 regs[i].set2(INT_ArgReg[args++]->as_VMReg());
aoqi@1 438 } else {
aoqi@1 439 regs[i].set2(VMRegImpl::stack2reg(stk_args));
aoqi@1 440 stk_args += 2;
aoqi@1 441 }
aoqi@1 442 break;
aoqi@1 443 case T_FLOAT:
aoqi@1 444 if (args < Argument::n_float_register_parameters) {
aoqi@1 445 regs[i].set1(FP_ArgReg[args++]->as_VMReg());
aoqi@1 446 } else {
aoqi@1 447 regs[i].set1(VMRegImpl::stack2reg(stk_args));
aoqi@1 448 stk_args += 2;
aoqi@1 449 }
aoqi@1 450 break;
aoqi@1 451 case T_DOUBLE:
aoqi@1 452 assert(sig_bt[i + 1] == T_VOID, "expecting half");
aoqi@1 453 if (args < Argument::n_float_register_parameters) {
aoqi@1 454 regs[i].set2(FP_ArgReg[args++]->as_VMReg());
aoqi@1 455 } else {
aoqi@1 456 regs[i].set2(VMRegImpl::stack2reg(stk_args));
aoqi@1 457 stk_args += 2;
aoqi@1 458 }
aoqi@1 459 break;
aoqi@1 460 default:
aoqi@1 461 ShouldNotReachHere();
aoqi@1 462 break;
aoqi@1 463 }
aoqi@1 464 }
aoqi@1 465
aoqi@1 466 return round_to(stk_args, 2);
aoqi@1 467 }
aoqi@1 468
aoqi@1 469 // Helper class mostly to avoid passing masm everywhere, and handle store
aoqi@1 470 // displacement overflow logic for LP64
aoqi@1 471 class AdapterGenerator {
aoqi@1 472 MacroAssembler *masm;
aoqi@1 473 #ifdef _LP64
aoqi@1 474 Register Rdisp;
aoqi@1 475 void set_Rdisp(Register r) { Rdisp = r; }
aoqi@1 476 #endif // _LP64
aoqi@1 477
aoqi@1 478 void patch_callers_callsite();
aoqi@1 479
aoqi@1 480 // base+st_off points to top of argument
aoqi@1 481 int arg_offset(const int st_off) { return st_off; }
aoqi@1 482 int next_arg_offset(const int st_off) {
aoqi@1 483 return st_off - Interpreter::stackElementSize;
aoqi@1 484 }
aoqi@1 485
aoqi@1 486 #ifdef _LP64
aoqi@1 487 // On _LP64 argument slot values are loaded first into a register
aoqi@1 488 // because they might not fit into displacement.
aoqi@1 489 Register arg_slot(const int st_off);
aoqi@1 490 Register next_arg_slot(const int st_off);
aoqi@1 491 #else
aoqi@1 492 int arg_slot(const int st_off) { return arg_offset(st_off); }
aoqi@1 493 int next_arg_slot(const int st_off) { return next_arg_offset(st_off); }
aoqi@1 494 #endif // _LP64
aoqi@1 495
aoqi@1 496 // Stores long into offset pointed to by base
aoqi@1 497 void store_c2i_long(Register r, Register base,
aoqi@1 498 const int st_off, bool is_stack);
aoqi@1 499 void store_c2i_object(Register r, Register base,
aoqi@1 500 const int st_off);
aoqi@1 501 void store_c2i_int(Register r, Register base,
aoqi@1 502 const int st_off);
aoqi@1 503 void store_c2i_double(VMReg r_2,
aoqi@1 504 VMReg r_1, Register base, const int st_off);
aoqi@1 505 void store_c2i_float(FloatRegister f, Register base,
aoqi@1 506 const int st_off);
aoqi@1 507
aoqi@1 508 public:
aoqi@1 509 //void tag_stack(const BasicType sig, int st_off);
aoqi@1 510 void gen_c2i_adapter(int total_args_passed,
aoqi@1 511 // VMReg max_arg,
aoqi@1 512 int comp_args_on_stack, // VMRegStackSlots
aoqi@1 513 const BasicType *sig_bt,
aoqi@1 514 const VMRegPair *regs,
aoqi@1 515 Label& skip_fixup);
aoqi@1 516 void gen_i2c_adapter(int total_args_passed,
aoqi@1 517 // VMReg max_arg,
aoqi@1 518 int comp_args_on_stack, // VMRegStackSlots
aoqi@1 519 const BasicType *sig_bt,
aoqi@1 520 const VMRegPair *regs);
aoqi@1 521
aoqi@1 522 AdapterGenerator(MacroAssembler *_masm) : masm(_masm) {}
aoqi@1 523 };
aoqi@1 524
aoqi@1 525
aoqi@1 526 // Patch the callers callsite with entry to compiled code if it exists.
aoqi@1 527 void AdapterGenerator::patch_callers_callsite() {
aoqi@6880 528 Label L;
aoqi@6880 529 __ verify_oop(Rmethod);
aoqi@6880 530 __ ld_ptr(AT, Rmethod, in_bytes(Method::code_offset()));
aoqi@6880 531 __ beq(AT,R0,L);
aoqi@6880 532 __ delayed()->nop();
aoqi@6880 533 // Schedule the branch target address early.
aoqi@6880 534 // Call into the VM to patch the caller, then jump to compiled callee
aoqi@6880 535 // eax isn't live so capture return address while we easily can
aoqi@6880 536 __ move(V0, RA);
aoqi@6880 537
aoqi@6880 538 __ pushad();
aoqi@1 539 #ifdef COMPILER2
aoqi@6880 540 // C2 may leave the stack dirty if not in SSE2+ mode
aoqi@6880 541 __ empty_FPU_stack();
aoqi@1 542 #endif /* COMPILER2 */
aoqi@1 543
aoqi@6880 544 // VM needs caller's callsite
aoqi@6880 545 // VM needs target method
aoqi@6880 546
aoqi@6880 547 __ move(A0, Rmethod);
aoqi@6880 548 __ move(A1, V0);
aoqi@1 549 //we should preserve the return address
aoqi@6880 550 __ verify_oop(Rmethod);
aoqi@6880 551 __ move(S0, SP);
aoqi@6880 552 __ move(AT, -(StackAlignmentInBytes)); // align the stack
aoqi@6880 553 __ andr(SP, SP, AT);
aoqi@6880 554 __ call(CAST_FROM_FN_PTR(address, SharedRuntime::fixup_callers_callsite),
aoqi@6880 555 relocInfo::runtime_call_type);
aoqi@6880 556
aoqi@6880 557 __ delayed()->nop();
aoqi@6880 558 __ move(SP, S0);
aoqi@6880 559 __ popad();
aoqi@6880 560 __ bind(L);
aoqi@1 561 }
aoqi@1 562
aoqi@1 563 #ifdef _LP64
aoqi@1 564 Register AdapterGenerator::arg_slot(const int st_off) {
aoqi@6880 565 Unimplemented();
aoqi@1 566 }
aoqi@1 567
aoqi@1 568 Register AdapterGenerator::next_arg_slot(const int st_off){
aoqi@6880 569 Unimplemented();
aoqi@1 570 }
aoqi@1 571 #endif // _LP64
aoqi@1 572
aoqi@1 573 // Stores long into offset pointed to by base
aoqi@1 574 void AdapterGenerator::store_c2i_long(Register r, Register base,
aoqi@1 575 const int st_off, bool is_stack) {
aoqi@6880 576 Unimplemented();
aoqi@1 577 }
aoqi@1 578
aoqi@1 579 void AdapterGenerator::store_c2i_object(Register r, Register base,
aoqi@6880 580 const int st_off) {
aoqi@6880 581 Unimplemented();
aoqi@1 582 }
aoqi@1 583
aoqi@1 584 void AdapterGenerator::store_c2i_int(Register r, Register base,
aoqi@6880 585 const int st_off) {
aoqi@6880 586 Unimplemented();
aoqi@1 587 }
aoqi@1 588
aoqi@1 589 // Stores into offset pointed to by base
aoqi@1 590 void AdapterGenerator::store_c2i_double(VMReg r_2,
aoqi@1 591 VMReg r_1, Register base, const int st_off) {
aoqi@6880 592 Unimplemented();
aoqi@1 593 }
aoqi@1 594
aoqi@1 595 void AdapterGenerator::store_c2i_float(FloatRegister f, Register base,
aoqi@1 596 const int st_off) {
aoqi@6880 597 Unimplemented();
aoqi@1 598 }
aoqi@1 599
aoqi@1 600 void AdapterGenerator::gen_c2i_adapter(
aoqi@1 601 int total_args_passed,
aoqi@1 602 // VMReg max_arg,
aoqi@1 603 int comp_args_on_stack, // VMRegStackSlots
aoqi@1 604 const BasicType *sig_bt,
aoqi@1 605 const VMRegPair *regs,
aoqi@1 606 Label& skip_fixup) {
aoqi@1 607
aoqi@1 608 // Before we get into the guts of the C2I adapter, see if we should be here
aoqi@1 609 // at all. We've come from compiled code and are attempting to jump to the
aoqi@1 610 // interpreter, which means the caller made a static call to get here
aoqi@1 611 // (vcalls always get a compiled target if there is one). Check for a
aoqi@1 612 // compiled target. If there is one, we need to patch the caller's call.
aoqi@1 613 // However we will run interpreted if we come thru here. The next pass
aoqi@1 614 // thru the call site will run compiled. If we ran compiled here then
aoqi@1 615 // we can (theorectically) do endless i2c->c2i->i2c transitions during
aoqi@1 616 // deopt/uncommon trap cycles. If we always go interpreted here then
aoqi@1 617 // we can have at most one and don't need to play any tricks to keep
aoqi@1 618 // from endlessly growing the stack.
aoqi@1 619 //
aoqi@1 620 // Actually if we detected that we had an i2c->c2i transition here we
aoqi@1 621 // ought to be able to reset the world back to the state of the interpreted
aoqi@1 622 // call and not bother building another interpreter arg area. We don't
aoqi@1 623 // do that at this point.
aoqi@1 624
aoqi@6880 625 patch_callers_callsite();
aoqi@6880 626
aoqi@6880 627 __ bind(skip_fixup);
aoqi@1 628
aoqi@1 629 #ifdef COMPILER2
aoqi@6880 630 __ empty_FPU_stack();
aoqi@1 631 #endif /* COMPILER2 */
aoqi@6880 632 //this is for native ?
aoqi@6880 633 // Since all args are passed on the stack, total_args_passed * interpreter_
aoqi@6880 634 // stack_element_size is the
aoqi@6880 635 // space we need.
aoqi@6880 636 int extraspace = total_args_passed * Interpreter::stackElementSize;
aoqi@6880 637
aoqi@6880 638 // stack is aligned, keep it that way
aoqi@6880 639 extraspace = round_to(extraspace, 2*wordSize);
aoqi@6880 640
aoqi@6880 641 // Get return address
aoqi@6880 642 __ move(V0, RA);
aoqi@6880 643 // set senderSP value
aoqi@6880 644 //refer to interpreter_mips.cpp:generate_asm_entry
aoqi@6880 645 __ move(Rsender, SP);
aoqi@6880 646 __ addi(SP, SP, -extraspace);
aoqi@6880 647
aoqi@6880 648 // Now write the args into the outgoing interpreter space
aoqi@6880 649 for (int i = 0; i < total_args_passed; i++) {
aoqi@6880 650 if (sig_bt[i] == T_VOID) {
aoqi@6880 651 assert(i > 0 && (sig_bt[i-1] == T_LONG || sig_bt[i-1] == T_DOUBLE), "missing half");
aoqi@6880 652 continue;
aoqi@6880 653 }
aoqi@6880 654
aoqi@6880 655 // st_off points to lowest address on stack.
aoqi@6880 656 int st_off = ((total_args_passed - 1) - i) * Interpreter::stackElementSize;
aoqi@6880 657 // Say 4 args:
aoqi@6880 658 // i st_off
aoqi@6880 659 // 0 12 T_LONG
aoqi@6880 660 // 1 8 T_VOID
aoqi@6880 661 // 2 4 T_OBJECT
aoqi@6880 662 // 3 0 T_BOOL
aoqi@6880 663 VMReg r_1 = regs[i].first();
aoqi@6880 664 VMReg r_2 = regs[i].second();
aoqi@6880 665 if (!r_1->is_valid()) {
aoqi@6880 666 assert(!r_2->is_valid(), "");
aoqi@6880 667 continue;
aoqi@6880 668 }
aoqi@6880 669 if (r_1->is_stack()) {
aoqi@6880 670 // memory to memory use fpu stack top
aoqi@6880 671 int ld_off = r_1->reg2stack() * VMRegImpl::stack_slot_size + extraspace;
aoqi@6880 672 if (!r_2->is_valid()) {
aoqi@6880 673 __ ld_ptr(AT, SP, ld_off);
aoqi@6880 674 __ st_ptr(AT, SP, st_off);
aoqi@6880 675
aoqi@6880 676 } else {
aoqi@6880 677
aoqi@6880 678
aoqi@6880 679 int next_off = st_off - Interpreter::stackElementSize;
aoqi@6880 680 __ ld_ptr(AT, SP, ld_off);
aoqi@6880 681 __ st_ptr(AT, SP, st_off);
aoqi@6880 682
aoqi@6880 683 /* Ref to is_Register condition */
aoqi@6880 684 if(sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE)
aoqi@6880 685 __ st_ptr(AT,SP,st_off - 8);
aoqi@6880 686 }
aoqi@6880 687 } else if (r_1->is_Register()) {
aoqi@6880 688 Register r = r_1->as_Register();
aoqi@6880 689 if (!r_2->is_valid()) {
aoqi@6880 690 __ sd(r,SP, st_off); //aoqi_test FIXME
aoqi@6880 691 } else {
aoqi@6880 692 //FIXME, mips will not enter here
aoqi@6880 693 // long/double in gpr
aoqi@6880 694 __ sd(r,SP, st_off); //aoqi_test FIXME
aoqi@6880 695 /* Jin: In [java/util/zip/ZipFile.java]
aoqi@1 696
aoqi@1 697 private static native long open(String name, int mode, long lastModified);
aoqi@1 698 private static native int getTotal(long jzfile);
aoqi@1 699 *
aoqi@1 700 * We need to transfer T_LONG paramenters from a compiled method to a native method.
aoqi@1 701 * It's a complex process:
aoqi@1 702 *
aoqi@1 703 * Caller -> lir_static_call -> gen_resolve_stub
aoqi@1 704 -> -- resolve_static_call_C
aoqi@6880 705 `- gen_c2i_adapter() [*]
aoqi@1 706 |
aoqi@6880 707 `- AdapterHandlerLibrary::get_create_apapter_index
aoqi@1 708 -> generate_native_entry
aoqi@1 709 -> InterpreterRuntime::SignatureHandlerGenerator::pass_long [**]
aoqi@1 710
aoqi@1 711 * In [**], T_Long parameter is stored in stack as:
aoqi@1 712
aoqi@1 713 (high)
aoqi@1 714 | |
aoqi@1 715 -----------
aoqi@1 716 | 8 bytes |
aoqi@1 717 | (void) |
aoqi@1 718 -----------
aoqi@1 719 | 8 bytes |
aoqi@1 720 | (long) |
aoqi@1 721 -----------
aoqi@1 722 | |
aoqi@1 723 (low)
aoqi@1 724 *
aoqi@6880 725 * However, the sequence is reversed here:
aoqi@1 726 *
aoqi@1 727 (high)
aoqi@1 728 | |
aoqi@1 729 -----------
aoqi@1 730 | 8 bytes |
aoqi@1 731 | (long) |
aoqi@1 732 -----------
aoqi@1 733 | 8 bytes |
aoqi@1 734 | (void) |
aoqi@1 735 -----------
aoqi@1 736 | |
aoqi@1 737 (low)
aoqi@1 738 *
aoqi@1 739 * So I stored another 8 bytes in the T_VOID slot. It then can be accessed from generate_native_entry().
aoqi@1 740 */
aoqi@6880 741 if (sig_bt[i] == T_LONG)
aoqi@6880 742 __ sd(r,SP, st_off - 8);
aoqi@6880 743 }
aoqi@6880 744 } else if (r_1->is_FloatRegister()) {
aoqi@6880 745 assert(sig_bt[i] == T_FLOAT || sig_bt[i] == T_DOUBLE, "Must be a float register");
aoqi@6880 746
aoqi@6880 747 FloatRegister fr = r_1->as_FloatRegister();
aoqi@6880 748 if (sig_bt[i] == T_FLOAT)
aoqi@6880 749 __ swc1(fr,SP, st_off);
aoqi@6880 750 else {
aoqi@6880 751 __ sdc1(fr,SP, st_off);
aoqi@6880 752 __ sdc1(fr,SP, st_off - 8); /* T_DOUBLE needs two slots */
aoqi@6880 753 }
aoqi@6880 754 }
aoqi@6880 755 }
aoqi@6880 756
aoqi@6880 757 // Schedule the branch target address early.
aoqi@6880 758 __ ld_ptr(AT, Rmethod,in_bytes(Method::interpreter_entry_offset()) );
aoqi@6880 759 // And repush original return address
aoqi@6880 760 __ move(RA, V0);
aoqi@6880 761 __ jr (AT);
aoqi@6880 762 __ delayed()->nop();
aoqi@1 763 }
aoqi@1 764
aoqi@1 765 void AdapterGenerator::gen_i2c_adapter(
aoqi@6880 766 int total_args_passed,
aoqi@6880 767 // VMReg max_arg,
aoqi@6880 768 int comp_args_on_stack, // VMRegStackSlots
aoqi@6880 769 const BasicType *sig_bt,
aoqi@6880 770 const VMRegPair *regs) {
aoqi@1 771
aoqi@1 772 // Generate an I2C adapter: adjust the I-frame to make space for the C-frame
aoqi@1 773 // layout. Lesp was saved by the calling I-frame and will be restored on
aoqi@1 774 // return. Meanwhile, outgoing arg space is all owned by the callee
aoqi@1 775 // C-frame, so we can mangle it at will. After adjusting the frame size,
aoqi@1 776 // hoist register arguments and repack other args according to the compiled
aoqi@1 777 // code convention. Finally, end in a jump to the compiled code. The entry
aoqi@1 778 // point address is the start of the buffer.
aoqi@1 779
aoqi@1 780 // We will only enter here from an interpreted frame and never from after
aoqi@1 781 // passing thru a c2i. Azul allowed this but we do not. If we lose the
aoqi@1 782 // race and use a c2i we will remain interpreted for the race loser(s).
aoqi@1 783 // This removes all sorts of headaches on the mips side and also eliminates
aoqi@1 784 // the possibility of having c2i -> i2c -> c2i -> ... endless transitions.
aoqi@1 785
aoqi@1 786
aoqi@1 787 __ move(T9, SP);
aoqi@1 788
aoqi@1 789 // Cut-out for having no stack args. Since up to 2 int/oop args are passed
aoqi@1 790 // in registers, we will occasionally have no stack args.
aoqi@1 791 int comp_words_on_stack = 0;
aoqi@1 792 if (comp_args_on_stack) {
aoqi@1 793 // Sig words on the stack are greater-than VMRegImpl::stack0. Those in
aoqi@1 794 // registers are below. By subtracting stack0, we either get a negative
aoqi@1 795 // number (all values in registers) or the maximum stack slot accessed.
aoqi@1 796 // int comp_args_on_stack = VMRegImpl::reg2stack(max_arg);
aoqi@1 797 // Convert 4-byte stack slots to words.
aoqi@1 798 // did mips need round? FIXME aoqi
aoqi@1 799 comp_words_on_stack = round_to(comp_args_on_stack*4, wordSize)>>LogBytesPerWord;
aoqi@1 800 // Round up to miminum stack alignment, in wordSize
aoqi@1 801 comp_words_on_stack = round_to(comp_words_on_stack, 2);
aoqi@1 802 __ daddi(SP, SP, -comp_words_on_stack * wordSize);
aoqi@1 803 }
aoqi@1 804
aoqi@1 805 // Align the outgoing SP
aoqi@1 806 __ move(AT, -(StackAlignmentInBytes));
aoqi@6880 807 __ andr(SP, SP, AT);
aoqi@1 808 // push the return address on the stack (note that pushing, rather
aoqi@1 809 // than storing it, yields the correct frame alignment for the callee)
aoqi@1 810 // Put saved SP in another register
aoqi@1 811 const Register saved_sp = V0;
aoqi@1 812 __ move(saved_sp, T9);
aoqi@1 813
aoqi@1 814
aoqi@1 815 // Will jump to the compiled code just as if compiled code was doing it.
aoqi@1 816 // Pre-load the register-jump target early, to schedule it better.
aoqi@1 817 __ ld(T9, Rmethod, in_bytes(Method::from_compiled_offset()));
aoqi@1 818
aoqi@1 819 // Now generate the shuffle code. Pick up all register args and move the
aoqi@1 820 // rest through the floating point stack top.
aoqi@1 821 for (int i = 0; i < total_args_passed; i++) {
aoqi@1 822 if (sig_bt[i] == T_VOID) {
aoqi@1 823 // Longs and doubles are passed in native word order, but misaligned
aoqi@1 824 // in the 32-bit build.
aoqi@1 825 assert(i > 0 && (sig_bt[i-1] == T_LONG || sig_bt[i-1] == T_DOUBLE), "missing half");
aoqi@1 826 continue;
aoqi@1 827 }
aoqi@1 828
aoqi@6880 829 // Pick up 0, 1 or 2 words from SP+offset.
aoqi@6880 830
aoqi@6880 831 //FIXME. aoqi. just delete the assert
aoqi@1 832 //assert(!regs[i].second()->is_valid() || regs[i].first()->next() == regs[i].second(), "scrambled load targets?");
aoqi@1 833 // Load in argument order going down.
aoqi@1 834 int ld_off = (total_args_passed -1 - i)*Interpreter::stackElementSize;
aoqi@1 835 // Point to interpreter value (vs. tag)
aoqi@1 836 int next_off = ld_off - Interpreter::stackElementSize;
aoqi@1 837 //
aoqi@6880 838 //
aoqi@1 839 //
aoqi@1 840 VMReg r_1 = regs[i].first();
aoqi@1 841 VMReg r_2 = regs[i].second();
aoqi@1 842 if (!r_1->is_valid()) {
aoqi@1 843 assert(!r_2->is_valid(), "");
aoqi@1 844 continue;
aoqi@1 845 }
aoqi@6880 846 if (r_1->is_stack()) {
aoqi@6880 847 // Convert stack slot to an SP offset (+ wordSize to
aoqi@1 848 // account for return address )
aoqi@6880 849 //NOTICE HERE!!!! I sub a wordSize here
aoqi@6880 850 int st_off = regs[i].first()->reg2stack()*VMRegImpl::stack_slot_size;
aoqi@1 851 //+ wordSize;
aoqi@1 852
aoqi@6880 853 // We can use esi as a temp here because compiled code doesn't
aoqi@1 854 // need esi as an input
aoqi@6880 855 // and if we end up going thru a c2i because of a miss a reasonable
aoqi@6880 856 // value of esi
aoqi@6880 857 // we be generated.
aoqi@1 858 if (!r_2->is_valid()) {
aoqi@6880 859 __ ld(AT, saved_sp, ld_off);
aoqi@6880 860 __ sd(AT, SP, st_off);
aoqi@1 861 } else {
aoqi@6880 862 // Interpreter local[n] == MSW, local[n+1] == LSW however locals
aoqi@6880 863 // are accessed as negative so LSW is at LOW address
aoqi@6880 864
aoqi@6880 865 // ld_off is MSW so get LSW
aoqi@6880 866 // st_off is LSW (i.e. reg.first())
aoqi@6880 867 /*
aoqi@6880 868 __ ld(AT, saved_sp, next_off);
aoqi@6880 869 __ sd(AT, SP, st_off);
aoqi@6880 870 __ ld(AT, saved_sp, ld_off);
aoqi@6880 871 __ sd(AT, SP, st_off + wordSize);
aoqi@6880 872 */
aoqi@6880 873
aoqi@6880 874 /* 2012/4/9 Jin
aoqi@6880 875 * [./org/eclipse/swt/graphics/GC.java]
aoqi@6880 876 * void drawImageXRender(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight,
aoqi@6880 877 int destX, int destY, int destWidth, int destHeight,
aoqi@6880 878 boolean simple,
aoqi@6880 879 int imgWidth, int imgHeight,
aoqi@6880 880 long maskPixmap, <-- Pass T_LONG in stack
aoqi@6880 881 int maskType);
aoqi@6880 882 * Before this modification, Eclipse displays icons with solid black background.
aoqi@6880 883 */
aoqi@6880 884 __ ld(AT, saved_sp, ld_off);
aoqi@1 885 if (sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE)
aoqi@6880 886 __ ld(AT, saved_sp, ld_off - 8);
aoqi@6880 887 __ sd(AT, SP, st_off);
aoqi@1 888 }
aoqi@1 889 } else if (r_1->is_Register()) { // Register argument
aoqi@1 890 Register r = r_1->as_Register();
aoqi@1 891 // assert(r != eax, "must be different");
aoqi@1 892 if (r_2->is_valid()) {
aoqi@6880 893 // assert(r_2->as_Register() != eax, "need another temporary register");
aoqi@6880 894 // Remember r_1 is low address (and LSB on mips)
aoqi@6880 895 // So r_2 gets loaded from high address regardless of the platform
aoqi@6880 896 //aoqi
aoqi@6880 897 assert(r_2->as_Register() == r_1->as_Register(), "");
aoqi@6880 898 //__ ld(r_2->as_Register(), saved_sp, ld_off);
aoqi@6880 899 //__ ld(r, saved_sp, next_off);
aoqi@6880 900 __ ld(r, saved_sp, ld_off);
aoqi@6880 901
aoqi@6880 902 /* Jin:
aoqi@6880 903 *
aoqi@6880 904 * For T_LONG type, the real layout is as below:
aoqi@6880 905
aoqi@6880 906 (high)
aoqi@6880 907 | |
aoqi@6880 908 -----------
aoqi@6880 909 | 8 bytes |
aoqi@6880 910 | (void) |
aoqi@6880 911 -----------
aoqi@6880 912 | 8 bytes |
aoqi@6880 913 | (long) |
aoqi@6880 914 -----------
aoqi@6880 915 | |
aoqi@6880 916 (low)
aoqi@6880 917 *
aoqi@6880 918 * We should load the low-8 bytes.
aoqi@6880 919 */
aoqi@6880 920 if (sig_bt[i] == T_LONG)
aoqi@6880 921 __ ld(r, saved_sp, ld_off - 8);
aoqi@1 922 } else {
aoqi@6880 923 __ lw(r, saved_sp, ld_off);
aoqi@1 924 }
aoqi@1 925 } else if (r_1->is_FloatRegister()) { // Float Register
aoqi@6880 926 assert(sig_bt[i] == T_FLOAT || sig_bt[i] == T_DOUBLE, "Must be a float register");
aoqi@6880 927
aoqi@6880 928 FloatRegister fr = r_1->as_FloatRegister();
aoqi@6880 929 if (sig_bt[i] == T_FLOAT)
aoqi@6880 930 __ lwc1(fr, saved_sp, ld_off);
aoqi@6880 931 else {
aoqi@6880 932 __ ldc1(fr, saved_sp, ld_off);
aoqi@6880 933 __ ldc1(fr, saved_sp, ld_off - 8);
aoqi@6880 934 }
aoqi@6880 935 }
aoqi@1 936 }
aoqi@1 937
aoqi@1 938 // 6243940 We might end up in handle_wrong_method if
aoqi@1 939 // the callee is deoptimized as we race thru here. If that
aoqi@1 940 // happens we don't want to take a safepoint because the
aoqi@1 941 // caller frame will look interpreted and arguments are now
aoqi@1 942 // "compiled" so it is much better to make this transition
aoqi@1 943 // invisible to the stack walking code. Unfortunately if
aoqi@1 944 // we try and find the callee by normal means a safepoint
aoqi@1 945 // is possible. So we stash the desired callee in the thread
aoqi@1 946 // and the vm will find there should this case occur.
aoqi@1 947 __ get_thread(T8);
aoqi@1 948 __ sd(Rmethod, T8, in_bytes(JavaThread::callee_target_offset()));
aoqi@1 949
aoqi@1 950 // move methodOop to eax in case we end up in an c2i adapter.
aoqi@1 951 // the c2i adapters expect methodOop in eax (c2) because c2's
aoqi@1 952 // resolve stubs return the result (the method) in eax.
aoqi@6880 953 // I'd love to fix this.
aoqi@6880 954 __ move(V0, Rmethod);
aoqi@1 955 __ jr(T9);
aoqi@1 956 __ delayed()->nop();
aoqi@1 957 }
aoqi@1 958
aoqi@1 959 // ---------------------------------------------------------------
aoqi@1 960 AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm,
aoqi@1 961 int total_args_passed,
aoqi@1 962 // VMReg max_arg,
aoqi@1 963 int comp_args_on_stack, // VMRegStackSlots
aoqi@1 964 const BasicType *sig_bt,
aoqi@1 965 const VMRegPair *regs,
aoqi@1 966 AdapterFingerPrint* fingerprint) {
aoqi@1 967 address i2c_entry = __ pc();
aoqi@1 968
aoqi@1 969 AdapterGenerator agen(masm);
aoqi@1 970
aoqi@1 971 agen.gen_i2c_adapter(total_args_passed, comp_args_on_stack, sig_bt, regs);
aoqi@1 972
aoqi@1 973
aoqi@1 974 // -------------------------------------------------------------------------
aoqi@1 975 // Generate a C2I adapter. On entry we know G5 holds the methodOop. The
aoqi@1 976 // args start out packed in the compiled layout. They need to be unpacked
aoqi@1 977 // into the interpreter layout. This will almost always require some stack
aoqi@1 978 // space. We grow the current (compiled) stack, then repack the args. We
aoqi@1 979 // finally end in a jump to the generic interpreter entry point. On exit
aoqi@1 980 // from the interpreter, the interpreter will restore our SP (lest the
aoqi@1 981 // compiled code, which relys solely on SP and not FP, get sick).
aoqi@1 982
aoqi@1 983 address c2i_unverified_entry = __ pc();
aoqi@1 984 Label skip_fixup;
aoqi@1 985 {
aoqi@1 986 Register holder = T1;
aoqi@1 987 Register receiver = T0;
aoqi@1 988 Register temp = T8;
aoqi@1 989 address ic_miss = SharedRuntime::get_ic_miss_stub();
aoqi@1 990
aoqi@1 991 Label missed;
aoqi@1 992
aoqi@1 993 __ verify_oop(holder);
aoqi@1 994 //add for compressedoops
aoqi@1 995 __ load_klass(temp, receiver);
aoqi@1 996 __ verify_oop(temp);
aoqi@1 997
aoqi@6880 998 __ ld_ptr(AT, holder, CompiledICHolder::holder_klass_offset());
aoqi@1 999 __ ld_ptr(Rmethod, holder, CompiledICHolder::holder_method_offset());
aoqi@6880 1000 __ bne(AT, temp, missed);
aoqi@6880 1001 __ delayed()->nop();
aoqi@1 1002 // Method might have been compiled since the call site was patched to
aoqi@1 1003 // interpreted if that is the case treat it as a miss so we can get
aoqi@1 1004 // the call site corrected.
aoqi@1 1005 __ ld_ptr(AT, Rmethod, in_bytes(Method::code_offset()));
aoqi@6880 1006 __ beq(AT, R0, skip_fixup);
aoqi@6880 1007 __ delayed()->nop();
aoqi@1 1008 __ bind(missed);
aoqi@1 1009
aoqi@1 1010 __ jmp(ic_miss, relocInfo::runtime_call_type);
aoqi@6880 1011 __ delayed()->nop();
aoqi@1 1012 }
aoqi@1 1013
aoqi@1 1014 address c2i_entry = __ pc();
aoqi@1 1015
aoqi@1 1016 agen.gen_c2i_adapter(total_args_passed, comp_args_on_stack, sig_bt, regs, skip_fixup);
aoqi@1 1017
aoqi@1 1018 __ flush();
aoqi@1 1019 return AdapterHandlerLibrary::new_entry(fingerprint,i2c_entry, c2i_entry, c2i_unverified_entry);
aoqi@1 1020 }
aoqi@1 1021
aoqi@1 1022 int SharedRuntime::c_calling_convention(const BasicType *sig_bt,
aoqi@1 1023 VMRegPair *regs,
aoqi@1 1024 VMRegPair *regs2,
aoqi@1 1025 int total_args_passed) {
aoqi@6880 1026 assert(regs2 == NULL, "not needed on MIPS");
aoqi@6880 1027 // Return the number of VMReg stack_slots needed for the args.
aoqi@6880 1028 // This value does not include an abi space (like register window
aoqi@6880 1029 // save area).
aoqi@6880 1030
aoqi@6880 1031 // The native convention is V8 if !LP64
aoqi@6880 1032 // The LP64 convention is the V9 convention which is slightly more sane.
aoqi@6880 1033
aoqi@6880 1034 // We return the amount of VMReg stack slots we need to reserve for all
aoqi@6880 1035 // the arguments NOT counting out_preserve_stack_slots. Since we always
aoqi@6880 1036 // have space for storing at least 6 registers to memory we start with that.
aoqi@6880 1037 // See int_stk_helper for a further discussion.
aoqi@6880 1038 // We return the amount of VMRegImpl stack slots we need to reserve for all
aoqi@6880 1039 // the arguments NOT counting out_preserve_stack_slots.
aoqi@1 1040 static const Register INT_ArgReg[Argument::n_register_parameters] = {
aoqi@1 1041 A0, A1, A2, A3, A4, A5, A6, A7
aoqi@1 1042 };
aoqi@1 1043 static const FloatRegister FP_ArgReg[Argument::n_float_register_parameters] = {
aoqi@1 1044 F12, F13, F14, F15, F16, F17, F18, F19
aoqi@1 1045 };
aoqi@6880 1046 uint args = 0;
aoqi@6880 1047 uint stk_args = 0; // inc by 2 each time
aoqi@1 1048
aoqi@1 1049 /* Example:
aoqi@1 1050 --- n java.lang.UNIXProcess::forkAndExec
aoqi@1 1051 private native int forkAndExec(byte[] prog,
aoqi@1 1052 byte[] argBlock, int argc,
aoqi@1 1053 byte[] envBlock, int envc,
aoqi@1 1054 byte[] dir,
aoqi@1 1055 boolean redirectErrorStream,
aoqi@1 1056 FileDescriptor stdin_fd,
aoqi@1 1057 FileDescriptor stdout_fd,
aoqi@1 1058 FileDescriptor stderr_fd)
aoqi@1 1059 JNIEXPORT jint JNICALL
aoqi@1 1060 Java_java_lang_UNIXProcess_forkAndExec(JNIEnv *env,
aoqi@1 1061 jobject process,
aoqi@1 1062 jbyteArray prog,
aoqi@1 1063 jbyteArray argBlock, jint argc,
aoqi@1 1064 jbyteArray envBlock, jint envc,
aoqi@1 1065 jbyteArray dir,
aoqi@1 1066 jboolean redirectErrorStream,
aoqi@1 1067 jobject stdin_fd,
aoqi@1 1068 jobject stdout_fd,
aoqi@1 1069 jobject stderr_fd)
aoqi@1 1070
aoqi@1 1071 ::c_calling_convention
aoqi@6880 1072 0: // env <-- a0
aoqi@6880 1073 1: L // klass/obj <-- t0 => a1
aoqi@6880 1074 2: [ // prog[] <-- a0 => a2
aoqi@6880 1075 3: [ // argBlock[] <-- a1 => a3
aoqi@6880 1076 4: I // argc
aoqi@6880 1077 5: [ // envBlock[] <-- a3 => a5
aoqi@6880 1078 6: I // envc
aoqi@6880 1079 7: [ // dir[] <-- a5 => a7
aoqi@6880 1080 8: Z // redirectErrorStream a6 => sp[0]
aoqi@6880 1081 9: L // stdin a7 => sp[8]
aoqi@6880 1082 10: L // stdout fp[16] => sp[16]
aoqi@6880 1083 11: L // stderr fp[24] => sp[24]
aoqi@1 1084 */
aoqi@6880 1085 for (int i = 0; i < total_args_passed; i++) {
aoqi@6880 1086 switch (sig_bt[i]) {
aoqi@6880 1087 case T_VOID: // Halves of longs and doubles
aoqi@6880 1088 assert(i != 0 && (sig_bt[i - 1] == T_LONG || sig_bt[i - 1] == T_DOUBLE), "expecting half");
aoqi@6880 1089 regs[i].set_bad();
aoqi@6880 1090 break;
aoqi@1 1091 case T_BOOLEAN:
aoqi@1 1092 case T_CHAR:
aoqi@1 1093 case T_BYTE:
aoqi@1 1094 case T_SHORT:
aoqi@1 1095 case T_INT:
aoqi@6880 1096 if (args < Argument::n_register_parameters) {
aoqi@6880 1097 regs[i].set1(INT_ArgReg[args++]->as_VMReg());
aoqi@6880 1098 } else {
aoqi@6880 1099 regs[i].set1(VMRegImpl::stack2reg(stk_args));
aoqi@6880 1100 stk_args += 2;
aoqi@6880 1101 }
aoqi@6880 1102 break;
aoqi@6880 1103 case T_LONG:
aoqi@6880 1104 assert(sig_bt[i + 1] == T_VOID, "expecting half");
aoqi@6880 1105 // fall through
aoqi@1 1106 case T_OBJECT:
aoqi@1 1107 case T_ARRAY:
aoqi@1 1108 case T_ADDRESS:
aoqi@6880 1109 case T_METADATA:
aoqi@6880 1110 if (args < Argument::n_register_parameters) {
aoqi@6880 1111 regs[i].set2(INT_ArgReg[args++]->as_VMReg());
aoqi@6880 1112 } else {
aoqi@6880 1113 regs[i].set2(VMRegImpl::stack2reg(stk_args));
aoqi@6880 1114 stk_args += 2;
aoqi@6880 1115 }
aoqi@1 1116 break;
aoqi@6880 1117 case T_FLOAT:
aoqi@6880 1118 if (args < Argument::n_float_register_parameters) {
aoqi@6880 1119 regs[i].set1(FP_ArgReg[args++]->as_VMReg());
aoqi@6880 1120 } else {
aoqi@6880 1121 regs[i].set1(VMRegImpl::stack2reg(stk_args));
aoqi@6880 1122 stk_args += 2;
aoqi@6880 1123 }
aoqi@1 1124 break;
aoqi@6880 1125 case T_DOUBLE:
aoqi@6880 1126 assert(sig_bt[i + 1] == T_VOID, "expecting half");
aoqi@6880 1127 if (args < Argument::n_float_register_parameters) {
aoqi@6880 1128 regs[i].set2(FP_ArgReg[args++]->as_VMReg());
aoqi@6880 1129 } else {
aoqi@6880 1130 regs[i].set2(VMRegImpl::stack2reg(stk_args));
aoqi@6880 1131 stk_args += 2;
aoqi@6880 1132 }
aoqi@6880 1133 break;
aoqi@1 1134 default:
aoqi@1 1135 ShouldNotReachHere();
aoqi@1 1136 break;
aoqi@1 1137 }
aoqi@1 1138 }
aoqi@6880 1139
aoqi@6880 1140 return round_to(stk_args, 2);
aoqi@1 1141 }
aoqi@1 1142
aoqi@1 1143 // ---------------------------------------------------------------------------
aoqi@1 1144 void SharedRuntime::save_native_result(MacroAssembler *masm, BasicType ret_type, int frame_slots) {
aoqi@6880 1145 // We always ignore the frame_slots arg and just use the space just below frame pointer
aoqi@6880 1146 // which by this time is free to use
aoqi@6880 1147 switch (ret_type) {
aoqi@6880 1148 case T_FLOAT:
aoqi@6880 1149 __ swc1(FSF, FP, -wordSize);
aoqi@6880 1150 break;
aoqi@6880 1151 case T_DOUBLE:
aoqi@6880 1152 __ sdc1(FSF, FP, -wordSize );
aoqi@6880 1153 break;
aoqi@6880 1154 case T_VOID: break;
aoqi@6880 1155 case T_LONG:
aoqi@8009 1156 __ sd(V0, FP, -wordSize);
aoqi@8009 1157 break;
aoqi@6880 1158 case T_OBJECT:
aoqi@6880 1159 case T_ARRAY:
aoqi@6880 1160 __ sd(V0, FP, -wordSize);
aoqi@6880 1161 break;
aoqi@6880 1162 default: {
aoqi@8009 1163 __ sw(V0, FP, -wordSize);
aoqi@8009 1164 }
aoqi@6880 1165 }
aoqi@1 1166 }
aoqi@1 1167
aoqi@1 1168 void SharedRuntime::restore_native_result(MacroAssembler *masm, BasicType ret_type, int frame_slots) {
aoqi@6880 1169 // We always ignore the frame_slots arg and just use the space just below frame pointer
aoqi@6880 1170 // which by this time is free to use
aoqi@6880 1171 switch (ret_type) {
aoqi@6880 1172 case T_FLOAT:
aoqi@6880 1173 __ lwc1(FSF, FP, -wordSize);
aoqi@6880 1174 break;
aoqi@6880 1175 case T_DOUBLE:
aoqi@6880 1176 __ ldc1(FSF, FP, -wordSize );
aoqi@6880 1177 break;
aoqi@6880 1178 case T_LONG:
aoqi@6880 1179 __ ld(V0, FP, -wordSize);
aoqi@6880 1180 break;
aoqi@6880 1181 case T_VOID: break;
aoqi@6880 1182 case T_OBJECT:
aoqi@6880 1183 case T_ARRAY:
aoqi@6880 1184 __ ld(V0, FP, -wordSize);
aoqi@6880 1185 break;
aoqi@6880 1186 default: {
aoqi@8009 1187 __ lw(V0, FP, -wordSize);
aoqi@8009 1188 }
aoqi@6880 1189 }
aoqi@1 1190 }
aoqi@1 1191
aoqi@1 1192 static void save_args(MacroAssembler *masm, int arg_count, int first_arg, VMRegPair *args) {
aoqi@6880 1193 for ( int i = first_arg ; i < arg_count ; i++ ) {
aoqi@6880 1194 if (args[i].first()->is_Register()) {
aoqi@6880 1195 __ push(args[i].first()->as_Register());
aoqi@6880 1196 } else if (args[i].first()->is_FloatRegister()) {
aoqi@6880 1197 __ push(args[i].first()->as_FloatRegister());
aoqi@1 1198 }
aoqi@6880 1199 }
aoqi@1 1200 }
aoqi@1 1201
aoqi@1 1202 static void restore_args(MacroAssembler *masm, int arg_count, int first_arg, VMRegPair *args) {
aoqi@6880 1203 for ( int i = arg_count - 1 ; i >= first_arg ; i-- ) {
aoqi@6880 1204 if (args[i].first()->is_Register()) {
aoqi@6880 1205 __ pop(args[i].first()->as_Register());
aoqi@6880 1206 } else if (args[i].first()->is_FloatRegister()) {
aoqi@6880 1207 __ pop(args[i].first()->as_FloatRegister());
aoqi@1 1208 }
aoqi@6880 1209 }
aoqi@1 1210 }
aoqi@1 1211
aoqi@1 1212 // A simple move of integer like type
aoqi@1 1213 static void simple_move32(MacroAssembler* masm, VMRegPair src, VMRegPair dst) {
aoqi@1 1214 if (src.first()->is_stack()) {
aoqi@1 1215 if (dst.first()->is_stack()) {
aoqi@1 1216 // stack to stack
aoqi@6880 1217 __ lw(AT, FP, reg2offset_in(src.first()));
aoqi@6880 1218 __ sd(AT,SP, reg2offset_out(dst.first()));
aoqi@1 1219 } else {
aoqi@1 1220 // stack to reg
aoqi@6880 1221 __ lw(dst.first()->as_Register(), FP, reg2offset_in(src.first()));
aoqi@1 1222 }
aoqi@1 1223 } else if (dst.first()->is_stack()) {
aoqi@1 1224 // reg to stack
aoqi@6880 1225 __ sd(src.first()->as_Register(), SP, reg2offset_out(dst.first()));
aoqi@1 1226 } else {
aoqi@6880 1227 if (dst.first() != src.first()){
aoqi@6880 1228 __ move(dst.first()->as_Register(), src.first()->as_Register()); // fujie error:dst.first()
aoqi@6880 1229 }
aoqi@1 1230 }
aoqi@1 1231 }
aoqi@1 1232
aoqi@1 1233 // An oop arg. Must pass a handle not the oop itself
aoqi@1 1234 static void object_move(MacroAssembler* masm,
aoqi@1 1235 OopMap* map,
aoqi@1 1236 int oop_handle_offset,
aoqi@1 1237 int framesize_in_slots,
aoqi@1 1238 VMRegPair src,
aoqi@1 1239 VMRegPair dst,
aoqi@1 1240 bool is_receiver,
aoqi@1 1241 int* receiver_offset) {
aoqi@1 1242
aoqi@1 1243 // must pass a handle. First figure out the location we use as a handle
aoqi@1 1244
aoqi@6880 1245 //FIXME, for mips, dst can be register
aoqi@6880 1246 if (src.first()->is_stack()) {
aoqi@6880 1247 // Oop is already on the stack as an argument
aoqi@6880 1248 Register rHandle = V0;
aoqi@6880 1249 Label nil;
aoqi@6880 1250 __ xorr(rHandle, rHandle, rHandle);
aoqi@6880 1251 __ ld(AT, FP, reg2offset_in(src.first()));
aoqi@6880 1252 __ beq(AT,R0, nil);
aoqi@6880 1253 __ delayed()->nop();
aoqi@6880 1254 __ lea(rHandle, Address(FP, reg2offset_in(src.first())));
aoqi@6880 1255 __ bind(nil);
aoqi@6880 1256 if(dst.first()->is_stack())__ sd( rHandle, SP, reg2offset_out(dst.first()));
aoqi@6880 1257 else __ move( (dst.first())->as_Register(),rHandle);
aoqi@6880 1258 //if dst is register
aoqi@6880 1259 //FIXME, do mips need out preserve stack slots?
aoqi@6880 1260 int offset_in_older_frame = src.first()->reg2stack()
aoqi@6880 1261 + SharedRuntime::out_preserve_stack_slots();
aoqi@6880 1262 map->set_oop(VMRegImpl::stack2reg(offset_in_older_frame + framesize_in_slots));
aoqi@6880 1263 if (is_receiver) {
aoqi@6880 1264 *receiver_offset = (offset_in_older_frame
aoqi@6880 1265 + framesize_in_slots) * VMRegImpl::stack_slot_size;
aoqi@6880 1266 }
aoqi@6880 1267 } else {
aoqi@6880 1268 // Oop is in an a register we must store it to the space we reserve
aoqi@6880 1269 // on the stack for oop_handles
aoqi@6880 1270 const Register rOop = src.first()->as_Register();
aoqi@6880 1271 assert( (rOop->encoding() >= A0->encoding()) && (rOop->encoding() <= T0->encoding()),"wrong register");
aoqi@6880 1272 const Register rHandle = V0;
aoqi@6880 1273 //Important: refer to java_calling_convertion
aoqi@6880 1274 int oop_slot = (rOop->encoding() - A0->encoding()) * VMRegImpl::slots_per_word + oop_handle_offset;
aoqi@6880 1275 int offset = oop_slot*VMRegImpl::stack_slot_size;
aoqi@6880 1276 Label skip;
aoqi@6880 1277 __ sd( rOop , SP, offset );
aoqi@6880 1278 map->set_oop(VMRegImpl::stack2reg(oop_slot));
aoqi@6880 1279 __ xorr( rHandle, rHandle, rHandle);
aoqi@6880 1280 __ beq(rOop, R0, skip);
aoqi@6880 1281 __ delayed()->nop();
aoqi@6880 1282 __ lea(rHandle, Address(SP, offset));
aoqi@6880 1283 __ bind(skip);
aoqi@6880 1284 // Store the handle parameter
aoqi@6880 1285 if(dst.first()->is_stack())__ sd( rHandle, SP, reg2offset_out(dst.first()));
aoqi@6880 1286 else __ move((dst.first())->as_Register(), rHandle);
aoqi@6880 1287 //if dst is register
aoqi@6880 1288
aoqi@6880 1289 if (is_receiver) {
aoqi@6880 1290 *receiver_offset = offset;
aoqi@6880 1291 }
aoqi@6880 1292 }
aoqi@1 1293 }
aoqi@1 1294
aoqi@1 1295 // A float arg may have to do float reg int reg conversion
aoqi@1 1296 static void float_move(MacroAssembler* masm, VMRegPair src, VMRegPair dst) {
aoqi@1 1297 assert(!src.second()->is_valid() && !dst.second()->is_valid(), "bad float_move");
aoqi@1 1298
aoqi@6880 1299 if (src.first()->is_stack()) {
aoqi@6880 1300 if (dst.first()->is_stack()) {
aoqi@6880 1301 __ lwc1(F12 , FP, reg2offset_in(src.first()));
aoqi@6880 1302 __ swc1(F12 ,SP, reg2offset_out(dst.first()));
aoqi@6880 1303 }
aoqi@6880 1304 else
aoqi@6880 1305 __ lwc1( dst.first()->as_FloatRegister(), FP, reg2offset_in(src.first()));
aoqi@6880 1306 } else {
aoqi@6880 1307 // reg to stack
aoqi@6880 1308 if(dst.first()->is_stack())
aoqi@6880 1309 __ swc1( src.first()->as_FloatRegister(),SP, reg2offset_out(dst.first()));
aoqi@6880 1310 else
aoqi@6880 1311 __ mov_s( dst.first()->as_FloatRegister(), src.first()->as_FloatRegister());
aoqi@6880 1312 }
aoqi@1 1313 }
aoqi@6880 1314
aoqi@1 1315 // A long move
aoqi@1 1316 static void long_move(MacroAssembler* masm, VMRegPair src, VMRegPair dst) {
aoqi@1 1317
aoqi@6880 1318 // The only legal possibility for a long_move VMRegPair is:
aoqi@6880 1319 // 1: two stack slots (possibly unaligned)
aoqi@6880 1320 // as neither the java or C calling convention will use registers
aoqi@6880 1321 // for longs.
aoqi@6880 1322
aoqi@6880 1323 if (src.first()->is_stack()) {
aoqi@6880 1324 assert(src.second()->is_stack() && dst.second()->is_stack(), "must be all stack");
aoqi@6880 1325 if( dst.first()->is_stack()){
aoqi@6880 1326 __ ld(AT, FP, reg2offset_in(src.first()));
aoqi@6880 1327 __ sd(AT, SP, reg2offset_out(dst.first()));
aoqi@6880 1328 } else {
aoqi@6880 1329 __ ld( (dst.first())->as_Register() , FP, reg2offset_in(src.first()));
aoqi@6880 1330 }
aoqi@6880 1331 } else {
aoqi@6880 1332 if( dst.first()->is_stack()){
aoqi@6880 1333 __ sd( (src.first())->as_Register(), SP, reg2offset_out(dst.first()));
aoqi@6880 1334 } else{
aoqi@6880 1335 __ move( (dst.first())->as_Register() , (src.first())->as_Register());
aoqi@6880 1336 }
aoqi@6880 1337 }
aoqi@1 1338 }
aoqi@1 1339
aoqi@1 1340 // A double move
aoqi@1 1341 static void double_move(MacroAssembler* masm, VMRegPair src, VMRegPair dst) {
aoqi@1 1342
aoqi@6880 1343 // The only legal possibilities for a double_move VMRegPair are:
aoqi@6880 1344 // The painful thing here is that like long_move a VMRegPair might be
aoqi@6880 1345
aoqi@6880 1346 // Because of the calling convention we know that src is either
aoqi@6880 1347 // 1: a single physical register (xmm registers only)
aoqi@6880 1348 // 2: two stack slots (possibly unaligned)
aoqi@6880 1349 // dst can only be a pair of stack slots.
aoqi@6880 1350
aoqi@6880 1351
aoqi@6880 1352 if (src.first()->is_stack()) {
aoqi@6880 1353 // source is all stack
aoqi@6880 1354 if( dst.first()->is_stack()){
aoqi@6880 1355 __ ldc1(F12, FP, reg2offset_in(src.first()));
aoqi@6880 1356
aoqi@6880 1357 __ sdc1(F12, SP, reg2offset_out(dst.first()));
aoqi@6880 1358 } else{
aoqi@6880 1359 __ ldc1( (dst.first())->as_FloatRegister(), FP, reg2offset_in(src.first()));
aoqi@6880 1360 }
aoqi@6880 1361
aoqi@6880 1362 } else {
aoqi@6880 1363 // reg to stack
aoqi@6880 1364 // No worries about stack alignment
aoqi@6880 1365 if( dst.first()->is_stack()){
aoqi@6880 1366 __ sdc1( src.first()->as_FloatRegister(),SP, reg2offset_out(dst.first()));
aoqi@6880 1367 }
aoqi@6880 1368 else
aoqi@6880 1369 __ mov_d( dst.first()->as_FloatRegister(), src.first()->as_FloatRegister());
aoqi@6880 1370
aoqi@6880 1371 }
aoqi@1 1372 }
aoqi@1 1373
aoqi@1 1374 static void verify_oop_args(MacroAssembler* masm,
aoqi@1 1375 methodHandle method,
aoqi@1 1376 const BasicType* sig_bt,
aoqi@1 1377 const VMRegPair* regs) {
aoqi@1 1378 Register temp_reg = T9; // not part of any compiled calling seq
aoqi@1 1379 if (VerifyOops) {
aoqi@1 1380 for (int i = 0; i < method->size_of_parameters(); i++) {
aoqi@1 1381 if (sig_bt[i] == T_OBJECT ||
aoqi@1 1382 sig_bt[i] == T_ARRAY) {
aoqi@1 1383 VMReg r = regs[i].first();
aoqi@1 1384 assert(r->is_valid(), "bad oop arg");
aoqi@1 1385 if (r->is_stack()) {
aoqi@1 1386 __ ld(temp_reg, Address(SP, r->reg2stack() * VMRegImpl::stack_slot_size + wordSize));
aoqi@1 1387 __ verify_oop(temp_reg);
aoqi@1 1388 } else {
aoqi@1 1389 __ verify_oop(r->as_Register());
aoqi@1 1390 }
aoqi@1 1391 }
aoqi@1 1392 }
aoqi@1 1393 }
aoqi@1 1394 }
aoqi@1 1395
aoqi@1 1396 static void gen_special_dispatch(MacroAssembler* masm,
aoqi@1 1397 methodHandle method,
aoqi@1 1398 const BasicType* sig_bt,
aoqi@1 1399 const VMRegPair* regs) {
aoqi@1 1400 verify_oop_args(masm, method, sig_bt, regs);
aoqi@1 1401 vmIntrinsics::ID iid = method->intrinsic_id();
aoqi@1 1402
aoqi@1 1403 // Now write the args into the outgoing interpreter space
aoqi@1 1404 bool has_receiver = false;
aoqi@1 1405 Register receiver_reg = noreg;
aoqi@1 1406 int member_arg_pos = -1;
aoqi@1 1407 Register member_reg = noreg;
aoqi@1 1408 int ref_kind = MethodHandles::signature_polymorphic_intrinsic_ref_kind(iid);
aoqi@1 1409 if (ref_kind != 0) {
aoqi@1 1410 member_arg_pos = method->size_of_parameters() - 1; // trailing MemberName argument
aoqi@1 1411 member_reg = S3; // known to be free at this point
aoqi@1 1412 has_receiver = MethodHandles::ref_kind_has_receiver(ref_kind);
aoqi@1 1413 } else if (iid == vmIntrinsics::_invokeBasic) {
aoqi@1 1414 has_receiver = true;
aoqi@1 1415 } else {
aoqi@1 1416 fatal(err_msg_res("unexpected intrinsic id %d", iid));
aoqi@1 1417 }
aoqi@1 1418
aoqi@1 1419 if (member_reg != noreg) {
aoqi@1 1420 // Load the member_arg into register, if necessary.
aoqi@1 1421 SharedRuntime::check_member_name_argument_is_last_argument(method, sig_bt, regs);
aoqi@1 1422 VMReg r = regs[member_arg_pos].first();
aoqi@1 1423 if (r->is_stack()) {
fujie@410 1424 __ ld(member_reg, Address(SP, r->reg2stack() * VMRegImpl::stack_slot_size));
aoqi@1 1425 } else {
aoqi@1 1426 // no data motion is needed
aoqi@1 1427 member_reg = r->as_Register();
aoqi@1 1428 }
aoqi@1 1429 }
aoqi@1 1430
aoqi@1 1431 if (has_receiver) {
aoqi@1 1432 // Make sure the receiver is loaded into a register.
aoqi@1 1433 assert(method->size_of_parameters() > 0, "oob");
aoqi@1 1434 assert(sig_bt[0] == T_OBJECT, "receiver argument must be an object");
aoqi@1 1435 VMReg r = regs[0].first();
aoqi@1 1436 assert(r->is_valid(), "bad receiver arg");
aoqi@1 1437 if (r->is_stack()) {
aoqi@1 1438 // Porting note: This assumes that compiled calling conventions always
aoqi@1 1439 // pass the receiver oop in a register. If this is not true on some
aoqi@1 1440 // platform, pick a temp and load the receiver from stack.
aoqi@1 1441 fatal("receiver always in a register");
aoqi@1 1442 receiver_reg = SSR; // known to be free at this point
fujie@410 1443 __ ld(receiver_reg, Address(SP, r->reg2stack() * VMRegImpl::stack_slot_size));
aoqi@1 1444 } else {
aoqi@1 1445 // no data motion is needed
aoqi@1 1446 receiver_reg = r->as_Register();
aoqi@1 1447 }
aoqi@1 1448 }
aoqi@1 1449
aoqi@1 1450 // Figure out which address we are really jumping to:
aoqi@1 1451 MethodHandles::generate_method_handle_dispatch(masm, iid,
aoqi@1 1452 receiver_reg, member_reg, /*for_compiler_entry:*/ true);
aoqi@1 1453 }
aoqi@1 1454
aoqi@1 1455 // ---------------------------------------------------------------------------
aoqi@1 1456 // Generate a native wrapper for a given method. The method takes arguments
aoqi@1 1457 // in the Java compiled code convention, marshals them to the native
aoqi@1 1458 // convention (handlizes oops, etc), transitions to native, makes the call,
aoqi@1 1459 // returns to java state (possibly blocking), unhandlizes any result and
aoqi@1 1460 // returns.
aoqi@1 1461 nmethod *SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
aoqi@1 1462 methodHandle method,
aoqi@1 1463 int compile_id,
aoqi@6880 1464 BasicType* in_sig_bt,
aoqi@6880 1465 VMRegPair* in_regs,
aoqi@1 1466 BasicType ret_type) {
aoqi@1 1467 if (method->is_method_handle_intrinsic()) {
aoqi@1 1468 vmIntrinsics::ID iid = method->intrinsic_id();
aoqi@1 1469 intptr_t start = (intptr_t)__ pc();
aoqi@1 1470 int vep_offset = ((intptr_t)__ pc()) - start;
aoqi@1 1471 gen_special_dispatch(masm,
aoqi@1 1472 method,
aoqi@1 1473 in_sig_bt,
aoqi@1 1474 in_regs);
aoqi@1 1475 int frame_complete = ((intptr_t)__ pc()) - start; // not complete, period
aoqi@1 1476 __ flush();
aoqi@1 1477 int stack_slots = SharedRuntime::out_preserve_stack_slots(); // no out slots at all, actually
aoqi@1 1478 return nmethod::new_native_nmethod(method,
aoqi@1 1479 compile_id,
aoqi@1 1480 masm->code(),
aoqi@1 1481 vep_offset,
aoqi@1 1482 frame_complete,
aoqi@1 1483 stack_slots / VMRegImpl::slots_per_word,
aoqi@1 1484 in_ByteSize(-1),
aoqi@1 1485 in_ByteSize(-1),
aoqi@1 1486 (OopMapSet*)NULL);
aoqi@1 1487 }
aoqi@1 1488 bool is_critical_native = true;
aoqi@1 1489 address native_func = method->critical_native_function();
aoqi@1 1490 if (native_func == NULL) {
aoqi@1 1491 native_func = method->native_function();
aoqi@1 1492 is_critical_native = false;
aoqi@1 1493 }
aoqi@1 1494 assert(native_func != NULL, "must have function");
aoqi@1 1495
aoqi@1 1496 // Native nmethod wrappers never take possesion of the oop arguments.
aoqi@1 1497 // So the caller will gc the arguments. The only thing we need an
aoqi@1 1498 // oopMap for is if the call is static
aoqi@1 1499 //
aoqi@1 1500 // An OopMap for lock (and class if static), and one for the VM call itself
aoqi@1 1501 OopMapSet *oop_maps = new OopMapSet();
aoqi@1 1502
aoqi@6880 1503 // We have received a description of where all the java arg are located
aoqi@6880 1504 // on entry to the wrapper. We need to convert these args to where
aoqi@6880 1505 // the jni function will expect them. To figure out where they go
aoqi@6880 1506 // we convert the java signature to a C signature by inserting
aoqi@6880 1507 // the hidden arguments as arg[0] and possibly arg[1] (static method)
aoqi@1 1508
aoqi@1 1509 const int total_in_args = method->size_of_parameters();
aoqi@1 1510 int total_c_args = total_in_args;
aoqi@1 1511 if (!is_critical_native) {
aoqi@1 1512 total_c_args += 1;
aoqi@1 1513 if (method->is_static()) {
aoqi@1 1514 total_c_args++;
aoqi@1 1515 }
aoqi@1 1516 } else {
aoqi@1 1517 for (int i = 0; i < total_in_args; i++) {
aoqi@1 1518 if (in_sig_bt[i] == T_ARRAY) {
aoqi@1 1519 total_c_args++;
aoqi@1 1520 }
aoqi@1 1521 }
aoqi@1 1522 }
aoqi@1 1523
aoqi@6880 1524 BasicType* out_sig_bt = NEW_RESOURCE_ARRAY(BasicType, total_c_args);
aoqi@6880 1525 VMRegPair* out_regs = NEW_RESOURCE_ARRAY(VMRegPair, total_c_args);
aoqi@1 1526 BasicType* in_elem_bt = NULL;
aoqi@1 1527
aoqi@1 1528 int argc = 0;
aoqi@1 1529 if (!is_critical_native) {
aoqi@1 1530 out_sig_bt[argc++] = T_ADDRESS;
aoqi@1 1531 if (method->is_static()) {
aoqi@1 1532 out_sig_bt[argc++] = T_OBJECT;
aoqi@1 1533 }
aoqi@1 1534
aoqi@1 1535 for (int i = 0; i < total_in_args ; i++ ) {
aoqi@1 1536 out_sig_bt[argc++] = in_sig_bt[i];
aoqi@1 1537 }
aoqi@1 1538 } else {
aoqi@1 1539 Thread* THREAD = Thread::current();
aoqi@1 1540 in_elem_bt = NEW_RESOURCE_ARRAY(BasicType, total_in_args);
aoqi@1 1541 SignatureStream ss(method->signature());
aoqi@1 1542 for (int i = 0; i < total_in_args ; i++ ) {
aoqi@1 1543 if (in_sig_bt[i] == T_ARRAY) {
aoqi@1 1544 // Arrays are passed as int, elem* pair
aoqi@1 1545 out_sig_bt[argc++] = T_INT;
aoqi@1 1546 out_sig_bt[argc++] = T_ADDRESS;
aoqi@1 1547 Symbol* atype = ss.as_symbol(CHECK_NULL);
aoqi@1 1548 const char* at = atype->as_C_string();
aoqi@1 1549 if (strlen(at) == 2) {
aoqi@1 1550 assert(at[0] == '[', "must be");
aoqi@1 1551 switch (at[1]) {
aoqi@1 1552 case 'B': in_elem_bt[i] = T_BYTE; break;
aoqi@1 1553 case 'C': in_elem_bt[i] = T_CHAR; break;
aoqi@1 1554 case 'D': in_elem_bt[i] = T_DOUBLE; break;
aoqi@1 1555 case 'F': in_elem_bt[i] = T_FLOAT; break;
aoqi@1 1556 case 'I': in_elem_bt[i] = T_INT; break;
aoqi@1 1557 case 'J': in_elem_bt[i] = T_LONG; break;
aoqi@1 1558 case 'S': in_elem_bt[i] = T_SHORT; break;
aoqi@1 1559 case 'Z': in_elem_bt[i] = T_BOOLEAN; break;
aoqi@1 1560 default: ShouldNotReachHere();
aoqi@1 1561 }
aoqi@1 1562 }
aoqi@1 1563 } else {
aoqi@1 1564 out_sig_bt[argc++] = in_sig_bt[i];
aoqi@1 1565 in_elem_bt[i] = T_VOID;
aoqi@1 1566 }
aoqi@1 1567 if (in_sig_bt[i] != T_VOID) {
aoqi@1 1568 assert(in_sig_bt[i] == ss.type(), "must match");
aoqi@1 1569 ss.next();
aoqi@1 1570 }
aoqi@1 1571 }
aoqi@1 1572 }
aoqi@1 1573
aoqi@1 1574 // Now figure out where the args must be stored and how much stack space
aoqi@1 1575 // they require (neglecting out_preserve_stack_slots but space for storing
aoqi@1 1576 // the 1st six register arguments). It's weird see int_stk_helper.
aoqi@1 1577 //
aoqi@1 1578 int out_arg_slots;
aoqi@6880 1579 out_arg_slots = c_calling_convention(out_sig_bt, out_regs, NULL, total_c_args);
aoqi@1 1580
aoqi@1 1581 // Compute framesize for the wrapper. We need to handlize all oops in
aoqi@1 1582 // registers. We must create space for them here that is disjoint from
aoqi@1 1583 // the windowed save area because we have no control over when we might
aoqi@1 1584 // flush the window again and overwrite values that gc has since modified.
aoqi@1 1585 // (The live window race)
aoqi@1 1586 //
aoqi@1 1587 // We always just allocate 6 word for storing down these object. This allow
aoqi@1 1588 // us to simply record the base and use the Ireg number to decide which
aoqi@1 1589 // slot to use. (Note that the reg number is the inbound number not the
aoqi@1 1590 // outbound number).
aoqi@1 1591 // We must shuffle args to match the native convention, and include var-args space.
aoqi@1 1592
aoqi@1 1593 // Calculate the total number of stack slots we will need.
aoqi@1 1594
aoqi@1 1595 // First count the abi requirement plus all of the outgoing args
aoqi@1 1596 int stack_slots = SharedRuntime::out_preserve_stack_slots() + out_arg_slots;
aoqi@1 1597
aoqi@1 1598 // Now the space for the inbound oop handle area
aoqi@1 1599 int total_save_slots = 9 * VMRegImpl::slots_per_word; // 9 arguments passed in registers
aoqi@1 1600 if (is_critical_native) {
aoqi@1 1601 // Critical natives may have to call out so they need a save area
aoqi@1 1602 // for register arguments.
aoqi@1 1603 int double_slots = 0;
aoqi@1 1604 int single_slots = 0;
aoqi@1 1605 for ( int i = 0; i < total_in_args; i++) {
aoqi@1 1606 if (in_regs[i].first()->is_Register()) {
aoqi@1 1607 const Register reg = in_regs[i].first()->as_Register();
aoqi@1 1608 switch (in_sig_bt[i]) {
aoqi@1 1609 case T_BOOLEAN:
aoqi@1 1610 case T_BYTE:
aoqi@1 1611 case T_SHORT:
aoqi@1 1612 case T_CHAR:
aoqi@1 1613 case T_INT: single_slots++; break;
aoqi@1 1614 case T_ARRAY: // specific to LP64 (7145024)
aoqi@1 1615 case T_LONG: double_slots++; break;
aoqi@1 1616 default: ShouldNotReachHere();
aoqi@1 1617 }
aoqi@1 1618 } else if (in_regs[i].first()->is_FloatRegister()) {
aoqi@1 1619 switch (in_sig_bt[i]) {
aoqi@1 1620 case T_FLOAT: single_slots++; break;
aoqi@1 1621 case T_DOUBLE: double_slots++; break;
aoqi@1 1622 default: ShouldNotReachHere();
aoqi@1 1623 }
aoqi@1 1624 }
aoqi@1 1625 }
aoqi@1 1626 total_save_slots = double_slots * 2 + single_slots;
aoqi@1 1627 // align the save area
aoqi@1 1628 if (double_slots != 0) {
aoqi@1 1629 stack_slots = round_to(stack_slots, 2);
aoqi@1 1630 }
aoqi@1 1631 }
aoqi@1 1632
aoqi@1 1633 int oop_handle_offset = stack_slots;
aoqi@1 1634 stack_slots += total_save_slots;
aoqi@1 1635
aoqi@1 1636 // Now any space we need for handlizing a klass if static method
aoqi@1 1637
aoqi@6880 1638 int klass_slot_offset = 0;
aoqi@6880 1639 int klass_offset = -1;
aoqi@6880 1640 int lock_slot_offset = 0;
aoqi@6880 1641 bool is_static = false;
aoqi@1 1642
aoqi@1 1643 if (method->is_static()) {
aoqi@1 1644 klass_slot_offset = stack_slots;
aoqi@1 1645 stack_slots += VMRegImpl::slots_per_word;
aoqi@1 1646 klass_offset = klass_slot_offset * VMRegImpl::stack_slot_size;
aoqi@1 1647 is_static = true;
aoqi@1 1648 }
aoqi@1 1649
aoqi@1 1650 // Plus a lock if needed
aoqi@1 1651
aoqi@1 1652 if (method->is_synchronized()) {
aoqi@1 1653 lock_slot_offset = stack_slots;
aoqi@1 1654 stack_slots += VMRegImpl::slots_per_word;
aoqi@1 1655 }
aoqi@1 1656
aoqi@1 1657 // Now a place to save return value or as a temporary for any gpr -> fpr moves
aoqi@6880 1658 // + 2 for return address (which we own) and saved ebp
aoqi@6880 1659 stack_slots += 2 + 9 * VMRegImpl::slots_per_word; // (T0, A0, A1, A2, A3, A4, A5, A6, A7)
aoqi@1 1660
aoqi@1 1661 // Ok The space we have allocated will look like:
aoqi@1 1662 //
aoqi@1 1663 //
aoqi@1 1664 // FP-> | |
aoqi@1 1665 // |---------------------|
aoqi@1 1666 // | 2 slots for moves |
aoqi@1 1667 // |---------------------|
aoqi@1 1668 // | lock box (if sync) |
aoqi@1 1669 // |---------------------| <- lock_slot_offset
aoqi@1 1670 // | klass (if static) |
aoqi@1 1671 // |---------------------| <- klass_slot_offset
aoqi@1 1672 // | oopHandle area |
aoqi@1 1673 // |---------------------| <- oop_handle_offset
aoqi@1 1674 // | outbound memory |
aoqi@1 1675 // | based arguments |
aoqi@1 1676 // | |
aoqi@1 1677 // |---------------------|
aoqi@1 1678 // | vararg area |
aoqi@1 1679 // |---------------------|
aoqi@1 1680 // | |
aoqi@1 1681 // SP-> | out_preserved_slots |
aoqi@1 1682 //
aoqi@1 1683 //
aoqi@1 1684
aoqi@1 1685
aoqi@1 1686 // Now compute actual number of stack words we need rounding to make
aoqi@1 1687 // stack properly aligned.
aoqi@1 1688 stack_slots = round_to(stack_slots, StackAlignmentInSlots);
aoqi@1 1689
aoqi@1 1690 int stack_size = stack_slots * VMRegImpl::stack_slot_size;
aoqi@1 1691
aoqi@6880 1692 intptr_t start = (intptr_t)__ pc();
aoqi@6880 1693
aoqi@6880 1694
aoqi@6880 1695
aoqi@6880 1696 // First thing make an ic check to see if we should even be here
aoqi@6880 1697 address ic_miss = SharedRuntime::get_ic_miss_stub();
aoqi@6880 1698
aoqi@6880 1699 // We are free to use all registers as temps without saving them and
aoqi@6880 1700 // restoring them except ebp. ebp is the only callee save register
aoqi@6880 1701 // as far as the interpreter and the compiler(s) are concerned.
aoqi@1 1702
aoqi@1 1703 //refer to register_mips.hpp:IC_Klass
aoqi@6880 1704 const Register ic_reg = T1;
aoqi@6880 1705 const Register receiver = T0;
aoqi@6880 1706
aoqi@6880 1707 Label hit;
aoqi@6880 1708 Label exception_pending;
aoqi@6880 1709
aoqi@6880 1710 __ verify_oop(receiver);
aoqi@6880 1711 //add for compressedoops
aoqi@6880 1712 __ load_klass(T9, receiver);
aoqi@6880 1713 __ beq(T9, ic_reg, hit);
aoqi@6880 1714 __ delayed()->nop();
aoqi@6880 1715 __ jmp(ic_miss, relocInfo::runtime_call_type);
aoqi@6880 1716 __ delayed()->nop();
aoqi@6880 1717 // verified entry must be aligned for code patching.
aoqi@6880 1718 // and the first 5 bytes must be in the same cache line
aoqi@6880 1719 // if we align at 8 then we will be sure 5 bytes are in the same line
aoqi@6880 1720 __ align(8);
aoqi@6880 1721
aoqi@6880 1722 __ bind(hit);
aoqi@6880 1723
aoqi@6880 1724
aoqi@6880 1725 int vep_offset = ((intptr_t)__ pc()) - start;
aoqi@1 1726 #ifdef COMPILER1
aoqi@6880 1727 if (InlineObjectHash && method->intrinsic_id() == vmIntrinsics::_hashCode) {
aoqi@6880 1728 // Object.hashCode can pull the hashCode from the header word
aoqi@6880 1729 // instead of doing a full VM transition once it's been computed.
aoqi@6880 1730 // Since hashCode is usually polymorphic at call sites we can't do
aoqi@6880 1731 // this optimization at the call site without a lot of work.
aoqi@6880 1732 Label slowCase;
aoqi@6880 1733 Register receiver = T0;
aoqi@6880 1734 Register result = V0;
aoqi@6880 1735 __ ld ( result, receiver, oopDesc::mark_offset_in_bytes());
aoqi@6880 1736 // check if locked
aoqi@6880 1737 __ andi(AT, result, markOopDesc::unlocked_value);
aoqi@6880 1738 __ beq(AT, R0, slowCase);
aoqi@6880 1739 __ delayed()->nop();
aoqi@6880 1740 if (UseBiasedLocking) {
aoqi@6880 1741 // Check if biased and fall through to runtime if so
aoqi@6880 1742 __ andi (AT, result, markOopDesc::biased_lock_bit_in_place);
aoqi@6880 1743 __ bne(AT,R0, slowCase);
aoqi@6880 1744 __ delayed()->nop();
aoqi@6880 1745 }
aoqi@6880 1746 // get hash
aoqi@6880 1747 __ li(AT, markOopDesc::hash_mask_in_place);
aoqi@6880 1748 __ andr (AT, result, AT);
aoqi@6880 1749 // test if hashCode exists
aoqi@6880 1750 __ beq (AT, R0, slowCase);
aoqi@6880 1751 __ delayed()->nop();
aoqi@6880 1752 __ shr(result, markOopDesc::hash_shift);
aoqi@6880 1753 __ jr(RA);
aoqi@6880 1754 __ delayed()->nop();
aoqi@6880 1755 __ bind (slowCase);
aoqi@6880 1756 }
aoqi@1 1757 #endif // COMPILER1
aoqi@1 1758
aoqi@6880 1759 // The instruction at the verified entry point must be 5 bytes or longer
aoqi@6880 1760 // because it can be patched on the fly by make_non_entrant. The stack bang
aoqi@6880 1761 // instruction fits that requirement.
aoqi@6880 1762
aoqi@6880 1763 // Generate stack overflow check
aoqi@6880 1764
aoqi@6880 1765 if (UseStackBanging) {
aoqi@6880 1766 __ bang_stack_with_offset(StackShadowPages*os::vm_page_size());
aoqi@6880 1767 } else {
aoqi@6880 1768 // need a 5 byte instruction to allow MT safe patching to non-entrant
aoqi@6880 1769 __ nop();
aoqi@6880 1770 __ nop();
aoqi@6880 1771 __ nop();
aoqi@6880 1772 __ nop();
aoqi@6880 1773 __ nop();
aoqi@6880 1774 }
aoqi@6880 1775 // Generate a new frame for the wrapper.
aoqi@6880 1776 // do mips need this ?
aoqi@1 1777 #ifndef OPT_THREAD
aoqi@6880 1778 __ get_thread(TREG);
aoqi@1 1779 #endif
aoqi@1 1780 //FIXME here
aoqi@6880 1781 __ st_ptr(SP, TREG, in_bytes(JavaThread::last_Java_sp_offset()));
aoqi@6880 1782 __ move(AT, -(StackAlignmentInBytes));
aoqi@6880 1783 __ andr(SP, SP, AT);
aoqi@6880 1784
aoqi@6880 1785 __ enter();
aoqi@8009 1786 // -2 because return address is already present and so is saved ebp
aoqi@6880 1787 __ addiu(SP, SP, -1 * (stack_size - 2*wordSize));
aoqi@6880 1788
aoqi@6880 1789 // Frame is now completed as far a size and linkage.
aoqi@6880 1790
aoqi@6880 1791 int frame_complete = ((intptr_t)__ pc()) - start;
aoqi@6880 1792
aoqi@6880 1793 // Calculate the difference between esp and ebp. We need to know it
aoqi@6880 1794 // after the native call because on windows Java Natives will pop
aoqi@6880 1795 // the arguments and it is painful to do esp relative addressing
aoqi@6880 1796 // in a platform independent way. So after the call we switch to
aoqi@6880 1797 // ebp relative addressing.
aoqi@6880 1798 //FIXME actually , the fp_adjustment may not be the right, because andr(sp,sp,at)may change
aoqi@7997 1799 //the SP
aoqi@6880 1800 int fp_adjustment = stack_size - 2*wordSize;
aoqi@1 1801
aoqi@1 1802 #ifdef COMPILER2
aoqi@6880 1803 // C2 may leave the stack dirty if not in SSE2+ mode
aoqi@6880 1804 __ empty_FPU_stack();
aoqi@1 1805 #endif /* COMPILER2 */
aoqi@1 1806
aoqi@6880 1807 // Compute the ebp offset for any slots used after the jni call
aoqi@6880 1808
aoqi@6880 1809 int lock_slot_ebp_offset = (lock_slot_offset*VMRegImpl::stack_slot_size) - fp_adjustment;
aoqi@6880 1810 // We use edi as a thread pointer because it is callee save and
aoqi@6880 1811 // if we load it once it is usable thru the entire wrapper
aoqi@6880 1812 // const Register thread = edi;
aoqi@6880 1813 const Register thread = TREG;
aoqi@6880 1814
aoqi@6880 1815 // We use esi as the oop handle for the receiver/klass
aoqi@6880 1816 // It is callee save so it survives the call to native
aoqi@6880 1817
aoqi@6880 1818 // const Register oop_handle_reg = esi;
aoqi@6880 1819 const Register oop_handle_reg = S4;
aoqi@1 1820 if (is_critical_native) {
aoqi@1 1821 __ stop("generate_native_wrapper in sharedRuntime <2>");
aoqi@1 1822 //TODO:Fu
aoqi@1 1823 /*
aoqi@1 1824 check_needs_gc_for_critical_native(masm, stack_slots, total_c_args, total_in_args,
aoqi@1 1825 oop_handle_offset, oop_maps, in_regs, in_sig_bt);
aoqi@1 1826 */
aoqi@1 1827 }
aoqi@1 1828
aoqi@1 1829 #ifndef OPT_THREAD
aoqi@6880 1830 __ get_thread(thread);
aoqi@1 1831 #endif
aoqi@1 1832
aoqi@1 1833 //
aoqi@1 1834 // We immediately shuffle the arguments so that any vm call we have to
aoqi@1 1835 // make from here on out (sync slow path, jvmpi, etc.) we will have
aoqi@1 1836 // captured the oops from our caller and have a valid oopMap for
aoqi@1 1837 // them.
aoqi@1 1838
aoqi@1 1839 // -----------------
aoqi@6880 1840 // The Grand Shuffle
aoqi@1 1841 //
aoqi@1 1842 // Natives require 1 or 2 extra arguments over the normal ones: the JNIEnv*
aoqi@1 1843 // and, if static, the class mirror instead of a receiver. This pretty much
aoqi@1 1844 // guarantees that register layout will not match (and mips doesn't use reg
aoqi@1 1845 // parms though amd does). Since the native abi doesn't use register args
aoqi@1 1846 // and the java conventions does we don't have to worry about collisions.
aoqi@1 1847 // All of our moved are reg->stack or stack->stack.
aoqi@1 1848 // We ignore the extra arguments during the shuffle and handle them at the
aoqi@1 1849 // last moment. The shuffle is described by the two calling convention
aoqi@1 1850 // vectors we have in our possession. We simply walk the java vector to
aoqi@1 1851 // get the source locations and the c vector to get the destinations.
aoqi@1 1852
aoqi@6880 1853 int c_arg = method->is_static() ? 2 : 1 ;
aoqi@6880 1854
aoqi@6880 1855 // Record esp-based slot for receiver on stack for non-static methods
aoqi@6880 1856 int receiver_offset = -1;
aoqi@6880 1857
aoqi@6880 1858 // This is a trick. We double the stack slots so we can claim
aoqi@6880 1859 // the oops in the caller's frame. Since we are sure to have
aoqi@6880 1860 // more args than the caller doubling is enough to make
aoqi@6880 1861 // sure we can capture all the incoming oop args from the
aoqi@6880 1862 // caller.
aoqi@6880 1863 //
aoqi@6880 1864 OopMap* map = new OopMap(stack_slots * 2, 0 /* arg_slots*/);
aoqi@1 1865
aoqi@1 1866 // Mark location of rbp (someday)
aoqi@1 1867 // map->set_callee_saved(VMRegImpl::stack2reg( stack_slots - 2), stack_slots * 2, 0, vmreg(rbp));
aoqi@1 1868
aoqi@1 1869 // Use eax, ebx as temporaries during any memory-memory moves we have to do
aoqi@1 1870 // All inbound args are referenced based on rbp and all outbound args via rsp.
aoqi@1 1871
aoqi@1 1872
aoqi@1 1873
aoqi@1 1874 #ifdef ASSERT
aoqi@1 1875 bool reg_destroyed[RegisterImpl::number_of_registers];
aoqi@1 1876 bool freg_destroyed[FloatRegisterImpl::number_of_registers];
aoqi@1 1877 for ( int r = 0 ; r < RegisterImpl::number_of_registers ; r++ ) {
aoqi@1 1878 reg_destroyed[r] = false;
aoqi@1 1879 }
aoqi@1 1880 for ( int f = 0 ; f < FloatRegisterImpl::number_of_registers ; f++ ) {
aoqi@1 1881 freg_destroyed[f] = false;
aoqi@1 1882 }
aoqi@1 1883
aoqi@1 1884 #endif /* ASSERT */
aoqi@1 1885
aoqi@6880 1886 // We know that we only have args in at most two integer registers (ecx, edx). So eax, ebx
aoqi@6880 1887 // Are free to temporaries if we have to do stack to steck moves.
aoqi@6880 1888 // All inbound args are referenced based on ebp and all outbound args via esp.
aoqi@1 1889
aoqi@1 1890 // This may iterate in two different directions depending on the
aoqi@1 1891 // kind of native it is. The reason is that for regular JNI natives
aoqi@1 1892 // the incoming and outgoing registers are offset upwards and for
aoqi@1 1893 // critical natives they are offset down.
aoqi@1 1894 GrowableArray<int> arg_order(2 * total_in_args);
aoqi@1 1895 VMRegPair tmp_vmreg;
aoqi@1 1896 tmp_vmreg.set1(T8->as_VMReg());
aoqi@1 1897
aoqi@1 1898 if (!is_critical_native) {
aoqi@1 1899 for (int i = total_in_args - 1, c_arg = total_c_args - 1; i >= 0; i--, c_arg--) {
aoqi@1 1900 arg_order.push(i);
aoqi@1 1901 arg_order.push(c_arg);
aoqi@1 1902 }
aoqi@1 1903 } else {
aoqi@1 1904 // Compute a valid move order, using tmp_vmreg to break any cycles
aoqi@1 1905 __ stop("generate_native_wrapper in sharedRuntime <2>");
aoqi@1 1906 //TODO:Fu
aoqi@1 1907 // ComputeMoveOrder cmo(total_in_args, in_regs, total_c_args, out_regs, in_sig_bt, arg_order, tmp_vmreg);
aoqi@1 1908 }
aoqi@1 1909
aoqi@1 1910 int temploc = -1;
aoqi@1 1911 for (int ai = 0; ai < arg_order.length(); ai += 2) {
aoqi@1 1912 int i = arg_order.at(ai);
aoqi@1 1913 int c_arg = arg_order.at(ai + 1);
aoqi@1 1914 __ block_comment(err_msg("move %d -> %d", i, c_arg));
aoqi@1 1915 if (c_arg == -1) {
aoqi@1 1916 assert(is_critical_native, "should only be required for critical natives");
aoqi@1 1917 // This arg needs to be moved to a temporary
aoqi@1 1918 __ move(tmp_vmreg.first()->as_Register(), in_regs[i].first()->as_Register());
aoqi@1 1919 in_regs[i] = tmp_vmreg;
aoqi@1 1920 temploc = i;
aoqi@1 1921 continue;
aoqi@1 1922 } else if (i == -1) {
aoqi@1 1923 assert(is_critical_native, "should only be required for critical natives");
aoqi@1 1924 // Read from the temporary location
aoqi@1 1925 assert(temploc != -1, "must be valid");
aoqi@1 1926 i = temploc;
aoqi@1 1927 temploc = -1;
aoqi@1 1928 }
aoqi@1 1929 #ifdef ASSERT
aoqi@1 1930 if (in_regs[i].first()->is_Register()) {
aoqi@1 1931 assert(!reg_destroyed[in_regs[i].first()->as_Register()->encoding()], "destroyed reg!");
aoqi@1 1932 } else if (in_regs[i].first()->is_FloatRegister()) {
aoqi@1 1933 assert(!freg_destroyed[in_regs[i].first()->as_FloatRegister()->encoding()], "destroyed reg!");
aoqi@1 1934 }
aoqi@1 1935 if (out_regs[c_arg].first()->is_Register()) {
aoqi@1 1936 reg_destroyed[out_regs[c_arg].first()->as_Register()->encoding()] = true;
aoqi@1 1937 } else if (out_regs[c_arg].first()->is_FloatRegister()) {
aoqi@1 1938 freg_destroyed[out_regs[c_arg].first()->as_FloatRegister()->encoding()] = true;
aoqi@1 1939 }
aoqi@1 1940 #endif /* ASSERT */
aoqi@1 1941 switch (in_sig_bt[i]) {
aoqi@1 1942 case T_ARRAY:
aoqi@1 1943 if (is_critical_native) {
aoqi@6880 1944 __ stop("generate_native_wrapper in sharedRuntime <2>");
aoqi@1 1945 //TODO:Fu
aoqi@1 1946 // unpack_array_argument(masm, in_regs[i], in_elem_bt[i], out_regs[c_arg + 1], out_regs[c_arg]);
aoqi@1 1947 c_arg++;
aoqi@1 1948 #ifdef ASSERT
aoqi@1 1949 if (out_regs[c_arg].first()->is_Register()) {
aoqi@1 1950 reg_destroyed[out_regs[c_arg].first()->as_Register()->encoding()] = true;
aoqi@1 1951 } else if (out_regs[c_arg].first()->is_FloatRegister()) {
aoqi@1 1952 freg_destroyed[out_regs[c_arg].first()->as_FloatRegister()->encoding()] = true;
aoqi@1 1953 }
aoqi@1 1954 #endif
aoqi@1 1955 break;
aoqi@1 1956 }
aoqi@1 1957 case T_OBJECT:
aoqi@1 1958 assert(!is_critical_native, "no oop arguments");
aoqi@1 1959 object_move(masm, map, oop_handle_offset, stack_slots, in_regs[i], out_regs[c_arg],
aoqi@1 1960 ((i == 0) && (!is_static)),
aoqi@1 1961 &receiver_offset);
aoqi@1 1962 break;
aoqi@1 1963 case T_VOID:
aoqi@1 1964 break;
aoqi@1 1965
aoqi@1 1966 case T_FLOAT:
aoqi@1 1967 float_move(masm, in_regs[i], out_regs[c_arg]);
aoqi@1 1968 break;
aoqi@1 1969
aoqi@1 1970 case T_DOUBLE:
aoqi@1 1971 assert( i + 1 < total_in_args &&
aoqi@1 1972 in_sig_bt[i + 1] == T_VOID &&
aoqi@1 1973 out_sig_bt[c_arg+1] == T_VOID, "bad arg list");
aoqi@1 1974 double_move(masm, in_regs[i], out_regs[c_arg]);
aoqi@1 1975 break;
aoqi@1 1976
aoqi@1 1977 case T_LONG :
aoqi@1 1978 long_move(masm, in_regs[i], out_regs[c_arg]);
aoqi@1 1979 break;
aoqi@1 1980
aoqi@1 1981 case T_ADDRESS: assert(false, "found T_ADDRESS in java args");
aoqi@1 1982
aoqi@1 1983 default:
aoqi@1 1984 simple_move32(masm, in_regs[i], out_regs[c_arg]);
aoqi@1 1985 }
aoqi@1 1986 }
aoqi@1 1987
aoqi@1 1988 // point c_arg at the first arg that is already loaded in case we
aoqi@1 1989 // need to spill before we call out
aoqi@1 1990 c_arg = total_c_args - total_in_args;
aoqi@6880 1991 // Pre-load a static method's oop into esi. Used both by locking code and
aoqi@6880 1992 // the normal JNI call code.
aoqi@6880 1993
aoqi@6880 1994 __ move(oop_handle_reg, A1);
aoqi@6880 1995
aoqi@6880 1996 if (method->is_static() && !is_critical_native) {
aoqi@6880 1997
aoqi@6880 1998 // load opp into a register
aoqi@6880 1999 int oop_index = __ oop_recorder()->find_index(JNIHandles::make_local(
aoqi@6880 2000 (method->method_holder())->java_mirror()));
aoqi@6880 2001
aoqi@6880 2002
aoqi@6880 2003 RelocationHolder rspec = oop_Relocation::spec(oop_index);
aoqi@6880 2004 __ relocate(rspec);
aoqi@6880 2005 __ patchable_set48(oop_handle_reg, (long)JNIHandles::make_local((method->method_holder())->java_mirror()));
aoqi@6880 2006 // Now handlize the static class mirror it's known not-null.
aoqi@6880 2007 __ sd( oop_handle_reg, SP, klass_offset);
aoqi@6880 2008 map->set_oop(VMRegImpl::stack2reg(klass_slot_offset));
aoqi@6880 2009
aoqi@6880 2010 // Now get the handle
aoqi@6880 2011 __ lea(oop_handle_reg, Address(SP, klass_offset));
aoqi@6880 2012 // store the klass handle as second argument
aoqi@6880 2013 __ move(A1, oop_handle_reg);
aoqi@6880 2014 // and protect the arg if we must spill
aoqi@6880 2015 c_arg--;
aoqi@6880 2016 }
aoqi@6880 2017
aoqi@1 2018 // Change state to native (we save the return address in the thread, since it might not
aoqi@1 2019 // be pushed on the stack when we do a a stack traversal). It is enough that the pc()
aoqi@1 2020 // points into the right code segment. It does not have to be the correct return pc.
aoqi@1 2021 // We use the same pc/oopMap repeatedly when we call out
aoqi@1 2022
aoqi@6880 2023 intptr_t the_pc = (intptr_t) __ pc();
aoqi@6880 2024 oop_maps->add_gc_map(the_pc - start, map);
aoqi@6880 2025
aoqi@6880 2026 __ set_last_Java_frame(SP, noreg, NULL);
aoqi@6880 2027 __ relocate(relocInfo::internal_pc_type);
aoqi@6880 2028 {
aoqi@6880 2029 intptr_t save_pc = (intptr_t)the_pc ;
aoqi@6880 2030 __ patchable_set48(AT, save_pc);
aoqi@6880 2031 }
aoqi@6880 2032 __ sd(AT, thread, in_bytes(JavaThread::frame_anchor_offset() + JavaFrameAnchor::last_Java_pc_offset()));
aoqi@6880 2033
aoqi@6880 2034
aoqi@6880 2035 // We have all of the arguments setup at this point. We must not touch any register
aoqi@6880 2036 // argument registers at this point (what if we save/restore them there are no oop?
aoqi@6880 2037 {
aoqi@6880 2038 SkipIfEqual skip_if(masm, &DTraceMethodProbes, 0);
aoqi@6880 2039 int metadata_index = __ oop_recorder()->find_index(method());
aoqi@6880 2040 RelocationHolder rspec = metadata_Relocation::spec(metadata_index);
aoqi@6880 2041 __ relocate(rspec);
aoqi@6880 2042 __ patchable_set48(AT, (long)(method()));
aoqi@6880 2043
aoqi@6880 2044 __ call_VM_leaf(
aoqi@6880 2045 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
aoqi@6880 2046 thread, AT);
aoqi@6880 2047
aoqi@6880 2048 }
aoqi@6880 2049
aoqi@6880 2050 // These are register definitions we need for locking/unlocking
aoqi@6880 2051 const Register swap_reg = T8; // Must use eax for cmpxchg instruction
aoqi@6880 2052 const Register obj_reg = T9; // Will contain the oop
aoqi@6880 2053 //const Register lock_reg = T6; // Address of compiler lock object (BasicLock)
aoqi@6880 2054 const Register lock_reg = c_rarg0; // Address of compiler lock object (BasicLock)
aoqi@6880 2055
aoqi@6880 2056
aoqi@6880 2057
aoqi@6880 2058 Label slow_path_lock;
aoqi@6880 2059 Label lock_done;
aoqi@6880 2060
aoqi@6880 2061 // Lock a synchronized method
aoqi@6880 2062 if (method->is_synchronized()) {
aoqi@6880 2063 assert(!is_critical_native, "unhandled");
aoqi@6880 2064
aoqi@6880 2065 const int mark_word_offset = BasicLock::displaced_header_offset_in_bytes();
aoqi@6880 2066
aoqi@6880 2067 // Get the handle (the 2nd argument)
aoqi@6880 2068 __ move(oop_handle_reg, A1);
aoqi@6880 2069
aoqi@6880 2070 // Get address of the box
aoqi@6880 2071 __ lea(lock_reg, Address(FP, lock_slot_ebp_offset));
aoqi@6880 2072
aoqi@6880 2073 // Load the oop from the handle
aoqi@6880 2074 __ ld(obj_reg, oop_handle_reg, 0);
aoqi@6880 2075
aoqi@6880 2076 if (UseBiasedLocking) {
aoqi@6880 2077 // Note that oop_handle_reg is trashed during this call
aoqi@6880 2078 __ biased_locking_enter(lock_reg, obj_reg, swap_reg, A1, false, lock_done, &slow_path_lock);
aoqi@6880 2079 }
aoqi@6880 2080
aoqi@6880 2081 // Load immediate 1 into swap_reg %eax
aoqi@6880 2082 __ move(swap_reg, 1);
aoqi@6880 2083
aoqi@6880 2084 __ ld(AT, obj_reg, 0);
aoqi@6880 2085 __ orr(swap_reg, swap_reg, AT);
aoqi@6880 2086
aoqi@6880 2087 __ sd( swap_reg, lock_reg, mark_word_offset);
aoqi@6880 2088 __ cmpxchg(lock_reg, Address(obj_reg, 0), swap_reg);
aoqi@6880 2089 __ bne(AT, R0, lock_done);
aoqi@6880 2090 __ delayed()->nop();
aoqi@6880 2091 // Test if the oopMark is an obvious stack pointer, i.e.,
aoqi@6880 2092 // 1) (mark & 3) == 0, and
aoqi@6880 2093 // 2) esp <= mark < mark + os::pagesize()
aoqi@6880 2094 // These 3 tests can be done by evaluating the following
aoqi@6880 2095 // expression: ((mark - esp) & (3 - os::vm_page_size())),
aoqi@6880 2096 // assuming both stack pointer and pagesize have their
aoqi@6880 2097 // least significant 2 bits clear.
aoqi@6880 2098 // NOTE: the oopMark is in swap_reg %eax as the result of cmpxchg
aoqi@6880 2099
aoqi@8009 2100 __ dsub(swap_reg, swap_reg, SP);
aoqi@8009 2101 __ move(AT, 3 - os::vm_page_size());
aoqi@6880 2102 __ andr(swap_reg , swap_reg, AT);
aoqi@6880 2103 // Save the test result, for recursive case, the result is zero
aoqi@6880 2104 __ sd(swap_reg, lock_reg, mark_word_offset);
aoqi@6880 2105 //FIXME here, Why notEqual?
aoqi@8009 2106 __ bne(swap_reg, R0, slow_path_lock);
aoqi@6880 2107 __ delayed()->nop();
aoqi@6880 2108 // Slow path will re-enter here
aoqi@6880 2109 __ bind(lock_done);
aoqi@6880 2110
aoqi@6880 2111 if (UseBiasedLocking) {
aoqi@6880 2112 // Re-fetch oop_handle_reg as we trashed it above
aoqi@6880 2113 __ move(A1, oop_handle_reg);
aoqi@6880 2114 }
aoqi@6880 2115 }
aoqi@6880 2116
aoqi@6880 2117
aoqi@6880 2118 // Finally just about ready to make the JNI call
aoqi@6880 2119
aoqi@6880 2120
aoqi@6880 2121 // get JNIEnv* which is first argument to native
aoqi@1 2122 if (!is_critical_native) {
aoqi@8009 2123 __ addi(A0, thread, in_bytes(JavaThread::jni_environment_offset()));
aoqi@1 2124 }
aoqi@1 2125
aoqi@6880 2126 // Example: Java_java_lang_ref_Finalizer_invokeFinalizeMethod(JNIEnv *env, jclass clazz, jobject ob)
aoqi@6880 2127 /* Load the second arguments into A1 */
aoqi@6880 2128 //__ ld(A1, SP , wordSize ); // klass
aoqi@6880 2129
aoqi@6880 2130 // Now set thread in native
aoqi@6880 2131 __ addi(AT, R0, _thread_in_native);
aoqi@6880 2132 __ sw(AT, thread, in_bytes(JavaThread::thread_state_offset()));
aoqi@6880 2133 /* Jin: do the call */
aoqi@6880 2134 __ call(method->native_function(), relocInfo::runtime_call_type);
aoqi@6880 2135 __ delayed()->nop();
aoqi@6880 2136 // WARNING - on Windows Java Natives use pascal calling convention and pop the
aoqi@6880 2137 // arguments off of the stack. We could just re-adjust the stack pointer here
aoqi@6880 2138 // and continue to do SP relative addressing but we instead switch to FP
aoqi@6880 2139 // relative addressing.
aoqi@6880 2140
aoqi@6880 2141 // Unpack native results.
aoqi@6880 2142 switch (ret_type) {
aoqi@6880 2143 case T_BOOLEAN: __ c2bool(V0); break;
aoqi@6880 2144 case T_CHAR : __ andi(V0,V0, 0xFFFF); break;
aoqi@6880 2145 case T_BYTE : __ sign_extend_byte (V0); break;
aoqi@6880 2146 case T_SHORT : __ sign_extend_short(V0); break;
aoqi@6880 2147 case T_INT : // nothing to do break;
aoqi@6880 2148 case T_DOUBLE :
aoqi@6880 2149 case T_FLOAT :
aoqi@6880 2150 // Result is in st0 we'll save as needed
aoqi@6880 2151 break;
aoqi@6880 2152 case T_ARRAY: // Really a handle
aoqi@6880 2153 case T_OBJECT: // Really a handle
aoqi@6880 2154 break; // can't de-handlize until after safepoint check
aoqi@6880 2155 case T_VOID: break;
aoqi@6880 2156 case T_LONG: break;
aoqi@6880 2157 default : ShouldNotReachHere();
aoqi@6880 2158 }
aoqi@6880 2159 // Switch thread to "native transition" state before reading the synchronization state.
aoqi@6880 2160 // This additional state is necessary because reading and testing the synchronization
aoqi@6880 2161 // state is not atomic w.r.t. GC, as this scenario demonstrates:
aoqi@6880 2162 // Java thread A, in _thread_in_native state, loads _not_synchronized and is preempted.
aoqi@6880 2163 // VM thread changes sync state to synchronizing and suspends threads for GC.
aoqi@6880 2164 // Thread A is resumed to finish this native method, but doesn't block here since it
aoqi@6880 2165 // didn't see any synchronization is progress, and escapes.
aoqi@6880 2166 __ addi(AT, R0, _thread_in_native_trans);
aoqi@6880 2167 __ sw(AT, thread, in_bytes(JavaThread::thread_state_offset()));
aoqi@6880 2168
aoqi@8009 2169 //if(os::is_MP()) {}
aoqi@8009 2170
aoqi@1 2171 Label after_transition;
aoqi@1 2172
aoqi@6880 2173 // check for safepoint operation in progress and/or pending suspend requests
aoqi@8009 2174 {
aoqi@8009 2175 Label Continue;
aoqi@6880 2176 __ li(AT, SafepointSynchronize::address_of_state());
aoqi@6880 2177 __ lw(A0, AT, 0);
aoqi@6880 2178 __ addi(AT, A0, -SafepointSynchronize::_not_synchronized);
aoqi@6880 2179 Label L;
aoqi@6880 2180 __ bne(AT,R0, L);
aoqi@6880 2181 __ delayed()->nop();
aoqi@6880 2182 __ lw(AT, thread, in_bytes(JavaThread::suspend_flags_offset()));
aoqi@6880 2183 __ beq(AT, R0, Continue);
aoqi@6880 2184 __ delayed()->nop();
aoqi@6880 2185 __ bind(L);
aoqi@6880 2186
aoqi@6880 2187 // Don't use call_VM as it will see a possible pending exception and forward it
aoqi@6880 2188 // and never return here preventing us from clearing _last_native_pc down below.
aoqi@6880 2189 // Also can't use call_VM_leaf either as it will check to see if esi & edi are
aoqi@6880 2190 // preserved and correspond to the bcp/locals pointers. So we do a runtime call
aoqi@6880 2191 // by hand.
aoqi@6880 2192 //
aoqi@6880 2193 save_native_result(masm, ret_type, stack_slots);
aoqi@8009 2194 __ move(A0, thread);
aoqi@8009 2195 __ addi(SP, SP, -wordSize);
aoqi@21 2196 __ push(S2);
aoqi@21 2197 __ move(AT, -(StackAlignmentInBytes));
aoqi@21 2198 __ move(S2, SP); // use S2 as a sender SP holder
aoqi@21 2199 __ andr(SP, SP, AT); // align stack as required by ABI
aoqi@1 2200 if (!is_critical_native) {
aoqi@1 2201 __ call(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans), relocInfo::runtime_call_type);
aoqi@6880 2202 __ delayed()->nop();
aoqi@1 2203 } else {
aoqi@1 2204 __ call(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans_and_transition), relocInfo::runtime_call_type);
aoqi@6880 2205 __ delayed()->nop();
aoqi@1 2206 }
aoqi@21 2207 __ move(SP, S2); // use S2 as a sender SP holder
aoqi@21 2208 __ pop(S2);
aoqi@6880 2209 __ addi(SP,SP, wordSize);
aoqi@6880 2210 //add for compressedoops
aoqi@6880 2211 __ reinit_heapbase();
aoqi@6880 2212 // Restore any method result value
aoqi@6880 2213 restore_native_result(masm, ret_type, stack_slots);
aoqi@1 2214
aoqi@1 2215 if (is_critical_native) {
aoqi@1 2216 // The call above performed the transition to thread_in_Java so
aoqi@1 2217 // skip the transition logic below.
aoqi@1 2218 __ beq(R0, R0, after_transition);
aoqi@6880 2219 __ delayed()->nop();
aoqi@1 2220 }
aoqi@1 2221
aoqi@6880 2222 __ bind(Continue);
aoqi@6880 2223 }
aoqi@6880 2224
aoqi@6880 2225 // change thread state
aoqi@6880 2226 __ addi(AT, R0, _thread_in_Java);
aoqi@6880 2227 __ sw(AT, thread, in_bytes(JavaThread::thread_state_offset()));
aoqi@1 2228 __ bind(after_transition);
aoqi@6880 2229 Label reguard;
aoqi@6880 2230 Label reguard_done;
aoqi@6880 2231 __ lw(AT, thread, in_bytes(JavaThread::stack_guard_state_offset()));
aoqi@6880 2232 __ addi(AT, AT, -JavaThread::stack_guard_yellow_disabled);
aoqi@6880 2233 __ beq(AT, R0, reguard);
aoqi@6880 2234 __ delayed()->nop();
aoqi@6880 2235 // slow path reguard re-enters here
aoqi@6880 2236 __ bind(reguard_done);
aoqi@6880 2237
aoqi@6880 2238 // Handle possible exception (will unlock if necessary)
aoqi@6880 2239
aoqi@6880 2240 // native result if any is live
aoqi@6880 2241
aoqi@6880 2242 // Unlock
aoqi@6880 2243 Label slow_path_unlock;
aoqi@6880 2244 Label unlock_done;
aoqi@6880 2245 if (method->is_synchronized()) {
aoqi@6880 2246
aoqi@6880 2247 Label done;
aoqi@6880 2248
aoqi@6880 2249 // Get locked oop from the handle we passed to jni
aoqi@6880 2250 __ ld( obj_reg, oop_handle_reg, 0);
aoqi@6880 2251 //FIXME
aoqi@6880 2252 if (UseBiasedLocking) {
aoqi@6880 2253 __ biased_locking_exit(obj_reg, T8, done);
aoqi@6880 2254
aoqi@6880 2255 }
aoqi@6880 2256
aoqi@6880 2257 // Simple recursive lock?
aoqi@6880 2258
aoqi@6880 2259 __ ld(AT, FP, lock_slot_ebp_offset);
aoqi@6880 2260 __ beq(AT, R0, done);
aoqi@6880 2261 __ delayed()->nop();
aoqi@6880 2262 // Must save eax if if it is live now because cmpxchg must use it
aoqi@6880 2263 if (ret_type != T_FLOAT && ret_type != T_DOUBLE && ret_type != T_VOID) {
aoqi@6880 2264 save_native_result(masm, ret_type, stack_slots);
aoqi@6880 2265 }
aoqi@6880 2266
aoqi@6880 2267 // get old displaced header
aoqi@6880 2268 __ ld (T8, FP, lock_slot_ebp_offset);
aoqi@6880 2269 // get address of the stack lock
aoqi@6880 2270 __ addi (c_rarg0, FP, lock_slot_ebp_offset);
aoqi@6880 2271 // Atomic swap old header if oop still contains the stack lock
aoqi@6880 2272 __ cmpxchg(T8, Address(obj_reg, 0), c_rarg0);
aoqi@6880 2273
aoqi@6880 2274 __ beq(AT, R0, slow_path_unlock);
aoqi@6880 2275 __ delayed()->nop();
aoqi@6880 2276 // slow path re-enters here
aoqi@6880 2277 __ bind(unlock_done);
aoqi@6880 2278 if (ret_type != T_FLOAT && ret_type != T_DOUBLE && ret_type != T_VOID) {
aoqi@6880 2279 restore_native_result(masm, ret_type, stack_slots);
aoqi@6880 2280 }
aoqi@6880 2281
aoqi@6880 2282 __ bind(done);
aoqi@6880 2283
aoqi@6880 2284 }
aoqi@6880 2285 {
aoqi@6880 2286 SkipIfEqual skip_if(masm, &DTraceMethodProbes, 0);
aoqi@6880 2287 // Tell dtrace about this method exit
aoqi@6880 2288 save_native_result(masm, ret_type, stack_slots);
aoqi@6880 2289 int metadata_index = __ oop_recorder()->find_index( (method()));
aoqi@6880 2290 RelocationHolder rspec = metadata_Relocation::spec(metadata_index);
aoqi@6880 2291 __ relocate(rspec);
aoqi@6880 2292 __ patchable_set48(AT, (long)(method()));
aoqi@6880 2293
aoqi@6880 2294 __ call_VM_leaf(
aoqi@6880 2295 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
aoqi@6880 2296 thread, AT);
aoqi@6880 2297 restore_native_result(masm, ret_type, stack_slots);
aoqi@6880 2298 }
aoqi@6880 2299
aoqi@6880 2300 // We can finally stop using that last_Java_frame we setup ages ago
aoqi@6880 2301
aoqi@6880 2302 __ reset_last_Java_frame(false, true);
aoqi@6880 2303
aoqi@6880 2304 // Unpack oop result
aoqi@6880 2305 if (ret_type == T_OBJECT || ret_type == T_ARRAY) {
aoqi@6880 2306 Label L;
aoqi@8009 2307 __ beq(V0, R0, L);
aoqi@6880 2308 __ delayed()->nop();
aoqi@6880 2309 __ ld(V0, V0, 0);
aoqi@6880 2310 __ bind(L);
aoqi@6880 2311 __ verify_oop(V0);
aoqi@6880 2312 }
aoqi@1 2313
aoqi@1 2314 if (!is_critical_native) {
aoqi@8009 2315 // reset handle block
aoqi@8009 2316 __ ld(AT, thread, in_bytes(JavaThread::active_handles_offset()));
aoqi@8009 2317 __ sw(R0, AT, JNIHandleBlock::top_offset_in_bytes());
aoqi@1 2318 }
aoqi@1 2319
aoqi@1 2320 if (!is_critical_native) {
aoqi@6880 2321 // Any exception pending?
aoqi@6880 2322 __ ld(AT, thread, in_bytes(Thread::pending_exception_offset()));
aoqi@6880 2323 __ bne(AT, R0, exception_pending);
aoqi@6880 2324 __ delayed()->nop();
aoqi@1 2325 }
aoqi@6880 2326 // no exception, we're almost done
aoqi@6880 2327
aoqi@6880 2328 // check that only result value is on FPU stack
aoqi@6880 2329 __ verify_FPU(ret_type == T_FLOAT || ret_type == T_DOUBLE ? 1 : 0, "native_wrapper normal exit");
aoqi@6880 2330
aoqi@1 2331 // Return
aoqi@1 2332 #ifndef OPT_THREAD
aoqi@6880 2333 __ get_thread(TREG);
aoqi@1 2334 #endif
aoqi@8009 2335 //__ ld_ptr(SP, TREG, in_bytes(JavaThread::last_Java_sp_offset()));
aoqi@6880 2336 __ leave();
aoqi@6880 2337
aoqi@6880 2338 __ jr(RA);
aoqi@6880 2339 __ delayed()->nop();
aoqi@6880 2340 // Unexpected paths are out of line and go here
aoqi@1 2341 /*
aoqi@1 2342 if (!is_critical_native) {
aoqi@1 2343 // forward the exception
aoqi@1 2344 __ bind(exception_pending);
aoqi@1 2345
aoqi@1 2346 // and forward the exception
aoqi@1 2347 __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
aoqi@1 2348 }
aoqi@1 2349 */
aoqi@6880 2350 // Slow path locking & unlocking
aoqi@6880 2351 if (method->is_synchronized()) {
aoqi@6880 2352
aoqi@6880 2353 // BEGIN Slow path lock
aoqi@6880 2354 __ bind(slow_path_lock);
aoqi@6880 2355
aoqi@6880 2356 // protect the args we've loaded
aoqi@6880 2357 save_args(masm, total_c_args, c_arg, out_regs);
aoqi@6880 2358
aoqi@6880 2359 // has last_Java_frame setup. No exceptions so do vanilla call not call_VM
aoqi@6880 2360 // args are (oop obj, BasicLock* lock, JavaThread* thread)
aoqi@6880 2361
aoqi@6880 2362 __ move(A0, obj_reg);
aoqi@6880 2363 __ move(A1, lock_reg);
aoqi@6880 2364 __ move(A2, thread);
aoqi@6880 2365 __ addi(SP, SP, - 3*wordSize);
aoqi@6880 2366
aoqi@6880 2367 __ move(AT, -(StackAlignmentInBytes));
aoqi@6880 2368 __ move(S2, SP); // use S2 as a sender SP holder
aoqi@6880 2369 __ andr(SP, SP, AT); // align stack as required by ABI
aoqi@6880 2370
aoqi@6880 2371 __ call(CAST_FROM_FN_PTR(address, SharedRuntime::complete_monitor_locking_C), relocInfo::runtime_call_type);
aoqi@6880 2372 __ delayed()->nop();
aoqi@6880 2373 __ move(SP, S2);
aoqi@6880 2374 __ addi(SP, SP, 3*wordSize);
aoqi@6880 2375
aoqi@6880 2376 restore_args(masm, total_c_args, c_arg, out_regs);
aoqi@6880 2377
aoqi@6880 2378 #ifdef ASSERT
aoqi@6880 2379 { Label L;
aoqi@6880 2380 __ ld(AT, thread, in_bytes(Thread::pending_exception_offset()));
aoqi@6880 2381 __ beq(AT, R0, L);
aoqi@6880 2382 __ delayed()->nop();
aoqi@6880 2383 __ stop("no pending exception allowed on exit from monitorenter");
aoqi@6880 2384 __ bind(L);
aoqi@6880 2385 }
aoqi@6880 2386 #endif
aoqi@6880 2387 __ b(lock_done);
aoqi@6880 2388 __ delayed()->nop();
aoqi@6880 2389 // END Slow path lock
aoqi@6880 2390
aoqi@6880 2391 // BEGIN Slow path unlock
aoqi@6880 2392 __ bind(slow_path_unlock);
aoqi@6880 2393
aoqi@6880 2394 // Slow path unlock
aoqi@6880 2395
aoqi@6880 2396 if (ret_type == T_FLOAT || ret_type == T_DOUBLE ) {
aoqi@6880 2397 save_native_result(masm, ret_type, stack_slots);
aoqi@6880 2398 }
aoqi@6880 2399 // Save pending exception around call to VM (which contains an EXCEPTION_MARK)
aoqi@6880 2400
aoqi@6880 2401 __ ld(AT, thread, in_bytes(Thread::pending_exception_offset()));
aoqi@6880 2402 __ push(AT);
aoqi@6880 2403 __ sd(R0, thread, in_bytes(Thread::pending_exception_offset()));
aoqi@1 2404
aoqi@1 2405 __ move(AT, -(StackAlignmentInBytes));
aoqi@1 2406 __ move(S2, SP); // use S2 as a sender SP holder
aoqi@1 2407 __ andr(SP, SP, AT); // align stack as required by ABI
aoqi@1 2408
aoqi@6880 2409 // should be a peal
aoqi@6880 2410 // +wordSize because of the push above
aoqi@6880 2411 __ addi(A1, FP, lock_slot_ebp_offset);
aoqi@6880 2412
aoqi@6880 2413 __ move(A0, obj_reg);
aoqi@6880 2414 __ addi(SP,SP, -2*wordSize);
aoqi@6880 2415 __ call(CAST_FROM_FN_PTR(address, SharedRuntime::complete_monitor_unlocking_C),
aoqi@6880 2416 relocInfo::runtime_call_type);
aoqi@6880 2417 __ delayed()->nop();
aoqi@6880 2418 __ addi(SP,SP, 2*wordSize);
aoqi@1 2419 __ move(SP, S2);
aoqi@6880 2420 //add for compressedoops
aoqi@6880 2421 __ reinit_heapbase();
aoqi@1 2422 #ifdef ASSERT
aoqi@6880 2423 {
aoqi@6880 2424 Label L;
aoqi@6880 2425 __ lw( AT, thread, in_bytes(Thread::pending_exception_offset()));
aoqi@6880 2426 __ beq(AT, R0, L);
aoqi@6880 2427 __ delayed()->nop();
aoqi@6880 2428 __ stop("no pending exception allowed on exit complete_monitor_unlocking_C");
aoqi@6880 2429 __ bind(L);
aoqi@6880 2430 }
aoqi@1 2431 #endif /* ASSERT */
aoqi@1 2432
aoqi@6880 2433 __ pop(AT);
aoqi@6880 2434 __ sd(AT, thread, in_bytes(Thread::pending_exception_offset()));
aoqi@6880 2435 if (ret_type == T_FLOAT || ret_type == T_DOUBLE ) {
aoqi@6880 2436 restore_native_result(masm, ret_type, stack_slots);
aoqi@1 2437 }
aoqi@6880 2438 __ b(unlock_done);
aoqi@6880 2439 __ delayed()->nop();
aoqi@6880 2440 // END Slow path unlock
aoqi@6880 2441
aoqi@6880 2442 }
aoqi@6880 2443
aoqi@6880 2444 // SLOW PATH Reguard the stack if needed
aoqi@6880 2445
aoqi@6880 2446 __ bind(reguard);
aoqi@6880 2447 save_native_result(masm, ret_type, stack_slots);
aoqi@6880 2448 __ call(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages),
aoqi@6880 2449 relocInfo::runtime_call_type);
aoqi@6880 2450 __ delayed()->nop();
aoqi@6880 2451 //add for compressedoops
aoqi@6880 2452 __ reinit_heapbase();
aoqi@6880 2453 restore_native_result(masm, ret_type, stack_slots);
aoqi@6880 2454 __ b(reguard_done);
aoqi@6880 2455 __ delayed()->nop();
aoqi@6880 2456
aoqi@6880 2457 // BEGIN EXCEPTION PROCESSING
aoqi@6880 2458 if (!is_critical_native) {
aoqi@6880 2459 // Forward the exception
aoqi@6880 2460 __ bind(exception_pending);
aoqi@6880 2461
aoqi@6880 2462 // remove possible return value from FPU register stack
aoqi@6880 2463 __ empty_FPU_stack();
aoqi@6880 2464
aoqi@6880 2465 // pop our frame
aoqi@8009 2466 //forward_exception_entry need return address on stack
aoqi@8009 2467 __ addiu(SP, FP, wordSize);
aoqi@6880 2468 __ ld(FP, SP, (-1) * wordSize);
aoqi@6880 2469
aoqi@6880 2470 // and forward the exception
aoqi@6880 2471 __ jmp(StubRoutines::forward_exception_entry(), relocInfo::runtime_call_type);
aoqi@6880 2472 __ delayed()->nop();
aoqi@6880 2473 }
aoqi@6880 2474 __ flush();
aoqi@6880 2475
aoqi@6880 2476 nmethod *nm = nmethod::new_native_nmethod(method,
aoqi@6880 2477 compile_id,
aoqi@6880 2478 masm->code(),
aoqi@6880 2479 vep_offset,
aoqi@6880 2480 frame_complete,
aoqi@6880 2481 stack_slots / VMRegImpl::slots_per_word,
aoqi@6880 2482 (is_static ? in_ByteSize(klass_offset) : in_ByteSize(receiver_offset)),
aoqi@6880 2483 in_ByteSize(lock_slot_offset*VMRegImpl::stack_slot_size),
aoqi@6880 2484 oop_maps);
aoqi@1 2485
aoqi@1 2486 if (is_critical_native) {
aoqi@1 2487 nm->set_lazy_critical_native(true);
aoqi@1 2488 }
aoqi@6880 2489
aoqi@6880 2490 return nm;
aoqi@1 2491
aoqi@1 2492 }
aoqi@1 2493
aoqi@1 2494 #ifdef HAVE_DTRACE_H
aoqi@1 2495 // ---------------------------------------------------------------------------
aoqi@1 2496 // Generate a dtrace nmethod for a given signature. The method takes arguments
aoqi@1 2497 // in the Java compiled code convention, marshals them to the native
aoqi@1 2498 // abi and then leaves nops at the position you would expect to call a native
aoqi@1 2499 // function. When the probe is enabled the nops are replaced with a trap
aoqi@1 2500 // instruction that dtrace inserts and the trace will cause a notification
aoqi@1 2501 // to dtrace.
aoqi@1 2502 //
aoqi@1 2503 // The probes are only able to take primitive types and java/lang/String as
aoqi@1 2504 // arguments. No other java types are allowed. Strings are converted to utf8
aoqi@1 2505 // strings so that from dtrace point of view java strings are converted to C
aoqi@1 2506 // strings. There is an arbitrary fixed limit on the total space that a method
aoqi@1 2507 // can use for converting the strings. (256 chars per string in the signature).
aoqi@1 2508 // So any java string larger then this is truncated.
aoqi@1 2509
aoqi@1 2510 static int fp_offset[ConcreteRegisterImpl::number_of_registers] = { 0 };
aoqi@1 2511 static bool offsets_initialized = false;
aoqi@1 2512
aoqi@1 2513 static VMRegPair reg64_to_VMRegPair(Register r) {
aoqi@1 2514 VMRegPair ret;
aoqi@1 2515 if (wordSize == 8) {
aoqi@1 2516 ret.set2(r->as_VMReg());
aoqi@1 2517 } else {
aoqi@1 2518 ret.set_pair(r->successor()->as_VMReg(), r->as_VMReg());
aoqi@1 2519 }
aoqi@1 2520 return ret;
aoqi@1 2521 }
aoqi@1 2522
aoqi@1 2523
aoqi@6880 2524 nmethod *SharedRuntime::generate_dtrace_nmethod(MacroAssembler *masm,
aoqi@6880 2525 methodHandle method) {
aoqi@1 2526
aoqi@1 2527
aoqi@1 2528 // generate_dtrace_nmethod is guarded by a mutex so we are sure to
aoqi@1 2529 // be single threaded in this method.
aoqi@1 2530 assert(AdapterHandlerLibrary_lock->owned_by_self(), "must be");
aoqi@1 2531
aoqi@1 2532 // Fill in the signature array, for the calling-convention call.
aoqi@1 2533 int total_args_passed = method->size_of_parameters();
aoqi@1 2534
aoqi@1 2535 BasicType* in_sig_bt = NEW_RESOURCE_ARRAY(BasicType, total_args_passed);
aoqi@1 2536 VMRegPair *in_regs = NEW_RESOURCE_ARRAY(VMRegPair, total_args_passed);
aoqi@1 2537
aoqi@1 2538 // The signature we are going to use for the trap that dtrace will see
aoqi@1 2539 // java/lang/String is converted. We drop "this" and any other object
aoqi@1 2540 // is converted to NULL. (A one-slot java/lang/Long object reference
aoqi@1 2541 // is converted to a two-slot long, which is why we double the allocation).
aoqi@1 2542 BasicType* out_sig_bt = NEW_RESOURCE_ARRAY(BasicType, total_args_passed * 2);
aoqi@1 2543 VMRegPair* out_regs = NEW_RESOURCE_ARRAY(VMRegPair, total_args_passed * 2);
aoqi@1 2544
aoqi@1 2545 int i=0;
aoqi@1 2546 int total_strings = 0;
aoqi@1 2547 int first_arg_to_pass = 0;
aoqi@1 2548 int total_c_args = 0;
aoqi@1 2549
aoqi@1 2550 // Skip the receiver as dtrace doesn't want to see it
aoqi@1 2551 if( !method->is_static() ) {
aoqi@1 2552 in_sig_bt[i++] = T_OBJECT;
aoqi@1 2553 first_arg_to_pass = 1;
aoqi@1 2554 }
aoqi@1 2555
aoqi@1 2556 SignatureStream ss(method->signature());
aoqi@1 2557 for ( ; !ss.at_return_type(); ss.next()) {
aoqi@1 2558 BasicType bt = ss.type();
aoqi@1 2559 in_sig_bt[i++] = bt; // Collect remaining bits of signature
aoqi@1 2560 out_sig_bt[total_c_args++] = bt;
aoqi@1 2561 if( bt == T_OBJECT) {
aoqi@1 2562 symbolOop s = ss.as_symbol_or_null();
aoqi@1 2563 if (s == vmSymbols::java_lang_String()) {
aoqi@1 2564 total_strings++;
aoqi@1 2565 out_sig_bt[total_c_args-1] = T_ADDRESS;
aoqi@1 2566 } else if (s == vmSymbols::java_lang_Boolean() ||
aoqi@1 2567 s == vmSymbols::java_lang_Byte()) {
aoqi@1 2568 out_sig_bt[total_c_args-1] = T_BYTE;
aoqi@1 2569 } else if (s == vmSymbols::java_lang_Character() ||
aoqi@1 2570 s == vmSymbols::java_lang_Short()) {
aoqi@1 2571 out_sig_bt[total_c_args-1] = T_SHORT;
aoqi@1 2572 } else if (s == vmSymbols::java_lang_Integer() ||
aoqi@1 2573 s == vmSymbols::java_lang_Float()) {
aoqi@1 2574 out_sig_bt[total_c_args-1] = T_INT;
aoqi@1 2575 } else if (s == vmSymbols::java_lang_Long() ||
aoqi@1 2576 s == vmSymbols::java_lang_Double()) {
aoqi@1 2577 out_sig_bt[total_c_args-1] = T_LONG;
aoqi@1 2578 out_sig_bt[total_c_args++] = T_VOID;
aoqi@1 2579 }
aoqi@1 2580 } else if ( bt == T_LONG || bt == T_DOUBLE ) {
aoqi@1 2581 in_sig_bt[i++] = T_VOID; // Longs & doubles take 2 Java slots
aoqi@1 2582 // We convert double to long
aoqi@1 2583 out_sig_bt[total_c_args-1] = T_LONG;
aoqi@1 2584 out_sig_bt[total_c_args++] = T_VOID;
aoqi@1 2585 } else if ( bt == T_FLOAT) {
aoqi@1 2586 // We convert float to int
aoqi@1 2587 out_sig_bt[total_c_args-1] = T_INT;
aoqi@1 2588 }
aoqi@1 2589 }
aoqi@1 2590
aoqi@1 2591 assert(i==total_args_passed, "validly parsed signature");
aoqi@1 2592
aoqi@1 2593 // Now get the compiled-Java layout as input arguments
aoqi@1 2594 int comp_args_on_stack;
aoqi@1 2595 comp_args_on_stack = SharedRuntime::java_calling_convention(
aoqi@1 2596 in_sig_bt, in_regs, total_args_passed, false);
aoqi@1 2597
aoqi@1 2598 // We have received a description of where all the java arg are located
aoqi@1 2599 // on entry to the wrapper. We need to convert these args to where
aoqi@1 2600 // the a native (non-jni) function would expect them. To figure out
aoqi@1 2601 // where they go we convert the java signature to a C signature and remove
aoqi@1 2602 // T_VOID for any long/double we might have received.
aoqi@1 2603
aoqi@1 2604
aoqi@1 2605 // Now figure out where the args must be stored and how much stack space
aoqi@1 2606 // they require (neglecting out_preserve_stack_slots but space for storing
aoqi@1 2607 // the 1st six register arguments). It's weird see int_stk_helper.
aoqi@6880 2608
aoqi@1 2609 int out_arg_slots;
aoqi@1 2610 out_arg_slots = c_calling_convention(out_sig_bt, out_regs, NULL, total_c_args);
aoqi@1 2611
aoqi@1 2612 // Calculate the total number of stack slots we will need.
aoqi@1 2613
aoqi@1 2614 // First count the abi requirement plus all of the outgoing args
aoqi@1 2615 int stack_slots = SharedRuntime::out_preserve_stack_slots() + out_arg_slots;
aoqi@1 2616
aoqi@1 2617 // Plus a temp for possible converion of float/double/long register args
aoqi@1 2618
aoqi@1 2619 int conversion_temp = stack_slots;
aoqi@1 2620 stack_slots += 2;
aoqi@1 2621
aoqi@1 2622
aoqi@1 2623 // Now space for the string(s) we must convert
aoqi@1 2624
aoqi@1 2625 int string_locs = stack_slots;
aoqi@1 2626 stack_slots += total_strings *
aoqi@1 2627 (max_dtrace_string_size / VMRegImpl::stack_slot_size);
aoqi@1 2628
aoqi@1 2629 // Ok The space we have allocated will look like:
aoqi@1 2630 //
aoqi@1 2631 //
aoqi@1 2632 // FP-> | |
aoqi@1 2633 // |---------------------|
aoqi@1 2634 // | string[n] |
aoqi@1 2635 // |---------------------| <- string_locs[n]
aoqi@1 2636 // | string[n-1] |
aoqi@1 2637 // |---------------------| <- string_locs[n-1]
aoqi@1 2638 // | ... |
aoqi@1 2639 // | ... |
aoqi@1 2640 // |---------------------| <- string_locs[1]
aoqi@1 2641 // | string[0] |
aoqi@1 2642 // |---------------------| <- string_locs[0]
aoqi@1 2643 // | temp |
aoqi@1 2644 // |---------------------| <- conversion_temp
aoqi@1 2645 // | outbound memory |
aoqi@1 2646 // | based arguments |
aoqi@1 2647 // | |
aoqi@1 2648 // |---------------------|
aoqi@1 2649 // | |
aoqi@1 2650 // SP-> | out_preserved_slots |
aoqi@1 2651 //
aoqi@1 2652 //
aoqi@1 2653
aoqi@1 2654 // Now compute actual number of stack words we need rounding to make
aoqi@1 2655 // stack properly aligned.
aoqi@1 2656 stack_slots = round_to(stack_slots, 4 * VMRegImpl::slots_per_word);
aoqi@1 2657
aoqi@1 2658 int stack_size = stack_slots * VMRegImpl::stack_slot_size;
aoqi@1 2659
aoqi@1 2660 intptr_t start = (intptr_t)__ pc();
aoqi@1 2661
aoqi@1 2662 // First thing make an ic check to see if we should even be here
aoqi@1 2663
aoqi@1 2664 {
aoqi@1 2665 Label L;
aoqi@1 2666 const Register temp_reg = G3_scratch;
aoqi@1 2667 Address ic_miss(temp_reg, SharedRuntime::get_ic_miss_stub());
aoqi@1 2668 __ verify_oop(O0);
aoqi@1 2669 __ ld_ptr(O0, oopDesc::klass_offset_in_bytes(), temp_reg);
aoqi@1 2670 __ cmp(temp_reg, G5_inline_cache_reg);
aoqi@1 2671 __ brx(Assembler::equal, true, Assembler::pt, L);
aoqi@1 2672 __ delayed()->nop();
aoqi@1 2673
aoqi@1 2674 __ jump_to(ic_miss, 0);
aoqi@1 2675 __ delayed()->nop();
aoqi@1 2676 __ align(CodeEntryAlignment);
aoqi@1 2677 __ bind(L);
aoqi@1 2678 }
aoqi@1 2679
aoqi@1 2680 int vep_offset = ((intptr_t)__ pc()) - start;
aoqi@1 2681
aoqi@1 2682
aoqi@1 2683 // The instruction at the verified entry point must be 5 bytes or longer
aoqi@1 2684 // because it can be patched on the fly by make_non_entrant. The stack bang
aoqi@1 2685 // instruction fits that requirement.
aoqi@1 2686
aoqi@1 2687 // Generate stack overflow check before creating frame
aoqi@1 2688 __ generate_stack_overflow_check(stack_size);
aoqi@1 2689
aoqi@1 2690 assert(((intptr_t)__ pc() - start - vep_offset) >= 5,
aoqi@1 2691 "valid size for make_non_entrant");
aoqi@1 2692
aoqi@1 2693 // Generate a new frame for the wrapper.
aoqi@1 2694 __ save(SP, -stack_size, SP);
aoqi@1 2695
aoqi@1 2696 // Frame is now completed as far a size and linkage.
aoqi@1 2697
aoqi@1 2698 int frame_complete = ((intptr_t)__ pc()) - start;
aoqi@1 2699
aoqi@1 2700 #ifdef ASSERT
aoqi@1 2701 bool reg_destroyed[RegisterImpl::number_of_registers];
aoqi@1 2702 bool freg_destroyed[FloatRegisterImpl::number_of_registers];
aoqi@1 2703 for ( int r = 0 ; r < RegisterImpl::number_of_registers ; r++ ) {
aoqi@1 2704 reg_destroyed[r] = false;
aoqi@1 2705 }
aoqi@1 2706 for ( int f = 0 ; f < FloatRegisterImpl::number_of_registers ; f++ ) {
aoqi@1 2707 freg_destroyed[f] = false;
aoqi@1 2708 }
aoqi@1 2709
aoqi@1 2710 #endif /* ASSERT */
aoqi@1 2711
aoqi@1 2712 VMRegPair zero;
aoqi@1 2713 const Register g0 = G0; // without this we get a compiler warning (why??)
aoqi@1 2714 zero.set2(g0->as_VMReg());
aoqi@1 2715
aoqi@1 2716 int c_arg, j_arg;
aoqi@1 2717
aoqi@1 2718 Register conversion_off = noreg;
aoqi@1 2719
aoqi@1 2720 for (j_arg = first_arg_to_pass, c_arg = 0 ;
aoqi@1 2721 j_arg < total_args_passed ; j_arg++, c_arg++ ) {
aoqi@1 2722
aoqi@1 2723 VMRegPair src = in_regs[j_arg];
aoqi@1 2724 VMRegPair dst = out_regs[c_arg];
aoqi@1 2725
aoqi@1 2726 #ifdef ASSERT
aoqi@1 2727 if (src.first()->is_Register()) {
aoqi@1 2728 assert(!reg_destroyed[src.first()->as_Register()->encoding()], "ack!");
aoqi@1 2729 } else if (src.first()->is_FloatRegister()) {
aoqi@1 2730 assert(!freg_destroyed[src.first()->as_FloatRegister()->encoding(
aoqi@1 2731 FloatRegisterImpl::S)], "ack!");
aoqi@1 2732 }
aoqi@1 2733 if (dst.first()->is_Register()) {
aoqi@1 2734 reg_destroyed[dst.first()->as_Register()->encoding()] = true;
aoqi@1 2735 } else if (dst.first()->is_FloatRegister()) {
aoqi@1 2736 freg_destroyed[dst.first()->as_FloatRegister()->encoding(
aoqi@1 2737 FloatRegisterImpl::S)] = true;
aoqi@1 2738 }
aoqi@1 2739 #endif /* ASSERT */
aoqi@1 2740
aoqi@1 2741 switch (in_sig_bt[j_arg]) {
aoqi@1 2742 case T_ARRAY:
aoqi@1 2743 case T_OBJECT:
aoqi@1 2744 {
aoqi@1 2745 if (out_sig_bt[c_arg] == T_BYTE || out_sig_bt[c_arg] == T_SHORT ||
aoqi@1 2746 out_sig_bt[c_arg] == T_INT || out_sig_bt[c_arg] == T_LONG) {
aoqi@1 2747 // need to unbox a one-slot value
aoqi@1 2748 Register in_reg = L0;
aoqi@1 2749 Register tmp = L2;
aoqi@1 2750 if ( src.first()->is_reg() ) {
aoqi@1 2751 in_reg = src.first()->as_Register();
aoqi@1 2752 } else {
aoqi@1 2753 assert(Assembler::is_simm13(reg2offset(src.first()) + STACK_BIAS),
aoqi@1 2754 "must be");
aoqi@1 2755 __ ld_ptr(FP, reg2offset(src.first()) + STACK_BIAS, in_reg);
aoqi@1 2756 }
aoqi@1 2757 // If the final destination is an acceptable register
aoqi@1 2758 if ( dst.first()->is_reg() ) {
aoqi@1 2759 if ( dst.is_single_phys_reg() || out_sig_bt[c_arg] != T_LONG ) {
aoqi@1 2760 tmp = dst.first()->as_Register();
aoqi@1 2761 }
aoqi@1 2762 }
aoqi@1 2763
aoqi@1 2764 Label skipUnbox;
aoqi@1 2765 if ( wordSize == 4 && out_sig_bt[c_arg] == T_LONG ) {
aoqi@1 2766 __ mov(G0, tmp->successor());
aoqi@1 2767 }
aoqi@1 2768 __ br_null(in_reg, true, Assembler::pn, skipUnbox);
aoqi@1 2769 __ delayed()->mov(G0, tmp);
aoqi@1 2770
aoqi@1 2771 BasicType bt = out_sig_bt[c_arg];
aoqi@1 2772 int box_offset = java_lang_boxing_object::value_offset_in_bytes(bt);
aoqi@1 2773 switch (bt) {
aoqi@1 2774 case T_BYTE:
aoqi@1 2775 __ ldub(in_reg, box_offset, tmp); break;
aoqi@1 2776 case T_SHORT:
aoqi@1 2777 __ lduh(in_reg, box_offset, tmp); break;
aoqi@1 2778 case T_INT:
aoqi@1 2779 __ ld(in_reg, box_offset, tmp); break;
aoqi@1 2780 case T_LONG:
aoqi@1 2781 __ ld_long(in_reg, box_offset, tmp); break;
aoqi@1 2782 default: ShouldNotReachHere();
aoqi@1 2783 }
aoqi@1 2784
aoqi@1 2785 __ bind(skipUnbox);
aoqi@1 2786 // If tmp wasn't final destination copy to final destination
aoqi@1 2787 if (tmp == L2) {
aoqi@1 2788 VMRegPair tmp_as_VM = reg64_to_VMRegPair(L2);
aoqi@1 2789 if (out_sig_bt[c_arg] == T_LONG) {
aoqi@1 2790 long_move(masm, tmp_as_VM, dst);
aoqi@1 2791 } else {
aoqi@1 2792 move32_64(masm, tmp_as_VM, out_regs[c_arg]);
aoqi@1 2793 }
aoqi@1 2794 }
aoqi@1 2795 if (out_sig_bt[c_arg] == T_LONG) {
aoqi@1 2796 assert(out_sig_bt[c_arg+1] == T_VOID, "must be");
aoqi@1 2797 ++c_arg; // move over the T_VOID to keep the loop indices in sync
aoqi@1 2798 }
aoqi@1 2799 } else if (out_sig_bt[c_arg] == T_ADDRESS) {
aoqi@1 2800 Register s =
aoqi@1 2801 src.first()->is_reg() ? src.first()->as_Register() : L2;
aoqi@1 2802 Register d =
aoqi@1 2803 dst.first()->is_reg() ? dst.first()->as_Register() : L2;
aoqi@1 2804
aoqi@1 2805 // We store the oop now so that the conversion pass can reach
aoqi@1 2806 // while in the inner frame. This will be the only store if
aoqi@1 2807 // the oop is NULL.
aoqi@1 2808 if (s != L2) {
aoqi@1 2809 // src is register
aoqi@1 2810 if (d != L2) {
aoqi@1 2811 // dst is register
aoqi@1 2812 __ mov(s, d);
aoqi@1 2813 } else {
aoqi@1 2814 assert(Assembler::is_simm13(reg2offset(dst.first()) +
aoqi@1 2815 STACK_BIAS), "must be");
aoqi@1 2816 __ st_ptr(s, SP, reg2offset(dst.first()) + STACK_BIAS);
aoqi@1 2817 }
aoqi@1 2818 } else {
aoqi@1 2819 // src not a register
aoqi@1 2820 assert(Assembler::is_simm13(reg2offset(src.first()) +
aoqi@1 2821 STACK_BIAS), "must be");
aoqi@1 2822 __ ld_ptr(FP, reg2offset(src.first()) + STACK_BIAS, d);
aoqi@1 2823 if (d == L2) {
aoqi@1 2824 assert(Assembler::is_simm13(reg2offset(dst.first()) +
aoqi@1 2825 STACK_BIAS), "must be");
aoqi@1 2826 __ st_ptr(d, SP, reg2offset(dst.first()) + STACK_BIAS);
aoqi@1 2827 }
aoqi@1 2828 }
aoqi@1 2829 } else if (out_sig_bt[c_arg] != T_VOID) {
aoqi@1 2830 // Convert the arg to NULL
aoqi@1 2831 if (dst.first()->is_reg()) {
aoqi@1 2832 __ mov(G0, dst.first()->as_Register());
aoqi@1 2833 } else {
aoqi@1 2834 assert(Assembler::is_simm13(reg2offset(dst.first()) +
aoqi@1 2835 STACK_BIAS), "must be");
aoqi@1 2836 __ st_ptr(G0, SP, reg2offset(dst.first()) + STACK_BIAS);
aoqi@1 2837 }
aoqi@1 2838 }
aoqi@1 2839 }
aoqi@1 2840 break;
aoqi@1 2841 case T_VOID:
aoqi@1 2842 break;
aoqi@1 2843
aoqi@1 2844 case T_FLOAT:
aoqi@1 2845 if (src.first()->is_stack()) {
aoqi@1 2846 // Stack to stack/reg is simple
aoqi@1 2847 move32_64(masm, src, dst);
aoqi@1 2848 } else {
aoqi@1 2849 if (dst.first()->is_reg()) {
aoqi@1 2850 // freg -> reg
aoqi@1 2851 int off =
aoqi@1 2852 STACK_BIAS + conversion_temp * VMRegImpl::stack_slot_size;
aoqi@1 2853 Register d = dst.first()->as_Register();
aoqi@1 2854 if (Assembler::is_simm13(off)) {
aoqi@1 2855 __ stf(FloatRegisterImpl::S, src.first()->as_FloatRegister(),
aoqi@1 2856 SP, off);
aoqi@1 2857 __ ld(SP, off, d);
aoqi@1 2858 } else {
aoqi@1 2859 if (conversion_off == noreg) {
aoqi@1 2860 __ set(off, L6);
aoqi@1 2861 conversion_off = L6;
aoqi@1 2862 }
aoqi@1 2863 __ stf(FloatRegisterImpl::S, src.first()->as_FloatRegister(),
aoqi@1 2864 SP, conversion_off);
aoqi@1 2865 __ ld(SP, conversion_off , d);
aoqi@1 2866 }
aoqi@1 2867 } else {
aoqi@1 2868 // freg -> mem
aoqi@1 2869 int off = STACK_BIAS + reg2offset(dst.first());
aoqi@1 2870 if (Assembler::is_simm13(off)) {
aoqi@1 2871 __ stf(FloatRegisterImpl::S, src.first()->as_FloatRegister(),
aoqi@1 2872 SP, off);
aoqi@1 2873 } else {
aoqi@1 2874 if (conversion_off == noreg) {
aoqi@1 2875 __ set(off, L6);
aoqi@1 2876 conversion_off = L6;
aoqi@1 2877 }
aoqi@1 2878 __ stf(FloatRegisterImpl::S, src.first()->as_FloatRegister(),
aoqi@1 2879 SP, conversion_off);
aoqi@1 2880 }
aoqi@1 2881 }
aoqi@1 2882 }
aoqi@1 2883 break;
aoqi@1 2884
aoqi@1 2885 case T_DOUBLE:
aoqi@1 2886 assert( j_arg + 1 < total_args_passed &&
aoqi@1 2887 in_sig_bt[j_arg + 1] == T_VOID &&
aoqi@1 2888 out_sig_bt[c_arg+1] == T_VOID, "bad arg list");
aoqi@1 2889 if (src.first()->is_stack()) {
aoqi@1 2890 // Stack to stack/reg is simple
aoqi@1 2891 long_move(masm, src, dst);
aoqi@1 2892 } else {
aoqi@1 2893 Register d = dst.first()->is_reg() ? dst.first()->as_Register() : L2;
aoqi@1 2894
aoqi@1 2895 // Destination could be an odd reg on 32bit in which case
aoqi@1 2896 // we can't load direct to the destination.
aoqi@1 2897
aoqi@1 2898 if (!d->is_even() && wordSize == 4) {
aoqi@1 2899 d = L2;
aoqi@1 2900 }
aoqi@1 2901 int off = STACK_BIAS + conversion_temp * VMRegImpl::stack_slot_size;
aoqi@1 2902 if (Assembler::is_simm13(off)) {
aoqi@1 2903 __ stf(FloatRegisterImpl::D, src.first()->as_FloatRegister(),
aoqi@1 2904 SP, off);
aoqi@1 2905 __ ld_long(SP, off, d);
aoqi@1 2906 } else {
aoqi@1 2907 if (conversion_off == noreg) {
aoqi@1 2908 __ set(off, L6);
aoqi@1 2909 conversion_off = L6;
aoqi@1 2910 }
aoqi@1 2911 __ stf(FloatRegisterImpl::D, src.first()->as_FloatRegister(),
aoqi@1 2912 SP, conversion_off);
aoqi@1 2913 __ ld_long(SP, conversion_off, d);
aoqi@1 2914 }
aoqi@1 2915 if (d == L2) {
aoqi@1 2916 long_move(masm, reg64_to_VMRegPair(L2), dst);
aoqi@1 2917 }
aoqi@1 2918 }
aoqi@1 2919 break;
aoqi@1 2920
aoqi@1 2921 case T_LONG :
aoqi@1 2922 // 32bit can't do a split move of something like g1 -> O0, O1
aoqi@1 2923 // so use a memory temp
aoqi@1 2924 if (src.is_single_phys_reg() && wordSize == 4) {
aoqi@1 2925 Register tmp = L2;
aoqi@1 2926 if (dst.first()->is_reg() &&
aoqi@1 2927 (wordSize == 8 || dst.first()->as_Register()->is_even())) {
aoqi@1 2928 tmp = dst.first()->as_Register();
aoqi@1 2929 }
aoqi@1 2930
aoqi@1 2931 int off = STACK_BIAS + conversion_temp * VMRegImpl::stack_slot_size;
aoqi@1 2932 if (Assembler::is_simm13(off)) {
aoqi@1 2933 __ stx(src.first()->as_Register(), SP, off);
aoqi@1 2934 __ ld_long(SP, off, tmp);
aoqi@1 2935 } else {
aoqi@1 2936 if (conversion_off == noreg) {
aoqi@1 2937 __ set(off, L6);
aoqi@1 2938 conversion_off = L6;
aoqi@1 2939 }
aoqi@1 2940 __ stx(src.first()->as_Register(), SP, conversion_off);
aoqi@1 2941 __ ld_long(SP, conversion_off, tmp);
aoqi@1 2942 }
aoqi@1 2943
aoqi@1 2944 if (tmp == L2) {
aoqi@1 2945 long_move(masm, reg64_to_VMRegPair(L2), dst);
aoqi@1 2946 }
aoqi@1 2947 } else {
aoqi@1 2948 long_move(masm, src, dst);
aoqi@1 2949 }
aoqi@1 2950 break;
aoqi@1 2951
aoqi@1 2952 case T_ADDRESS: assert(false, "found T_ADDRESS in java args");
aoqi@1 2953
aoqi@1 2954 default:
aoqi@1 2955 move32_64(masm, src, dst);
aoqi@1 2956 }
aoqi@1 2957 }
aoqi@1 2958
aoqi@1 2959
aoqi@1 2960 // If we have any strings we must store any register based arg to the stack
aoqi@1 2961 // This includes any still live xmm registers too.
aoqi@1 2962
aoqi@1 2963 if (total_strings > 0 ) {
aoqi@1 2964
aoqi@1 2965 // protect all the arg registers
aoqi@1 2966 __ save_frame(0);
aoqi@1 2967 __ mov(G2_thread, L7_thread_cache);
aoqi@1 2968 const Register L2_string_off = L2;
aoqi@1 2969
aoqi@1 2970 // Get first string offset
aoqi@1 2971 __ set(string_locs * VMRegImpl::stack_slot_size, L2_string_off);
aoqi@1 2972
aoqi@1 2973 for (c_arg = 0 ; c_arg < total_c_args ; c_arg++ ) {
aoqi@1 2974 if (out_sig_bt[c_arg] == T_ADDRESS) {
aoqi@1 2975
aoqi@1 2976 VMRegPair dst = out_regs[c_arg];
aoqi@1 2977 const Register d = dst.first()->is_reg() ?
aoqi@1 2978 dst.first()->as_Register()->after_save() : noreg;
aoqi@1 2979
aoqi@1 2980 // It's a string the oop and it was already copied to the out arg
aoqi@1 2981 // position
aoqi@1 2982 if (d != noreg) {
aoqi@1 2983 __ mov(d, O0);
aoqi@1 2984 } else {
aoqi@1 2985 assert(Assembler::is_simm13(reg2offset(dst.first()) + STACK_BIAS),
aoqi@1 2986 "must be");
aoqi@1 2987 __ ld_ptr(FP, reg2offset(dst.first()) + STACK_BIAS, O0);
aoqi@1 2988 }
aoqi@1 2989 Label skip;
aoqi@1 2990
aoqi@1 2991 __ br_null(O0, false, Assembler::pn, skip);
aoqi@1 2992 __ delayed()->add(FP, L2_string_off, O1);
aoqi@1 2993
aoqi@1 2994 if (d != noreg) {
aoqi@1 2995 __ mov(O1, d);
aoqi@1 2996 } else {
aoqi@1 2997 assert(Assembler::is_simm13(reg2offset(dst.first()) + STACK_BIAS),
aoqi@1 2998 "must be");
aoqi@1 2999 __ st_ptr(O1, FP, reg2offset(dst.first()) + STACK_BIAS);
aoqi@1 3000 }
aoqi@1 3001
aoqi@1 3002 __ call(CAST_FROM_FN_PTR(address, SharedRuntime::get_utf),
aoqi@1 3003 relocInfo::runtime_call_type);
aoqi@1 3004 __ delayed()->add(L2_string_off, max_dtrace_string_size, L2_string_off);
aoqi@1 3005
aoqi@1 3006 __ bind(skip);
aoqi@1 3007
aoqi@1 3008 }
aoqi@1 3009
aoqi@1 3010 }
aoqi@1 3011 __ mov(L7_thread_cache, G2_thread);
aoqi@1 3012 __ restore();
aoqi@1 3013
aoqi@1 3014 }
aoqi@1 3015
aoqi@1 3016
aoqi@1 3017 // Ok now we are done. Need to place the nop that dtrace wants in order to
aoqi@1 3018 // patch in the trap
aoqi@1 3019
aoqi@1 3020 int patch_offset = ((intptr_t)__ pc()) - start;
aoqi@1 3021
aoqi@1 3022 __ nop();
aoqi@1 3023
aoqi@1 3024
aoqi@1 3025 // Return
aoqi@1 3026
aoqi@1 3027 __ ret();
aoqi@1 3028 __ delayed()->restore();
aoqi@1 3029
aoqi@1 3030 __ flush();
aoqi@1 3031
aoqi@1 3032 nmethod *nm = nmethod::new_dtrace_nmethod(
aoqi@1 3033 method, masm->code(), vep_offset, patch_offset, frame_complete,
aoqi@1 3034 stack_slots / VMRegImpl::slots_per_word);
aoqi@1 3035 return nm;
aoqi@1 3036
aoqi@1 3037 }
aoqi@1 3038
aoqi@1 3039 #endif // HAVE_DTRACE_H
aoqi@1 3040
aoqi@1 3041 // this function returns the adjust size (in number of words) to a c2i adapter
aoqi@1 3042 // activation for use during deoptimization
aoqi@1 3043 int Deoptimization::last_frame_adjust(int callee_parameters, int callee_locals) {
aoqi@6880 3044 return (callee_locals - callee_parameters) * Interpreter::stackElementWords;
aoqi@1 3045 }
aoqi@1 3046
aoqi@1 3047 // "Top of Stack" slots that may be unused by the calling convention but must
aoqi@1 3048 // otherwise be preserved.
aoqi@1 3049 // On Intel these are not necessary and the value can be zero.
aoqi@1 3050 // On Sparc this describes the words reserved for storing a register window
aoqi@1 3051 // when an interrupt occurs.
aoqi@1 3052 uint SharedRuntime::out_preserve_stack_slots() {
aoqi@1 3053 //return frame::register_save_words * VMRegImpl::slots_per_word;
aoqi@6880 3054 return 0;
aoqi@1 3055 }
aoqi@1 3056
aoqi@1 3057 //------------------------------generate_deopt_blob----------------------------
aoqi@1 3058 // Ought to generate an ideal graph & compile, but here's some SPARC ASM
aoqi@1 3059 // instead.
aoqi@1 3060 void SharedRuntime::generate_deopt_blob() {
aoqi@1 3061 // allocate space for the code
aoqi@1 3062 ResourceMark rm;
aoqi@1 3063 // setup code generation tools
aoqi@1 3064 //CodeBuffer buffer ("deopt_blob", 4000, 2048);
aoqi@1 3065 CodeBuffer buffer ("deopt_blob", 8000, 2048);//aoqi FIXME for debug
aoqi@1 3066 MacroAssembler* masm = new MacroAssembler( & buffer);
aoqi@1 3067 int frame_size_in_words;
aoqi@1 3068 OopMap* map = NULL;
aoqi@1 3069 // Account for the extra args we place on the stack
aoqi@1 3070 // by the time we call fetch_unroll_info
aoqi@1 3071 const int additional_words = 2; // deopt kind, thread
aoqi@1 3072
aoqi@1 3073 OopMapSet *oop_maps = new OopMapSet();
aoqi@1 3074
aoqi@1 3075 address start = __ pc();
aoqi@1 3076 Label cont;
aoqi@1 3077 // we use S3 for DeOpt reason register
aoqi@1 3078 Register reason = S3;
aoqi@1 3079 // use S6 for thread register
aoqi@1 3080 Register thread = TREG;
aoqi@1 3081 // use S7 for fetch_unroll_info returned UnrollBlock
aoqi@1 3082 Register unroll = S7;
aoqi@1 3083 // Prolog for non exception case!
aoqi@1 3084 // Correct the return address we were given.
aoqi@6880 3085 //FIXME, return address is on the tos or Ra?
fujie@375 3086 __ addi(RA, RA, - (NativeCall::return_address_offset_long));
aoqi@1 3087 // Save everything in sight.
aoqi@1 3088 map = RegisterSaver::save_live_registers(masm, additional_words, &frame_size_in_words);
aoqi@1 3089 // Normal deoptimization
aoqi@1 3090 __ move(reason, Deoptimization::Unpack_deopt);
aoqi@1 3091 __ b(cont);
aoqi@1 3092 __ delayed()->nop();
aoqi@1 3093
aoqi@1 3094 int reexecute_offset = __ pc() - start;
aoqi@1 3095
aoqi@6880 3096 // Reexecute case
aoqi@6880 3097 // return address is the pc describes what bci to do re-execute at
aoqi@6880 3098
aoqi@6880 3099 // No need to update map as each call to save_live_registers will produce identical oopmap
aoqi@1 3100 (void) RegisterSaver::save_live_registers(masm, additional_words, &frame_size_in_words);
aoqi@6880 3101 __ move(reason, Deoptimization::Unpack_reexecute);
aoqi@1 3102 __ b(cont);
aoqi@1 3103 __ delayed()->nop();
aoqi@1 3104
aoqi@1 3105 int exception_offset = __ pc() - start;
aoqi@1 3106 // Prolog for exception case
aoqi@1 3107
aoqi@1 3108 // all registers are dead at this entry point, except for eax and
aoqi@1 3109 // edx which contain the exception oop and exception pc
aoqi@1 3110 // respectively. Set them in TLS and fall thru to the
aoqi@1 3111 // unpack_with_exception_in_tls entry point.
aoqi@6880 3112
aoqi@1 3113 __ get_thread(thread);
aoqi@6880 3114 __ st_ptr(V1, thread, in_bytes(JavaThread::exception_pc_offset()));
aoqi@1 3115 __ st_ptr(V0, thread, in_bytes(JavaThread::exception_oop_offset()));
aoqi@1 3116 int exception_in_tls_offset = __ pc() - start;
aoqi@1 3117 // new implementation because exception oop is now passed in JavaThread
aoqi@1 3118
aoqi@1 3119 // Prolog for exception case
aoqi@1 3120 // All registers must be preserved because they might be used by LinearScan
aoqi@1 3121 // Exceptiop oop and throwing PC are passed in JavaThread
aoqi@1 3122 // tos: stack at point of call to method that threw the exception (i.e. only
aoqi@1 3123 // args are on the stack, no return address)
aoqi@1 3124
aoqi@6880 3125 // Return address will be patched later with the throwing pc. The correct value is not
aoqi@1 3126 // available now because loading it from memory would destroy registers.
aoqi@6880 3127 // Save everything in sight.
aoqi@1 3128 // No need to update map as each call to save_live_registers will produce identical oopmap
fujie@375 3129 __ addi(RA, RA, - (NativeCall::return_address_offset_long));
aoqi@1 3130 (void) RegisterSaver::save_live_registers(masm, additional_words, &frame_size_in_words);
aoqi@1 3131
aoqi@1 3132 // Now it is safe to overwrite any register
aoqi@1 3133 // store the correct deoptimization type
aoqi@1 3134 __ move(reason, Deoptimization::Unpack_exception);
aoqi@6880 3135 // load throwing pc from JavaThread and patch it as the return address
aoqi@1 3136 // of the current frame. Then clear the field in JavaThread
aoqi@1 3137 __ get_thread(thread);
aoqi@1 3138 __ ld_ptr(V1, thread, in_bytes(JavaThread::exception_pc_offset()));
aoqi@1 3139 __ st_ptr(V1, SP, RegisterSaver::raOffset() * wordSize); //save ra
aoqi@1 3140 __ st_ptr(R0, thread, in_bytes(JavaThread::exception_pc_offset()));
aoqi@1 3141
aoqi@1 3142
aoqi@1 3143 #ifdef ASSERT
aoqi@1 3144 // verify that there is really an exception oop in JavaThread
aoqi@1 3145 __ ld_ptr(AT, thread, in_bytes(JavaThread::exception_oop_offset()));
aoqi@1 3146 __ verify_oop(AT);
aoqi@1 3147 // verify that there is no pending exception
aoqi@1 3148 Label no_pending_exception;
aoqi@1 3149 __ ld_ptr(AT, thread, in_bytes(Thread::pending_exception_offset()));
aoqi@6880 3150 __ beq(AT, R0, no_pending_exception);
aoqi@6880 3151 __ delayed()->nop();
aoqi@1 3152 __ stop("must not have pending exception here");
aoqi@1 3153 __ bind(no_pending_exception);
aoqi@1 3154 #endif
aoqi@1 3155 __ bind(cont);
aoqi@1 3156 // Compiled code leaves the floating point stack dirty, empty it.
aoqi@1 3157 __ empty_FPU_stack();
aoqi@1 3158
aoqi@1 3159
aoqi@1 3160 // Call C code. Need thread and this frame, but NOT official VM entry
aoqi@6880 3161 // crud. We cannot block on this call, no GC can happen.
aoqi@1 3162 #ifndef OPT_THREAD
aoqi@1 3163 __ get_thread(thread);
aoqi@1 3164 #endif
aoqi@1 3165
aoqi@1 3166 __ move(A0, thread);
aoqi@1 3167 __ addi(SP, SP, -additional_words * wordSize);
aoqi@1 3168
aoqi@1 3169 __ set_last_Java_frame(NOREG, NOREG, NULL);
aoqi@1 3170
aoqi@1 3171 // Call fetch_unroll_info(). Need thread and this frame, but NOT official VM entry - cannot block on
aoqi@1 3172 // this call, no GC can happen. Call should capture return values.
aoqi@1 3173
aoqi@6880 3174 __ relocate(relocInfo::internal_pc_type);
aoqi@6880 3175 {
fujie@373 3176 intptr_t save_pc = (intptr_t)__ pc() + NativeMovConstReg::instruction_size + 28;
fujie@368 3177 __ patchable_set48(AT, save_pc);
aoqi@1 3178 }
aoqi@1 3179 __ sd(AT, thread, in_bytes(JavaThread::frame_anchor_offset() + JavaFrameAnchor::last_Java_pc_offset()));
aoqi@1 3180
aoqi@1 3181 __ call((address)Deoptimization::fetch_unroll_info);
aoqi@1 3182 //__ call(CAST_FROM_FN_PTR(address, Deoptimization::fetch_unroll_info), relocInfo::runtime_call_type);
aoqi@1 3183 __ delayed()->nop();
aoqi@1 3184 oop_maps->add_gc_map(__ pc() - start, map);
aoqi@1 3185 __ addiu(SP, SP, additional_words * wordSize);
aoqi@1 3186 __ get_thread(thread);
aoqi@1 3187 __ reset_last_Java_frame(false, true);
aoqi@1 3188
aoqi@1 3189 // Load UnrollBlock into S7
aoqi@1 3190 __ move(unroll, V0);
aoqi@1 3191
aoqi@1 3192
aoqi@1 3193 // Move the unpack kind to a safe place in the UnrollBlock because
aoqi@1 3194 // we are very short of registers
aoqi@1 3195
aoqi@1 3196 Address unpack_kind(unroll, Deoptimization::UnrollBlock::unpack_kind_offset_in_bytes());
aoqi@1 3197 __ sw(reason, unpack_kind);
aoqi@1 3198 // save the unpack_kind value
aoqi@1 3199 // Retrieve the possible live values (return values)
aoqi@1 3200 // All callee save registers representing jvm state
aoqi@1 3201 // are now in the vframeArray.
aoqi@1 3202
aoqi@1 3203 Label noException;
aoqi@1 3204 __ move(AT, Deoptimization::Unpack_exception);
aoqi@1 3205 __ bne(AT, reason, noException);// Was exception pending?
aoqi@1 3206 __ delayed()->nop();
aoqi@1 3207 __ ld_ptr(V0, thread, in_bytes(JavaThread::exception_oop_offset()));
aoqi@1 3208 __ ld_ptr(V1, thread, in_bytes(JavaThread::exception_pc_offset()));
aoqi@1 3209 __ st_ptr(R0, thread, in_bytes(JavaThread::exception_pc_offset()));
aoqi@1 3210 __ st_ptr(R0, thread, in_bytes(JavaThread::exception_oop_offset()));
aoqi@6880 3211
aoqi@1 3212 __ verify_oop(V0);
aoqi@1 3213
aoqi@1 3214 // Overwrite the result registers with the exception results.
aoqi@6880 3215 __ st_ptr(V0, SP, RegisterSaver::v0Offset()*wordSize);
aoqi@1 3216 __ st_ptr(V1, SP, RegisterSaver::v1Offset()*wordSize);
aoqi@6880 3217
aoqi@1 3218 __ bind(noException);
aoqi@1 3219
aoqi@1 3220
aoqi@1 3221 // Stack is back to only having register save data on the stack.
aoqi@1 3222 // Now restore the result registers. Everything else is either dead or captured
aoqi@1 3223 // in the vframeArray.
aoqi@1 3224
aoqi@1 3225 RegisterSaver::restore_result_registers(masm);
aoqi@1 3226 // All of the register save area has been popped of the stack. Only the
aoqi@1 3227 // return address remains.
aoqi@6880 3228 // Pop all the frames we must move/replace.
aoqi@1 3229 // Frame picture (youngest to oldest)
aoqi@1 3230 // 1: self-frame (no frame link)
aoqi@1 3231 // 2: deopting frame (no frame link)
aoqi@6880 3232 // 3: caller of deopting frame (could be compiled/interpreted).
aoqi@1 3233 //
aoqi@1 3234 // Note: by leaving the return address of self-frame on the stack
aoqi@1 3235 // and using the size of frame 2 to adjust the stack
aoqi@1 3236 // when we are done the return to frame 3 will still be on the stack.
aoqi@1 3237
aoqi@1 3238 // register for the sender's sp
aoqi@1 3239 Register sender_sp = Rsender;
aoqi@1 3240 // register for frame pcs
aoqi@1 3241 Register pcs = T0;
aoqi@1 3242 // register for frame sizes
aoqi@1 3243 Register sizes = T1;
aoqi@1 3244 // register for frame count
aoqi@1 3245 Register count = T3;
aoqi@6880 3246
aoqi@1 3247 // Pop deoptimized frame
aoqi@1 3248 __ lw(AT, unroll, Deoptimization::UnrollBlock::size_of_deoptimized_frame_offset_in_bytes());
aoqi@1 3249 __ add(SP, SP, AT);
aoqi@1 3250 // sp should be pointing at the return address to the caller (3)
aoqi@6880 3251
aoqi@1 3252 // Load array of frame pcs into pcs
aoqi@1 3253 __ ld_ptr(pcs, unroll, Deoptimization::UnrollBlock::frame_pcs_offset_in_bytes());
aoqi@1 3254 __ addi(SP, SP, wordSize); // trash the old pc
aoqi@1 3255 // Load array of frame sizes into T6
aoqi@1 3256 __ ld_ptr(sizes, unroll, Deoptimization::UnrollBlock::frame_sizes_offset_in_bytes());
aoqi@1 3257
aoqi@6880 3258
aoqi@1 3259
aoqi@1 3260 // Load count of frams into T3
aoqi@1 3261 __ lw(count, unroll, Deoptimization::UnrollBlock::number_of_frames_offset_in_bytes());
aoqi@1 3262 // Pick up the initial fp we should save
aoqi@1 3263 __ ld(FP, unroll, Deoptimization::UnrollBlock::initial_info_offset_in_bytes());
aoqi@1 3264 // Now adjust the caller's stack to make up for the extra locals
aoqi@1 3265 // but record the original sp so that we can save it in the skeletal interpreter
aoqi@1 3266 // frame and the stack walking of interpreter_sender will get the unextended sp
aoqi@1 3267 // value and not the "real" sp value.
aoqi@1 3268 __ move(sender_sp, SP);
aoqi@1 3269 __ lw(AT, unroll, Deoptimization::UnrollBlock::caller_adjustment_offset_in_bytes());
aoqi@1 3270 __ sub(SP, SP, AT);
aoqi@1 3271
aoqi@1 3272 // Push interpreter frames in a loop
aoqi@1 3273 /*
aoqi@1 3274 *
aoqi@1 3275 Loop:
aoqi@6880 3276 0x000000555bd82d18: lw t2, 0x0(t1) ; lw sizes[i] <--- error lw->ld
aoqi@1 3277 0x000000555bd82d1c: ld at, 0x0(t0) ; ld pcs[i]
aoqi@6880 3278 0x000000555bd82d20: daddi t2, t2, 0xfffffff0 ; t2 -= 16
aoqi@1 3279 0x000000555bd82d24: daddi sp, sp, 0xfffffff0
aoqi@1 3280 0x000000555bd82d28: sd fp, 0x0(sp) ; push fp
aoqi@1 3281 0x000000555bd82d2c: sd at, 0x8(sp) ; push at
aoqi@6880 3282 0x000000555bd82d30: dadd fp, sp, zero ; fp <- sp
aoqi@6880 3283 0x000000555bd82d34: dsub sp, sp, t2 ; sp -= t2
aoqi@1 3284 0x000000555bd82d38: sd zero, 0xfffffff0(fp) ; __ sd(R0, FP, frame::interpreter_frame_last_sp_offset * wordSize);
aoqi@1 3285 0x000000555bd82d3c: sd s4, 0xfffffff8(fp) ; __ sd(sender_sp, FP, frame::interpreter_frame_sender_sp_offset * wordSize);
aoqi@1 3286 0x000000555bd82d40: dadd s4, sp, zero ; move(sender_sp, SP);
aoqi@1 3287 0x000000555bd82d44: daddi t3, t3, 0xffffffff ; count --
aoqi@1 3288 0x000000555bd82d48: daddi t1, t1, 0x4 ; sizes += 4
aoqi@1 3289 0x000000555bd82d4c: bne t3, zero, 0x000000555bd82d18
aoqi@1 3290 0x000000555bd82d50: daddi t0, t0, 0x4 ; <--- error t0 += 8
aoqi@1 3291 */
aoqi@1 3292
aoqi@1 3293 // pcs[0] = frame_pcs[0] = deopt_sender.raw_pc(); regex.split
aoqi@1 3294 Label loop;
aoqi@1 3295 __ bind(loop);
aoqi@6880 3296 __ ld(T2, sizes, 0); // Load frame size
aoqi@6880 3297 __ ld_ptr(AT, pcs, 0); // save return address
aoqi@1 3298 __ addi(T2, T2, -2*wordSize); // we'll push pc and rbp, by hand
aoqi@6880 3299 __ push2(AT, FP);
aoqi@1 3300 __ move(FP, SP);
aoqi@6880 3301 __ sub(SP, SP, T2); // Prolog!
aoqi@1 3302 // This value is corrected by layout_activation_impl
aoqi@6880 3303 __ sd(R0, FP, frame::interpreter_frame_last_sp_offset * wordSize);
aoqi@1 3304 __ sd(sender_sp, FP, frame::interpreter_frame_sender_sp_offset * wordSize);// Make it walkable
aoqi@6880 3305 __ move(sender_sp, SP); // pass to next frame
aoqi@6880 3306 __ addi(count, count, -1); // decrement counter
aoqi@6880 3307 __ addi(sizes, sizes, wordSize); // Bump array pointer (sizes)
aoqi@1 3308 __ bne(count, R0, loop);
aoqi@6880 3309 __ delayed()->addi(pcs, pcs, wordSize); // Bump array pointer (pcs)
aoqi@6880 3310 __ ld(AT, pcs, 0); // frame_pcs[number_of_frames] = Interpreter::deopt_entry(vtos, 0);
aoqi@1 3311 // Re-push self-frame
aoqi@6880 3312 __ push2(AT, FP);
aoqi@1 3313 __ move(FP, SP);
aoqi@6880 3314 __ sd(R0, FP, frame::interpreter_frame_last_sp_offset * wordSize);
aoqi@6880 3315 __ sd(sender_sp, FP, frame::interpreter_frame_sender_sp_offset * wordSize);
aoqi@1 3316 __ addi(SP, SP, -(frame_size_in_words - 2 - additional_words) * wordSize);
aoqi@1 3317
aoqi@1 3318 // Restore frame locals after moving the frame
aoqi@1 3319 __ sd(V0, SP, RegisterSaver::v0Offset() * wordSize);
aoqi@1 3320 __ sd(V1, SP, RegisterSaver::v1Offset() * wordSize);
aoqi@1 3321 __ sdc1(F0, SP, RegisterSaver::fpResultOffset()* wordSize);// Pop float stack and store in local
aoqi@1 3322 __ sdc1(F1, SP, (RegisterSaver::fpResultOffset() + 1) * wordSize);
aoqi@1 3323
aoqi@6880 3324
aoqi@1 3325 // Call unpack_frames(). Need thread and this frame, but NOT official VM entry - cannot block on
aoqi@1 3326 // this call, no GC can happen.
aoqi@6880 3327 __ move(A1, reason); // exec_mode
aoqi@1 3328 __ get_thread(thread);
aoqi@6880 3329 __ move(A0, thread); // thread
aoqi@1 3330 __ addi(SP, SP, (-additional_words) *wordSize);
aoqi@1 3331
aoqi@1 3332 // set last_Java_sp, last_Java_fp
aoqi@1 3333 __ set_last_Java_frame(NOREG, FP, NULL);
aoqi@1 3334
aoqi@1 3335 __ move(AT, -(StackAlignmentInBytes));
aoqi@1 3336 __ andr(SP, SP, AT); // Fix stack alignment as required by ABI
aoqi@1 3337
aoqi@6880 3338 __ relocate(relocInfo::internal_pc_type);
aoqi@6880 3339 {
fujie@373 3340 intptr_t save_pc = (intptr_t)__ pc() + NativeMovConstReg::instruction_size + 28;
fujie@368 3341 __ patchable_set48(AT, save_pc);
aoqi@1 3342 }
aoqi@1 3343 __ sd(AT, thread, in_bytes(JavaThread::frame_anchor_offset() + JavaFrameAnchor::last_Java_pc_offset()));
aoqi@6880 3344
aoqi@1 3345 __ call(CAST_FROM_FN_PTR(address, Deoptimization::unpack_frames), relocInfo::runtime_call_type);
aoqi@1 3346 __ delayed()->nop();
aoqi@1 3347 // Revert SP alignment after call since we're going to do some SP relative addressing below
aoqi@1 3348 __ ld(SP, thread, in_bytes(JavaThread::last_Java_sp_offset()));
aoqi@1 3349 // Set an oopmap for the call site
aoqi@1 3350 oop_maps->add_gc_map(__ offset(), new OopMap( frame_size_in_words , 0));
aoqi@1 3351
aoqi@1 3352 __ push(V0);
aoqi@6880 3353
aoqi@1 3354 __ get_thread(thread);
chenhaoxuan@361 3355 __ reset_last_Java_frame(true, true);
aoqi@1 3356
aoqi@1 3357 // Collect return values
aoqi@1 3358 __ ld(V0, SP, (RegisterSaver::v0Offset() + additional_words +1) * wordSize);
aoqi@1 3359 __ ld(V1, SP, (RegisterSaver::v1Offset() + additional_words +1) * wordSize);
aoqi@1 3360 __ ldc1(F0, SP, RegisterSaver::fpResultOffset()* wordSize);// Pop float stack and store in local
aoqi@1 3361 __ ldc1(F1, SP, (RegisterSaver::fpResultOffset() + 1) * wordSize);
aoqi@6880 3362 //FIXME,
aoqi@1 3363 // Clear floating point stack before returning to interpreter
aoqi@1 3364 __ empty_FPU_stack();
aoqi@1 3365 //FIXME, we should consider about float and double
aoqi@1 3366 // Push a float or double return value if necessary.
aoqi@1 3367 __ leave();
aoqi@1 3368
aoqi@1 3369 // Jump to interpreter
aoqi@1 3370 __ jr(RA);
aoqi@1 3371 __ delayed()->nop();
aoqi@1 3372
aoqi@1 3373 masm->flush();
aoqi@1 3374 _deopt_blob = DeoptimizationBlob::create(&buffer, oop_maps, 0, exception_offset, reexecute_offset, frame_size_in_words);
aoqi@1 3375 _deopt_blob->set_unpack_with_exception_in_tls_offset(exception_in_tls_offset);
aoqi@1 3376 }
aoqi@1 3377
aoqi@1 3378 #ifdef COMPILER2
aoqi@1 3379
aoqi@1 3380 //------------------------------generate_uncommon_trap_blob--------------------
aoqi@1 3381 // Ought to generate an ideal graph & compile, but here's some SPARC ASM
aoqi@1 3382 // instead.
aoqi@1 3383 void SharedRuntime::generate_uncommon_trap_blob() {
aoqi@1 3384 // allocate space for the code
aoqi@1 3385 ResourceMark rm;
aoqi@1 3386 // setup code generation tools
aoqi@6880 3387 CodeBuffer buffer ("uncommon_trap_blob", 512*80 , 512*40 );
aoqi@6880 3388 MacroAssembler* masm = new MacroAssembler(&buffer);
aoqi@1 3389
aoqi@1 3390 enum frame_layout {
aoqi@6880 3391 s0_off, s0_off2,
aoqi@6880 3392 s1_off, s1_off2,
aoqi@6880 3393 s2_off, s2_off2,
aoqi@6880 3394 s3_off, s3_off2,
aoqi@6880 3395 s4_off, s4_off2,
aoqi@6880 3396 s5_off, s5_off2,
aoqi@6880 3397 s6_off, s6_off2,
aoqi@6880 3398 s7_off, s7_off2,
aoqi@6880 3399 fp_off, fp_off2,
aoqi@6880 3400 return_off, return_off2, // slot for return address sp + 9
aoqi@1 3401 framesize
aoqi@1 3402 };
aoqi@1 3403 assert(framesize % 4 == 0, "sp not 16-byte aligned");
aoqi@1 3404
aoqi@1 3405 address start = __ pc();
aoqi@1 3406
aoqi@1 3407 // Push self-frame.
aoqi@1 3408 __ daddiu(SP, SP, -framesize * BytesPerInt);
aoqi@1 3409
aoqi@1 3410 __ sd(RA, SP, return_off * BytesPerInt);
aoqi@1 3411 __ sd(FP, SP, fp_off * BytesPerInt);
aoqi@1 3412
aoqi@6880 3413 // Save callee saved registers. None for UseSSE=0,
aoqi@1 3414 // floats-only for UseSSE=1, and doubles for UseSSE=2.
aoqi@1 3415 __ sd(S0, SP, s0_off * BytesPerInt);
aoqi@1 3416 __ sd(S1, SP, s1_off * BytesPerInt);
aoqi@1 3417 __ sd(S2, SP, s2_off * BytesPerInt);
aoqi@1 3418 __ sd(S3, SP, s3_off * BytesPerInt);
aoqi@1 3419 __ sd(S4, SP, s4_off * BytesPerInt);
aoqi@1 3420 __ sd(S5, SP, s5_off * BytesPerInt);
aoqi@1 3421 __ sd(S6, SP, s6_off * BytesPerInt);
aoqi@1 3422 __ sd(S7, SP, s7_off * BytesPerInt);
aoqi@1 3423
aoqi@1 3424 __ daddi(FP, SP, fp_off * BytesPerInt);
aoqi@1 3425
aoqi@1 3426 // Clear the floating point exception stack
aoqi@1 3427 __ empty_FPU_stack();
aoqi@1 3428
aoqi@1 3429 Register thread = TREG;
aoqi@1 3430
aoqi@1 3431 #ifndef OPT_THREAD
aoqi@1 3432 __ get_thread(thread);
aoqi@1 3433 #endif
aoqi@1 3434 // set last_Java_sp
aoqi@1 3435 __ set_last_Java_frame(NOREG, FP, NULL);
aoqi@6880 3436 __ relocate(relocInfo::internal_pc_type);
aoqi@6880 3437 {
fujie@373 3438 long save_pc = (long)__ pc() + 52;
fujie@368 3439 __ patchable_set48(AT, (long)save_pc);
aoqi@1 3440 __ sd(AT, thread, in_bytes(JavaThread::frame_anchor_offset() + JavaFrameAnchor::last_Java_pc_offset()));
aoqi@1 3441 }
aoqi@1 3442 // Call C code. Need thread but NOT official VM entry
aoqi@1 3443 // crud. We cannot block on this call, no GC can happen. Call should
aoqi@1 3444 // capture callee-saved registers as well as return values.
aoqi@1 3445 __ move(A0, thread);
aoqi@1 3446 // argument already in T0
aoqi@1 3447 __ move(A1, T0);
fujie@386 3448 __ patchable_call((address)Deoptimization::uncommon_trap);
aoqi@1 3449
aoqi@1 3450 // Set an oopmap for the call site
aoqi@1 3451 OopMapSet *oop_maps = new OopMapSet();
aoqi@1 3452 OopMap* map = new OopMap( framesize, 0 );
aoqi@1 3453
aoqi@6880 3454 map->set_callee_saved( VMRegImpl::stack2reg(s0_off ), S0->as_VMReg() );
aoqi@1 3455 map->set_callee_saved( VMRegImpl::stack2reg(s1_off ), S1->as_VMReg() );
aoqi@1 3456 map->set_callee_saved( VMRegImpl::stack2reg(s2_off ), S2->as_VMReg() );
aoqi@1 3457 map->set_callee_saved( VMRegImpl::stack2reg(s3_off ), S3->as_VMReg() );
aoqi@1 3458 map->set_callee_saved( VMRegImpl::stack2reg(s4_off ), S4->as_VMReg() );
aoqi@1 3459 map->set_callee_saved( VMRegImpl::stack2reg(s5_off ), S5->as_VMReg() );
aoqi@1 3460 map->set_callee_saved( VMRegImpl::stack2reg(s6_off ), S6->as_VMReg() );
aoqi@1 3461 map->set_callee_saved( VMRegImpl::stack2reg(s7_off ), S7->as_VMReg() );
aoqi@1 3462
aoqi@1 3463 //oop_maps->add_gc_map( __ offset(), true, map);
aoqi@6880 3464 oop_maps->add_gc_map( __ offset(), map);
aoqi@1 3465
aoqi@1 3466 #ifndef OPT_THREAD
aoqi@1 3467 __ get_thread(thread);
aoqi@1 3468 #endif
aoqi@1 3469 __ reset_last_Java_frame(false,false);
aoqi@1 3470
aoqi@1 3471 // Load UnrollBlock into S7
aoqi@1 3472 Register unroll = S7;
aoqi@1 3473 __ move(unroll, V0);
aoqi@1 3474
aoqi@6880 3475 // Pop all the frames we must move/replace.
aoqi@6880 3476 //
aoqi@1 3477 // Frame picture (youngest to oldest)
aoqi@1 3478 // 1: self-frame (no frame link)
aoqi@1 3479 // 2: deopting frame (no frame link)
aoqi@6880 3480 // 3: possible-i2c-adapter-frame
aoqi@1 3481 // 4: caller of deopting frame (could be compiled/interpreted. If interpreted we will create an
aoqi@1 3482 // and c2i here)
aoqi@1 3483
aoqi@1 3484 // Pop self-frame. We have no frame, and must rely only on EAX and ESP.
aoqi@1 3485 __ daddiu(SP, SP, framesize * BytesPerInt);
aoqi@1 3486
aoqi@1 3487 // Pop deoptimized frame
aoqi@1 3488 __ lw(AT, unroll, Deoptimization::UnrollBlock::size_of_deoptimized_frame_offset_in_bytes());
aoqi@1 3489 __ dadd(SP, SP, AT);
aoqi@1 3490
aoqi@1 3491 // register for frame pcs
aoqi@1 3492 Register pcs = T8;
aoqi@1 3493 // register for frame sizes
aoqi@1 3494 Register sizes = T9;
aoqi@1 3495 // register for frame count
aoqi@1 3496 Register count = T3;
aoqi@1 3497 // register for the sender's sp
aoqi@1 3498 Register sender_sp = T1;
aoqi@1 3499
aoqi@1 3500 // sp should be pointing at the return address to the caller (4)
aoqi@1 3501 // Load array of frame pcs into ECX
aoqi@1 3502 __ ld(pcs, unroll, Deoptimization::UnrollBlock::frame_pcs_offset_in_bytes());
aoqi@1 3503
aoqi@1 3504 // Load array of frame sizes into ESI
aoqi@1 3505 __ ld(sizes, unroll, Deoptimization::UnrollBlock::frame_sizes_offset_in_bytes());
aoqi@1 3506 __ lwu(count, unroll, Deoptimization::UnrollBlock::number_of_frames_offset_in_bytes());
aoqi@1 3507
aoqi@1 3508 // Pick up the initial fp we should save
aoqi@1 3509 __ ld(FP, unroll, Deoptimization::UnrollBlock::initial_info_offset_in_bytes());
aoqi@1 3510 // Now adjust the caller's stack to make up for the extra locals
aoqi@1 3511 // but record the original sp so that we can save it in the skeletal interpreter
aoqi@1 3512 // frame and the stack walking of interpreter_sender will get the unextended sp
aoqi@1 3513 // value and not the "real" sp value.
aoqi@1 3514
aoqi@1 3515 __ move(sender_sp, SP);
aoqi@1 3516 __ lw(AT, unroll, Deoptimization::UnrollBlock::caller_adjustment_offset_in_bytes());
aoqi@1 3517 __ dsub(SP, SP, AT);
aoqi@1 3518 // Push interpreter frames in a loop
aoqi@1 3519 Label loop;
aoqi@1 3520 __ bind(loop);
aoqi@1 3521 __ ld(T2, sizes, 0); // Load frame size
aoqi@1 3522 __ ld(AT, pcs, 0); // save return address
aoqi@1 3523 __ daddi(T2, T2, -2*wordSize); // we'll push pc and rbp, by hand
aoqi@1 3524 __ push2(AT, FP);
aoqi@1 3525 __ move(FP, SP);
aoqi@1 3526 __ dsub(SP, SP, T2); // Prolog!
aoqi@1 3527 // This value is corrected by layout_activation_impl
aoqi@1 3528 __ sd(R0, FP, frame::interpreter_frame_last_sp_offset * wordSize);
aoqi@1 3529 __ sd(sender_sp, FP, frame::interpreter_frame_sender_sp_offset * wordSize);// Make it walkable
aoqi@1 3530 __ move(sender_sp, SP); // pass to next frame
aoqi@1 3531 __ daddi(count, count, -1); // decrement counter
aoqi@1 3532 __ daddi(sizes, sizes, wordSize); // Bump array pointer (sizes)
aoqi@1 3533 __ addi(pcs, pcs, wordSize); // Bump array pointer (pcs)
aoqi@1 3534 __ bne(count, R0, loop);
aoqi@1 3535 __ delayed()->nop(); // Bump array pointer (pcs)
aoqi@1 3536
aoqi@1 3537 __ ld(RA, pcs, 0);
aoqi@1 3538
aoqi@1 3539 // Re-push self-frame
aoqi@1 3540 __ daddi(SP, SP, - 2 * wordSize); // save old & set new FP
aoqi@1 3541 __ sd(FP, SP, 0 * wordSize); // save final return address
aoqi@1 3542 __ sd(RA, SP, 1 * wordSize);
aoqi@6880 3543 __ move(FP, SP);
aoqi@1 3544 __ daddi(SP, SP, -(framesize / 2 - 2) * wordSize);
aoqi@1 3545
aoqi@1 3546 // set last_Java_sp, last_Java_fp
aoqi@1 3547 __ set_last_Java_frame(NOREG, FP, NULL);
aoqi@1 3548
aoqi@1 3549 __ move(AT, -(StackAlignmentInBytes));
aoqi@1 3550 __ andr(SP, SP, AT); // Fix stack alignment as required by ABI
aoqi@1 3551
aoqi@6880 3552 __ relocate(relocInfo::internal_pc_type);
aoqi@6880 3553 {
fujie@373 3554 long save_pc = (long)__ pc() + 52;
fujie@368 3555 __ patchable_set48(AT, (long)save_pc);
aoqi@1 3556 }
aoqi@1 3557 __ sd(AT, thread,in_bytes(JavaThread::frame_anchor_offset() + JavaFrameAnchor::last_Java_pc_offset()));
aoqi@1 3558
aoqi@1 3559 // Call C code. Need thread but NOT official VM entry
aoqi@1 3560 // crud. We cannot block on this call, no GC can happen. Call should
aoqi@1 3561 // restore return values to their stack-slots with the new SP.
aoqi@1 3562 __ move(A0, thread);
aoqi@1 3563 __ move(A1, Deoptimization::Unpack_uncommon_trap);
fujie@386 3564 __ patchable_call((address)Deoptimization::unpack_frames);
aoqi@1 3565 // Set an oopmap for the call site
aoqi@6880 3566 //oop_maps->add_gc_map( __ offset(), true, new OopMap( framesize, 0 ) );
aoqi@1 3567 oop_maps->add_gc_map( __ offset(), new OopMap( framesize, 0 ) );//Fu
aoqi@1 3568
aoqi@1 3569 __ reset_last_Java_frame(true,true);
aoqi@1 3570
aoqi@1 3571 // Pop self-frame.
aoqi@1 3572 __ leave(); // Epilog!
aoqi@1 3573
aoqi@1 3574 // Jump to interpreter
aoqi@1 3575 __ jr(RA);
aoqi@1 3576 __ delayed()->nop();
aoqi@1 3577 // -------------
aoqi@1 3578 // make sure all code is generated
aoqi@1 3579 masm->flush();
aoqi@1 3580
aoqi@1 3581 _uncommon_trap_blob = UncommonTrapBlob::create(&buffer, oop_maps, framesize / 2);
aoqi@1 3582 }
aoqi@1 3583
aoqi@1 3584 #endif // COMPILER2
aoqi@1 3585
aoqi@1 3586 //------------------------------generate_handler_blob-------------------
aoqi@1 3587 //
aoqi@1 3588 // Generate a special Compile2Runtime blob that saves all registers, and sets
aoqi@1 3589 // up an OopMap and calls safepoint code to stop the compiled code for
aoqi@1 3590 // a safepoint.
aoqi@1 3591 //
aoqi@1 3592 // This blob is jumped to (via a breakpoint and the signal handler) from a
aoqi@6880 3593 // safepoint in compiled code.
aoqi@6880 3594
aoqi@1 3595 SafepointBlob* SharedRuntime::generate_handler_blob(address call_ptr, int pool_type) {
aoqi@1 3596
aoqi@1 3597 // Account for thread arg in our frame
aoqi@6880 3598 const int additional_words = 0;
aoqi@1 3599 int frame_size_in_words;
aoqi@1 3600
aoqi@6880 3601 assert (StubRoutines::forward_exception_entry() != NULL, "must be generated before");
aoqi@1 3602
aoqi@1 3603 ResourceMark rm;
aoqi@1 3604 OopMapSet *oop_maps = new OopMapSet();
aoqi@1 3605 OopMap* map;
aoqi@1 3606
aoqi@1 3607 // allocate space for the code
aoqi@6880 3608 // setup code generation tools
aoqi@1 3609 CodeBuffer buffer ("handler_blob", 2048, 512);
aoqi@1 3610 MacroAssembler* masm = new MacroAssembler( &buffer);
aoqi@6880 3611
aoqi@6880 3612 const Register thread = TREG;
aoqi@6880 3613 address start = __ pc();
aoqi@6880 3614 address call_pc = NULL;
aoqi@1 3615 bool cause_return = (pool_type == POLL_AT_RETURN);
aoqi@1 3616 bool save_vectors = (pool_type == POLL_AT_VECTOR_LOOP);
aoqi@1 3617
aoqi@1 3618 // If cause_return is true we are at a poll_return and there is
aoqi@1 3619 // the return address in RA to the caller on the nmethod
aoqi@1 3620 // that is safepoint. We can leave this return in RA and
aoqi@1 3621 // effectively complete the return and safepoint in the caller.
aoqi@1 3622 // Otherwise we load exception pc to RA.
aoqi@1 3623 __ push(thread);
aoqi@1 3624 #ifndef OPT_THREAD
aoqi@1 3625 __ get_thread(thread);
aoqi@1 3626 #endif
aoqi@1 3627
aoqi@1 3628 if(!cause_return) {
aoqi@1 3629 __ ld_ptr(RA, Address(thread, JavaThread::saved_exception_pc_offset()));
aoqi@1 3630 }
aoqi@6880 3631
aoqi@1 3632 __ pop(thread);
aoqi@1 3633 map = RegisterSaver::save_live_registers(masm, additional_words, &frame_size_in_words, save_vectors);
aoqi@1 3634
aoqi@1 3635 #ifndef OPT_THREAD
aoqi@1 3636 __ get_thread(thread);
aoqi@1 3637 #endif
aoqi@1 3638 // The following is basically a call_VM. However, we need the precise
aoqi@1 3639 // address of the call in order to generate an oopmap. Hence, we do all the
aoqi@1 3640 // work outselvs.
aoqi@1 3641
aoqi@1 3642 __ move(A0, thread);
aoqi@1 3643 __ set_last_Java_frame(NOREG, NOREG, NULL);
aoqi@1 3644
aoqi@1 3645
aoqi@1 3646 // do the call
aoqi@1 3647 //__ lui(T9, Assembler::split_high((int)call_ptr));
aoqi@1 3648 //__ addiu(T9, T9, Assembler::split_low((int)call_ptr));
aoqi@1 3649 __ call(call_ptr);
aoqi@1 3650 __ delayed()->nop();
aoqi@1 3651
aoqi@1 3652 // Set an oopmap for the call site. This oopmap will map all
aoqi@1 3653 // oop-registers and debug-info registers as callee-saved. This
aoqi@1 3654 // will allow deoptimization at this safepoint to find all possible
aoqi@1 3655 // debug-info recordings, as well as let GC find all oops.
aoqi@1 3656 oop_maps->add_gc_map(__ offset(), map);
aoqi@1 3657
aoqi@1 3658 Label noException;
aoqi@1 3659
aoqi@1 3660 // Clear last_Java_sp again
aoqi@1 3661 __ reset_last_Java_frame(false, false);
aoqi@1 3662
aoqi@1 3663 __ ld_ptr(AT, thread, in_bytes(Thread::pending_exception_offset()));
aoqi@1 3664 __ beq(AT, R0, noException);
aoqi@1 3665 __ delayed()->nop();
aoqi@1 3666
aoqi@1 3667 // Exception pending
aoqi@1 3668
aoqi@1 3669 RegisterSaver::restore_live_registers(masm, save_vectors);
aoqi@1 3670 //forward_exception_entry need return address on the stack
aoqi@1 3671 __ push(RA);
fujie@386 3672 __ patchable_jump((address)StubRoutines::forward_exception_entry());
aoqi@1 3673
aoqi@1 3674 // No exception case
aoqi@1 3675 __ bind(noException);
aoqi@6880 3676 // Normal exit, register restoring and exit
aoqi@1 3677 RegisterSaver::restore_live_registers(masm, save_vectors);
aoqi@1 3678 __ jr(RA);
aoqi@1 3679 __ delayed()->nop();
aoqi@6880 3680
aoqi@6880 3681 masm->flush();
aoqi@1 3682
aoqi@1 3683 // Fill-out other meta info
aoqi@6880 3684 return SafepointBlob::create(&buffer, oop_maps, frame_size_in_words);
aoqi@1 3685 }
aoqi@1 3686
aoqi@1 3687 //
aoqi@1 3688 // generate_resolve_blob - call resolution (static/virtual/opt-virtual/ic-miss
aoqi@1 3689 //
aoqi@1 3690 // Generate a stub that calls into vm to find out the proper destination
aoqi@1 3691 // of a java call. All the argument registers are live at this point
aoqi@1 3692 // but since this is generic code we don't know what they are and the caller
aoqi@1 3693 // must do any gc of the args.
aoqi@1 3694 //
aoqi@1 3695 RuntimeStub* SharedRuntime::generate_resolve_blob(address destination, const char* name) {
aoqi@1 3696 assert (StubRoutines::forward_exception_entry() != NULL, "must be generated before");
aoqi@1 3697
aoqi@1 3698 // allocate space for the code
aoqi@1 3699 ResourceMark rm;
aoqi@1 3700
aoqi@1 3701 //CodeBuffer buffer(name, 1000, 512);
aoqi@1 3702 //FIXME. aoqi. code_size
aoqi@8009 3703 CodeBuffer buffer(name, 2000, 2048);
aoqi@1 3704 MacroAssembler* masm = new MacroAssembler(&buffer);
aoqi@1 3705
aoqi@1 3706 int frame_size_words;
aoqi@6880 3707 //we put the thread in A0
aoqi@1 3708
aoqi@1 3709 OopMapSet *oop_maps = new OopMapSet();
aoqi@1 3710 OopMap* map = NULL;
aoqi@1 3711
aoqi@1 3712 int start = __ offset();
aoqi@1 3713 map = RegisterSaver::save_live_registers(masm, 0, &frame_size_words);
aoqi@1 3714
aoqi@1 3715
aoqi@1 3716 int frame_complete = __ offset();
aoqi@1 3717
aoqi@1 3718 const Register thread = T8;
aoqi@1 3719 __ get_thread(thread);
aoqi@1 3720
aoqi@6880 3721 __ move(A0, thread);
aoqi@1 3722 __ set_last_Java_frame(noreg, FP, NULL);
aoqi@6880 3723 //align the stack before invoke native
aoqi@1 3724 __ move(AT, -(StackAlignmentInBytes));
aoqi@6880 3725 __ andr(SP, SP, AT);
aoqi@6880 3726 __ relocate(relocInfo::internal_pc_type);
aoqi@6880 3727 {
fujie@373 3728 intptr_t save_pc = (intptr_t)__ pc() + NativeMovConstReg::instruction_size + 24 + 1 * BytesPerInstWord;
fujie@368 3729 __ patchable_set48(AT, save_pc);
aoqi@1 3730 }
aoqi@1 3731 __ sd(AT, thread, in_bytes(JavaThread::last_Java_pc_offset()));
aoqi@1 3732
aoqi@1 3733 __ call(destination);
aoqi@1 3734 __ delayed()->nop();
aoqi@1 3735
aoqi@1 3736 // Set an oopmap for the call site.
aoqi@1 3737 // We need this not only for callee-saved registers, but also for volatile
aoqi@1 3738 // registers that the compiler might be keeping live across a safepoint.
aoqi@1 3739 oop_maps->add_gc_map( __ offset() - start, map);
aoqi@1 3740 // V0 contains the address we are going to jump to assuming no exception got installed
aoqi@1 3741 __ get_thread(thread);
aoqi@1 3742 __ ld_ptr(SP, thread, in_bytes(JavaThread::last_Java_sp_offset()));
aoqi@1 3743 // clear last_Java_sp
aoqi@1 3744 __ reset_last_Java_frame(true, true);
aoqi@1 3745 // check for pending exceptions
aoqi@1 3746 Label pending;
aoqi@1 3747 __ ld_ptr(AT, thread, in_bytes(Thread::pending_exception_offset()));
aoqi@1 3748 __ bne(AT, R0, pending);
aoqi@6880 3749 __ delayed()->nop();
aoqi@6880 3750 // get the returned Method*
aoqi@6880 3751 //FIXME, do mips need this ?
aoqi@1 3752 __ get_vm_result_2(Rmethod, thread); // Refer to OpenJDK8
aoqi@1 3753 __ st_ptr(Rmethod, SP, RegisterSaver::methodOffset() * wordSize);
aoqi@1 3754 __ st_ptr(V0, SP, RegisterSaver::v0Offset() * wordSize);
aoqi@1 3755 RegisterSaver::restore_live_registers(masm);
aoqi@1 3756
aoqi@1 3757 // We are back the the original state on entry and ready to go the callee method.
aoqi@1 3758 __ jr(V0);
aoqi@1 3759 __ delayed()->nop();
aoqi@1 3760 // Pending exception after the safepoint
aoqi@1 3761
aoqi@1 3762 __ bind(pending);
aoqi@1 3763
aoqi@1 3764 RegisterSaver::restore_live_registers(masm);
aoqi@1 3765
aoqi@1 3766 // exception pending => remove activation and forward to exception handler
aoqi@6880 3767 //forward_exception_entry need return address on the stack
aoqi@1 3768 __ push(RA);
aoqi@1 3769 __ get_thread(thread);
aoqi@6880 3770 __ st_ptr(R0, thread, in_bytes(JavaThread::vm_result_offset()));
aoqi@1 3771 __ ld_ptr(V0, thread, in_bytes(Thread::pending_exception_offset()));
aoqi@1 3772 __ jmp(StubRoutines::forward_exception_entry(), relocInfo::runtime_call_type);
aoqi@1 3773 __ delayed() -> nop();
aoqi@1 3774 // -------------
aoqi@1 3775 // make sure all code is generated
aoqi@6880 3776 masm->flush();
aoqi@1 3777
aoqi@1 3778 RuntimeStub* tmp= RuntimeStub::new_runtime_stub(name, &buffer, frame_complete, frame_size_words, oop_maps, true);
aoqi@1 3779 return tmp;
aoqi@1 3780 }
aoqi@1 3781
aoqi@1 3782 extern "C" int SpinPause() {return 0;}
aoqi@1 3783 // extern "C" int SafeFetch32 (int * adr, int errValue) {return 0;} ;
aoqi@1 3784 // extern "C" intptr_t SafeFetchN (intptr_t * adr, intptr_t errValue) {return *adr; } ;

mercurial