stubGenerator_zero.cpp revision 1010:354d3184f6b2
1/* 2 * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved. 3 * Copyright 2007, 2008 Red Hat, Inc. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 21 * CA 95054 USA or visit www.sun.com if you need additional information or 22 * have any questions. 23 * 24 */ 25 26#include "incls/_precompiled.incl" 27#include "incls/_stubGenerator_zero.cpp.incl" 28 29// Declaration and definition of StubGenerator (no .hpp file). 30// For a more detailed description of the stub routine structure 31// see the comment in stubRoutines.hpp 32 33class StubGenerator: public StubCodeGenerator { 34 private: 35 // The call stub is used to call Java from C 36 static void call_stub( 37 JavaCallWrapper *call_wrapper, 38 intptr_t* result, 39 BasicType result_type, 40 methodOop method, 41 address entry_point, 42 intptr_t* parameters, 43 int parameter_words, 44 TRAPS) { 45 JavaThread *thread = (JavaThread *) THREAD; 46 ZeroStack *stack = thread->zero_stack(); 47 48 // Make sure we have no pending exceptions 49 assert(!HAS_PENDING_EXCEPTION, "call_stub called with pending exception"); 50 51 // Set up the stack if necessary 52 bool stack_needs_teardown = false; 53 if (stack->needs_setup()) { 54 size_t stack_used = thread->stack_base() - (address) &stack_used; 55 size_t stack_free = thread->stack_size() - stack_used; 56 size_t zero_stack_size = align_size_down(stack_free / 2, wordSize); 57 58 stack->setup(alloca(zero_stack_size), zero_stack_size); 59 stack_needs_teardown = true; 60 } 61 62 // Allocate and initialize our frame 63 thread->push_zero_frame( 64 EntryFrame::build(stack, parameters, parameter_words, call_wrapper)); 65 66 // Make the call 67 Interpreter::invoke_method(method, entry_point, THREAD); 68 69 // Store result depending on type 70 if (!HAS_PENDING_EXCEPTION) { 71 switch (result_type) { 72 case T_INT: 73 *(jint *) result = *(jint *) stack->sp(); 74 break; 75 case T_LONG: 76 *(jlong *) result = *(jlong *) stack->sp(); 77 break; 78 case T_FLOAT: 79 *(jfloat *) result = *(jfloat *) stack->sp(); 80 break; 81 case T_DOUBLE: 82 *(jdouble *) result = *(jdouble *) stack->sp(); 83 break; 84 case T_OBJECT: 85 *(oop *) result = *(oop *) stack->sp(); 86 break; 87 default: 88 ShouldNotReachHere(); 89 } 90 } 91 92 // Unwind our frame 93 thread->pop_zero_frame(); 94 95 // Tear down the stack if necessary 96 if (stack_needs_teardown) 97 stack->teardown(); 98 } 99 100 // These stubs get called from some dumb test routine. 101 // I'll write them properly when they're called from 102 // something that's actually doing something. 103 static void fake_arraycopy_stub(address src, address dst, int count) { 104 assert(count == 0, "huh?"); 105 } 106 107 void generate_arraycopy_stubs() { 108 // Call the conjoint generation methods immediately after 109 // the disjoint ones so that short branches from the former 110 // to the latter can be generated. 111 StubRoutines::_jbyte_disjoint_arraycopy = (address) fake_arraycopy_stub; 112 StubRoutines::_jbyte_arraycopy = (address) fake_arraycopy_stub; 113 114 StubRoutines::_jshort_disjoint_arraycopy = (address) fake_arraycopy_stub; 115 StubRoutines::_jshort_arraycopy = (address) fake_arraycopy_stub; 116 117 StubRoutines::_jint_disjoint_arraycopy = (address) fake_arraycopy_stub; 118 StubRoutines::_jint_arraycopy = (address) fake_arraycopy_stub; 119 120 StubRoutines::_jlong_disjoint_arraycopy = (address) fake_arraycopy_stub; 121 StubRoutines::_jlong_arraycopy = (address) fake_arraycopy_stub; 122 123 StubRoutines::_oop_disjoint_arraycopy = ShouldNotCallThisStub(); 124 StubRoutines::_oop_arraycopy = ShouldNotCallThisStub(); 125 126 StubRoutines::_checkcast_arraycopy = ShouldNotCallThisStub(); 127 StubRoutines::_unsafe_arraycopy = ShouldNotCallThisStub(); 128 StubRoutines::_generic_arraycopy = ShouldNotCallThisStub(); 129 130 // We don't generate specialized code for HeapWord-aligned source 131 // arrays, so just use the code we've already generated 132 StubRoutines::_arrayof_jbyte_disjoint_arraycopy = 133 StubRoutines::_jbyte_disjoint_arraycopy; 134 StubRoutines::_arrayof_jbyte_arraycopy = 135 StubRoutines::_jbyte_arraycopy; 136 137 StubRoutines::_arrayof_jshort_disjoint_arraycopy = 138 StubRoutines::_jshort_disjoint_arraycopy; 139 StubRoutines::_arrayof_jshort_arraycopy = 140 StubRoutines::_jshort_arraycopy; 141 142 StubRoutines::_arrayof_jint_disjoint_arraycopy = 143 StubRoutines::_jint_disjoint_arraycopy; 144 StubRoutines::_arrayof_jint_arraycopy = 145 StubRoutines::_jint_arraycopy; 146 147 StubRoutines::_arrayof_jlong_disjoint_arraycopy = 148 StubRoutines::_jlong_disjoint_arraycopy; 149 StubRoutines::_arrayof_jlong_arraycopy = 150 StubRoutines::_jlong_arraycopy; 151 152 StubRoutines::_arrayof_oop_disjoint_arraycopy = 153 StubRoutines::_oop_disjoint_arraycopy; 154 StubRoutines::_arrayof_oop_arraycopy = 155 StubRoutines::_oop_arraycopy; 156 } 157 158 void generate_initial() { 159 // Generates all stubs and initializes the entry points 160 161 // entry points that exist in all platforms Note: This is code 162 // that could be shared among different platforms - however the 163 // benefit seems to be smaller than the disadvantage of having a 164 // much more complicated generator structure. See also comment in 165 // stubRoutines.hpp. 166 167 StubRoutines::_forward_exception_entry = ShouldNotCallThisStub(); 168 StubRoutines::_call_stub_entry = (address) call_stub; 169 StubRoutines::_catch_exception_entry = ShouldNotCallThisStub(); 170 171 // atomic calls 172 StubRoutines::_atomic_xchg_entry = ShouldNotCallThisStub(); 173 StubRoutines::_atomic_xchg_ptr_entry = ShouldNotCallThisStub(); 174 StubRoutines::_atomic_cmpxchg_entry = ShouldNotCallThisStub(); 175 StubRoutines::_atomic_cmpxchg_ptr_entry = ShouldNotCallThisStub(); 176 StubRoutines::_atomic_cmpxchg_long_entry = ShouldNotCallThisStub(); 177 StubRoutines::_atomic_add_entry = ShouldNotCallThisStub(); 178 StubRoutines::_atomic_add_ptr_entry = ShouldNotCallThisStub(); 179 StubRoutines::_fence_entry = ShouldNotCallThisStub(); 180 181 // amd64 does this here, sparc does it in generate_all() 182 StubRoutines::_handler_for_unsafe_access_entry = 183 ShouldNotCallThisStub(); 184 } 185 186 void generate_all() { 187 // Generates all stubs and initializes the entry points 188 189 // These entry points require SharedInfo::stack0 to be set up in 190 // non-core builds and need to be relocatable, so they each 191 // fabricate a RuntimeStub internally. 192 StubRoutines::_throw_AbstractMethodError_entry = 193 ShouldNotCallThisStub(); 194 195 StubRoutines::_throw_ArithmeticException_entry = 196 ShouldNotCallThisStub(); 197 198 StubRoutines::_throw_NullPointerException_entry = 199 ShouldNotCallThisStub(); 200 201 StubRoutines::_throw_NullPointerException_at_call_entry = 202 ShouldNotCallThisStub(); 203 204 StubRoutines::_throw_StackOverflowError_entry = 205 ShouldNotCallThisStub(); 206 207 // support for verify_oop (must happen after universe_init) 208 StubRoutines::_verify_oop_subroutine_entry = 209 ShouldNotCallThisStub(); 210 211 // arraycopy stubs used by compilers 212 generate_arraycopy_stubs(); 213 } 214 215 public: 216 StubGenerator(CodeBuffer* code, bool all) : StubCodeGenerator(code) { 217 if (all) { 218 generate_all(); 219 } else { 220 generate_initial(); 221 } 222 } 223}; 224 225void StubGenerator_generate(CodeBuffer* code, bool all) { 226 StubGenerator g(code, all); 227} 228 229EntryFrame *EntryFrame::build(ZeroStack* stack, 230 const intptr_t* parameters, 231 int parameter_words, 232 JavaCallWrapper* call_wrapper) { 233 if (header_words + parameter_words > stack->available_words()) { 234 Unimplemented(); 235 } 236 237 stack->push(0); // next_frame, filled in later 238 intptr_t *fp = stack->sp(); 239 assert(fp - stack->sp() == next_frame_off, "should be"); 240 241 stack->push(ENTRY_FRAME); 242 assert(fp - stack->sp() == frame_type_off, "should be"); 243 244 stack->push((intptr_t) call_wrapper); 245 assert(fp - stack->sp() == call_wrapper_off, "should be"); 246 247 for (int i = 0; i < parameter_words; i++) 248 stack->push(parameters[i]); 249 250 return (EntryFrame *) fp; 251} 252