1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/cpu/zero/vm/stubGenerator_zero.cpp Tue Oct 13 12:04:21 2009 -0700 1.3 @@ -0,0 +1,251 @@ 1.4 +/* 1.5 + * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * Copyright 2007, 2008 Red Hat, Inc. 1.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 + * 1.9 + * This code is free software; you can redistribute it and/or modify it 1.10 + * under the terms of the GNU General Public License version 2 only, as 1.11 + * published by the Free Software Foundation. 1.12 + * 1.13 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.16 + * version 2 for more details (a copy is included in the LICENSE file that 1.17 + * accompanied this code). 1.18 + * 1.19 + * You should have received a copy of the GNU General Public License version 1.20 + * 2 along with this work; if not, write to the Free Software Foundation, 1.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.22 + * 1.23 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.24 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.25 + * have any questions. 1.26 + * 1.27 + */ 1.28 + 1.29 +#include "incls/_precompiled.incl" 1.30 +#include "incls/_stubGenerator_zero.cpp.incl" 1.31 + 1.32 +// Declaration and definition of StubGenerator (no .hpp file). 1.33 +// For a more detailed description of the stub routine structure 1.34 +// see the comment in stubRoutines.hpp 1.35 + 1.36 +class StubGenerator: public StubCodeGenerator { 1.37 + private: 1.38 + // The call stub is used to call Java from C 1.39 + static void call_stub( 1.40 + JavaCallWrapper *call_wrapper, 1.41 + intptr_t* result, 1.42 + BasicType result_type, 1.43 + methodOop method, 1.44 + address entry_point, 1.45 + intptr_t* parameters, 1.46 + int parameter_words, 1.47 + TRAPS) { 1.48 + JavaThread *thread = (JavaThread *) THREAD; 1.49 + ZeroStack *stack = thread->zero_stack(); 1.50 + 1.51 + // Make sure we have no pending exceptions 1.52 + assert(!HAS_PENDING_EXCEPTION, "call_stub called with pending exception"); 1.53 + 1.54 + // Set up the stack if necessary 1.55 + bool stack_needs_teardown = false; 1.56 + if (stack->needs_setup()) { 1.57 + size_t stack_used = thread->stack_base() - (address) &stack_used; 1.58 + size_t stack_free = thread->stack_size() - stack_used; 1.59 + size_t zero_stack_size = align_size_down(stack_free / 2, wordSize); 1.60 + 1.61 + stack->setup(alloca(zero_stack_size), zero_stack_size); 1.62 + stack_needs_teardown = true; 1.63 + } 1.64 + 1.65 + // Allocate and initialize our frame 1.66 + thread->push_zero_frame( 1.67 + EntryFrame::build(stack, parameters, parameter_words, call_wrapper)); 1.68 + 1.69 + // Make the call 1.70 + Interpreter::invoke_method(method, entry_point, THREAD); 1.71 + 1.72 + // Store result depending on type 1.73 + if (!HAS_PENDING_EXCEPTION) { 1.74 + switch (result_type) { 1.75 + case T_INT: 1.76 + *(jint *) result = *(jint *) stack->sp(); 1.77 + break; 1.78 + case T_LONG: 1.79 + *(jlong *) result = *(jlong *) stack->sp(); 1.80 + break; 1.81 + case T_FLOAT: 1.82 + *(jfloat *) result = *(jfloat *) stack->sp(); 1.83 + break; 1.84 + case T_DOUBLE: 1.85 + *(jdouble *) result = *(jdouble *) stack->sp(); 1.86 + break; 1.87 + case T_OBJECT: 1.88 + *(oop *) result = *(oop *) stack->sp(); 1.89 + break; 1.90 + default: 1.91 + ShouldNotReachHere(); 1.92 + } 1.93 + } 1.94 + 1.95 + // Unwind our frame 1.96 + thread->pop_zero_frame(); 1.97 + 1.98 + // Tear down the stack if necessary 1.99 + if (stack_needs_teardown) 1.100 + stack->teardown(); 1.101 + } 1.102 + 1.103 + // These stubs get called from some dumb test routine. 1.104 + // I'll write them properly when they're called from 1.105 + // something that's actually doing something. 1.106 + static void fake_arraycopy_stub(address src, address dst, int count) { 1.107 + assert(count == 0, "huh?"); 1.108 + } 1.109 + 1.110 + void generate_arraycopy_stubs() { 1.111 + // Call the conjoint generation methods immediately after 1.112 + // the disjoint ones so that short branches from the former 1.113 + // to the latter can be generated. 1.114 + StubRoutines::_jbyte_disjoint_arraycopy = (address) fake_arraycopy_stub; 1.115 + StubRoutines::_jbyte_arraycopy = (address) fake_arraycopy_stub; 1.116 + 1.117 + StubRoutines::_jshort_disjoint_arraycopy = (address) fake_arraycopy_stub; 1.118 + StubRoutines::_jshort_arraycopy = (address) fake_arraycopy_stub; 1.119 + 1.120 + StubRoutines::_jint_disjoint_arraycopy = (address) fake_arraycopy_stub; 1.121 + StubRoutines::_jint_arraycopy = (address) fake_arraycopy_stub; 1.122 + 1.123 + StubRoutines::_jlong_disjoint_arraycopy = (address) fake_arraycopy_stub; 1.124 + StubRoutines::_jlong_arraycopy = (address) fake_arraycopy_stub; 1.125 + 1.126 + StubRoutines::_oop_disjoint_arraycopy = ShouldNotCallThisStub(); 1.127 + StubRoutines::_oop_arraycopy = ShouldNotCallThisStub(); 1.128 + 1.129 + StubRoutines::_checkcast_arraycopy = ShouldNotCallThisStub(); 1.130 + StubRoutines::_unsafe_arraycopy = ShouldNotCallThisStub(); 1.131 + StubRoutines::_generic_arraycopy = ShouldNotCallThisStub(); 1.132 + 1.133 + // We don't generate specialized code for HeapWord-aligned source 1.134 + // arrays, so just use the code we've already generated 1.135 + StubRoutines::_arrayof_jbyte_disjoint_arraycopy = 1.136 + StubRoutines::_jbyte_disjoint_arraycopy; 1.137 + StubRoutines::_arrayof_jbyte_arraycopy = 1.138 + StubRoutines::_jbyte_arraycopy; 1.139 + 1.140 + StubRoutines::_arrayof_jshort_disjoint_arraycopy = 1.141 + StubRoutines::_jshort_disjoint_arraycopy; 1.142 + StubRoutines::_arrayof_jshort_arraycopy = 1.143 + StubRoutines::_jshort_arraycopy; 1.144 + 1.145 + StubRoutines::_arrayof_jint_disjoint_arraycopy = 1.146 + StubRoutines::_jint_disjoint_arraycopy; 1.147 + StubRoutines::_arrayof_jint_arraycopy = 1.148 + StubRoutines::_jint_arraycopy; 1.149 + 1.150 + StubRoutines::_arrayof_jlong_disjoint_arraycopy = 1.151 + StubRoutines::_jlong_disjoint_arraycopy; 1.152 + StubRoutines::_arrayof_jlong_arraycopy = 1.153 + StubRoutines::_jlong_arraycopy; 1.154 + 1.155 + StubRoutines::_arrayof_oop_disjoint_arraycopy = 1.156 + StubRoutines::_oop_disjoint_arraycopy; 1.157 + StubRoutines::_arrayof_oop_arraycopy = 1.158 + StubRoutines::_oop_arraycopy; 1.159 + } 1.160 + 1.161 + void generate_initial() { 1.162 + // Generates all stubs and initializes the entry points 1.163 + 1.164 + // entry points that exist in all platforms Note: This is code 1.165 + // that could be shared among different platforms - however the 1.166 + // benefit seems to be smaller than the disadvantage of having a 1.167 + // much more complicated generator structure. See also comment in 1.168 + // stubRoutines.hpp. 1.169 + 1.170 + StubRoutines::_forward_exception_entry = ShouldNotCallThisStub(); 1.171 + StubRoutines::_call_stub_entry = (address) call_stub; 1.172 + StubRoutines::_catch_exception_entry = ShouldNotCallThisStub(); 1.173 + 1.174 + // atomic calls 1.175 + StubRoutines::_atomic_xchg_entry = ShouldNotCallThisStub(); 1.176 + StubRoutines::_atomic_xchg_ptr_entry = ShouldNotCallThisStub(); 1.177 + StubRoutines::_atomic_cmpxchg_entry = ShouldNotCallThisStub(); 1.178 + StubRoutines::_atomic_cmpxchg_ptr_entry = ShouldNotCallThisStub(); 1.179 + StubRoutines::_atomic_cmpxchg_long_entry = ShouldNotCallThisStub(); 1.180 + StubRoutines::_atomic_add_entry = ShouldNotCallThisStub(); 1.181 + StubRoutines::_atomic_add_ptr_entry = ShouldNotCallThisStub(); 1.182 + StubRoutines::_fence_entry = ShouldNotCallThisStub(); 1.183 + 1.184 + // amd64 does this here, sparc does it in generate_all() 1.185 + StubRoutines::_handler_for_unsafe_access_entry = 1.186 + ShouldNotCallThisStub(); 1.187 + } 1.188 + 1.189 + void generate_all() { 1.190 + // Generates all stubs and initializes the entry points 1.191 + 1.192 + // These entry points require SharedInfo::stack0 to be set up in 1.193 + // non-core builds and need to be relocatable, so they each 1.194 + // fabricate a RuntimeStub internally. 1.195 + StubRoutines::_throw_AbstractMethodError_entry = 1.196 + ShouldNotCallThisStub(); 1.197 + 1.198 + StubRoutines::_throw_ArithmeticException_entry = 1.199 + ShouldNotCallThisStub(); 1.200 + 1.201 + StubRoutines::_throw_NullPointerException_entry = 1.202 + ShouldNotCallThisStub(); 1.203 + 1.204 + StubRoutines::_throw_NullPointerException_at_call_entry = 1.205 + ShouldNotCallThisStub(); 1.206 + 1.207 + StubRoutines::_throw_StackOverflowError_entry = 1.208 + ShouldNotCallThisStub(); 1.209 + 1.210 + // support for verify_oop (must happen after universe_init) 1.211 + StubRoutines::_verify_oop_subroutine_entry = 1.212 + ShouldNotCallThisStub(); 1.213 + 1.214 + // arraycopy stubs used by compilers 1.215 + generate_arraycopy_stubs(); 1.216 + } 1.217 + 1.218 + public: 1.219 + StubGenerator(CodeBuffer* code, bool all) : StubCodeGenerator(code) { 1.220 + if (all) { 1.221 + generate_all(); 1.222 + } else { 1.223 + generate_initial(); 1.224 + } 1.225 + } 1.226 +}; 1.227 + 1.228 +void StubGenerator_generate(CodeBuffer* code, bool all) { 1.229 + StubGenerator g(code, all); 1.230 +} 1.231 + 1.232 +EntryFrame *EntryFrame::build(ZeroStack* stack, 1.233 + const intptr_t* parameters, 1.234 + int parameter_words, 1.235 + JavaCallWrapper* call_wrapper) { 1.236 + if (header_words + parameter_words > stack->available_words()) { 1.237 + Unimplemented(); 1.238 + } 1.239 + 1.240 + stack->push(0); // next_frame, filled in later 1.241 + intptr_t *fp = stack->sp(); 1.242 + assert(fp - stack->sp() == next_frame_off, "should be"); 1.243 + 1.244 + stack->push(ENTRY_FRAME); 1.245 + assert(fp - stack->sp() == frame_type_off, "should be"); 1.246 + 1.247 + stack->push((intptr_t) call_wrapper); 1.248 + assert(fp - stack->sp() == call_wrapper_off, "should be"); 1.249 + 1.250 + for (int i = 0; i < parameter_words; i++) 1.251 + stack->push(parameters[i]); 1.252 + 1.253 + return (EntryFrame *) fp; 1.254 +}