src/cpu/zero/vm/stubGenerator_zero.cpp

Thu, 16 Jun 2011 13:46:55 -0700

author
never
date
Thu, 16 Jun 2011 13:46:55 -0700
changeset 2978
d83ac25d0304
parent 2314
f95d63e2154a
child 3136
c565834fb592
permissions
-rw-r--r--

7055355: JSR 292: crash while throwing WrongMethodTypeException
Reviewed-by: jrose, twisti, bdelsart

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

mercurial