src/cpu/zero/vm/stubGenerator_zero.cpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6198
55fb97c4c58d
parent 0
f90c822e73f8
permissions
-rw-r--r--

merge

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

mercurial