never@1445: /* mikael@6198: * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. twisti@1814: * Copyright 2007, 2008, 2010 Red Hat, Inc. never@1445: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. never@1445: * never@1445: * This code is free software; you can redistribute it and/or modify it never@1445: * under the terms of the GNU General Public License version 2 only, as never@1445: * published by the Free Software Foundation. never@1445: * never@1445: * This code is distributed in the hope that it will be useful, but WITHOUT never@1445: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or never@1445: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License never@1445: * version 2 for more details (a copy is included in the LICENSE file that never@1445: * accompanied this code). never@1445: * never@1445: * You should have received a copy of the GNU General Public License version never@1445: * 2 along with this work; if not, write to the Free Software Foundation, never@1445: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. never@1445: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. never@1445: * never@1445: */ never@1445: stefank@2314: #include "precompiled.hpp" stefank@2314: #include "asm/assembler.hpp" stefank@2314: #include "assembler_zero.inline.hpp" stefank@2314: #include "interpreter/interpreter.hpp" stefank@2314: #include "nativeInst_zero.hpp" stefank@2314: #include "oops/instanceOop.hpp" coleenp@4037: #include "oops/method.hpp" stefank@2314: #include "oops/objArrayKlass.hpp" stefank@2314: #include "oops/oop.inline.hpp" stefank@2314: #include "prims/methodHandles.hpp" stefank@2314: #include "runtime/frame.inline.hpp" stefank@2314: #include "runtime/handles.inline.hpp" stefank@2314: #include "runtime/sharedRuntime.hpp" stefank@2314: #include "runtime/stubCodeGenerator.hpp" stefank@2314: #include "runtime/stubRoutines.hpp" stefank@4299: #include "runtime/thread.inline.hpp" stefank@2314: #include "stack_zero.inline.hpp" stefank@2314: #include "utilities/top.hpp" stefank@2314: #ifdef COMPILER2 stefank@2314: #include "opto/runtime.hpp" stefank@2314: #endif never@1445: never@1445: // Declaration and definition of StubGenerator (no .hpp file). never@1445: // For a more detailed description of the stub routine structure never@1445: // see the comment in stubRoutines.hpp never@1445: never@1445: class StubGenerator: public StubCodeGenerator { never@1445: private: never@1445: // The call stub is used to call Java from C never@1445: static void call_stub( never@1445: JavaCallWrapper *call_wrapper, never@1445: intptr_t* result, never@1445: BasicType result_type, coleenp@4037: Method* method, never@1445: address entry_point, never@1445: intptr_t* parameters, never@1445: int parameter_words, never@1445: TRAPS) { never@1445: JavaThread *thread = (JavaThread *) THREAD; never@1445: ZeroStack *stack = thread->zero_stack(); never@1445: never@1445: // Make sure we have no pending exceptions never@1445: assert(!HAS_PENDING_EXCEPTION, "call_stub called with pending exception"); never@1445: never@1445: // Set up the stack if necessary never@1445: bool stack_needs_teardown = false; never@1445: if (stack->needs_setup()) { twisti@1866: size_t zero_stack_size = stack->suggest_size(thread); never@1445: stack->setup(alloca(zero_stack_size), zero_stack_size); never@1445: stack_needs_teardown = true; never@1445: } never@1445: never@1445: // Allocate and initialize our frame twisti@1814: EntryFrame *frame = twisti@1814: EntryFrame::build(parameters, parameter_words, call_wrapper, THREAD); never@1445: twisti@1814: if (!HAS_PENDING_EXCEPTION) { twisti@1814: // Push the frame twisti@1814: thread->push_zero_frame(frame); never@1445: twisti@1814: // Make the call twisti@1814: Interpreter::invoke_method(method, entry_point, THREAD); twisti@1814: twisti@1814: // Store the result twisti@1814: if (!HAS_PENDING_EXCEPTION) { twisti@1814: switch (result_type) { twisti@1814: case T_INT: twisti@1814: *(jint *) result = *(jint *) stack->sp(); twisti@1814: break; twisti@1814: case T_LONG: twisti@1814: *(jlong *) result = *(jlong *) stack->sp(); twisti@1814: break; twisti@1814: case T_FLOAT: twisti@1814: *(jfloat *) result = *(jfloat *) stack->sp(); twisti@1814: break; twisti@1814: case T_DOUBLE: twisti@1814: *(jdouble *) result = *(jdouble *) stack->sp(); twisti@1814: break; twisti@1814: case T_OBJECT: twisti@1814: *(oop *) result = *(oop *) stack->sp(); twisti@1814: break; twisti@1814: default: twisti@1814: ShouldNotReachHere(); twisti@1814: } never@1445: } twisti@1814: twisti@1814: // Unwind the frame twisti@1814: thread->pop_zero_frame(); never@1445: } never@1445: never@1445: // Tear down the stack if necessary never@1445: if (stack_needs_teardown) never@1445: stack->teardown(); never@1445: } never@1445: never@1445: // These stubs get called from some dumb test routine. never@1445: // I'll write them properly when they're called from never@1445: // something that's actually doing something. never@1445: static void fake_arraycopy_stub(address src, address dst, int count) { never@1445: assert(count == 0, "huh?"); never@1445: } never@1445: never@1445: void generate_arraycopy_stubs() { never@1445: // Call the conjoint generation methods immediately after never@1445: // the disjoint ones so that short branches from the former never@1445: // to the latter can be generated. never@1445: StubRoutines::_jbyte_disjoint_arraycopy = (address) fake_arraycopy_stub; never@1445: StubRoutines::_jbyte_arraycopy = (address) fake_arraycopy_stub; never@1445: never@1445: StubRoutines::_jshort_disjoint_arraycopy = (address) fake_arraycopy_stub; never@1445: StubRoutines::_jshort_arraycopy = (address) fake_arraycopy_stub; never@1445: never@1445: StubRoutines::_jint_disjoint_arraycopy = (address) fake_arraycopy_stub; never@1445: StubRoutines::_jint_arraycopy = (address) fake_arraycopy_stub; never@1445: never@1445: StubRoutines::_jlong_disjoint_arraycopy = (address) fake_arraycopy_stub; never@1445: StubRoutines::_jlong_arraycopy = (address) fake_arraycopy_stub; never@1445: never@1445: StubRoutines::_oop_disjoint_arraycopy = ShouldNotCallThisStub(); never@1445: StubRoutines::_oop_arraycopy = ShouldNotCallThisStub(); never@1445: never@1445: StubRoutines::_checkcast_arraycopy = ShouldNotCallThisStub(); never@1445: StubRoutines::_unsafe_arraycopy = ShouldNotCallThisStub(); never@1445: StubRoutines::_generic_arraycopy = ShouldNotCallThisStub(); never@1445: never@1445: // We don't generate specialized code for HeapWord-aligned source never@1445: // arrays, so just use the code we've already generated never@1445: StubRoutines::_arrayof_jbyte_disjoint_arraycopy = never@1445: StubRoutines::_jbyte_disjoint_arraycopy; never@1445: StubRoutines::_arrayof_jbyte_arraycopy = never@1445: StubRoutines::_jbyte_arraycopy; never@1445: never@1445: StubRoutines::_arrayof_jshort_disjoint_arraycopy = never@1445: StubRoutines::_jshort_disjoint_arraycopy; never@1445: StubRoutines::_arrayof_jshort_arraycopy = never@1445: StubRoutines::_jshort_arraycopy; never@1445: never@1445: StubRoutines::_arrayof_jint_disjoint_arraycopy = never@1445: StubRoutines::_jint_disjoint_arraycopy; never@1445: StubRoutines::_arrayof_jint_arraycopy = never@1445: StubRoutines::_jint_arraycopy; never@1445: never@1445: StubRoutines::_arrayof_jlong_disjoint_arraycopy = never@1445: StubRoutines::_jlong_disjoint_arraycopy; never@1445: StubRoutines::_arrayof_jlong_arraycopy = never@1445: StubRoutines::_jlong_arraycopy; never@1445: never@1445: StubRoutines::_arrayof_oop_disjoint_arraycopy = never@1445: StubRoutines::_oop_disjoint_arraycopy; never@1445: StubRoutines::_arrayof_oop_arraycopy = never@1445: StubRoutines::_oop_arraycopy; never@1445: } never@1445: omajid@5497: static int SafeFetch32(int *adr, int errValue) { omajid@5497: int value = errValue; omajid@5497: value = *adr; omajid@5497: return value; omajid@5497: } omajid@5497: omajid@5497: static intptr_t SafeFetchN(intptr_t *adr, intptr_t errValue) { omajid@5497: intptr_t value = errValue; omajid@5497: value = *adr; omajid@5497: return value; omajid@5497: } omajid@5497: omajid@5497: never@1445: void generate_initial() { never@1445: // Generates all stubs and initializes the entry points never@1445: never@1445: // entry points that exist in all platforms Note: This is code never@1445: // that could be shared among different platforms - however the never@1445: // benefit seems to be smaller than the disadvantage of having a never@1445: // much more complicated generator structure. See also comment in never@1445: // stubRoutines.hpp. never@1445: never@1445: StubRoutines::_forward_exception_entry = ShouldNotCallThisStub(); never@1445: StubRoutines::_call_stub_entry = (address) call_stub; never@1445: StubRoutines::_catch_exception_entry = ShouldNotCallThisStub(); never@1445: never@1445: // atomic calls never@1445: StubRoutines::_atomic_xchg_entry = ShouldNotCallThisStub(); never@1445: StubRoutines::_atomic_xchg_ptr_entry = ShouldNotCallThisStub(); never@1445: StubRoutines::_atomic_cmpxchg_entry = ShouldNotCallThisStub(); never@1445: StubRoutines::_atomic_cmpxchg_ptr_entry = ShouldNotCallThisStub(); never@1445: StubRoutines::_atomic_cmpxchg_long_entry = ShouldNotCallThisStub(); never@1445: StubRoutines::_atomic_add_entry = ShouldNotCallThisStub(); never@1445: StubRoutines::_atomic_add_ptr_entry = ShouldNotCallThisStub(); never@1445: StubRoutines::_fence_entry = ShouldNotCallThisStub(); never@1445: never@1445: // amd64 does this here, sparc does it in generate_all() never@1445: StubRoutines::_handler_for_unsafe_access_entry = never@1445: ShouldNotCallThisStub(); never@1445: } never@1445: never@1445: void generate_all() { never@1445: // Generates all stubs and initializes the entry points never@1445: never@1445: // These entry points require SharedInfo::stack0 to be set up in never@1445: // non-core builds and need to be relocatable, so they each never@1445: // fabricate a RuntimeStub internally. never@1445: StubRoutines::_throw_AbstractMethodError_entry = never@1445: ShouldNotCallThisStub(); never@1445: never@1445: StubRoutines::_throw_NullPointerException_at_call_entry = never@1445: ShouldNotCallThisStub(); never@1445: never@1445: StubRoutines::_throw_StackOverflowError_entry = never@1445: ShouldNotCallThisStub(); never@1445: never@1445: // support for verify_oop (must happen after universe_init) never@1445: StubRoutines::_verify_oop_subroutine_entry = never@1445: ShouldNotCallThisStub(); never@1445: never@1445: // arraycopy stubs used by compilers never@1445: generate_arraycopy_stubs(); omajid@5497: omajid@5497: // Safefetch stubs. omajid@5497: StubRoutines::_safefetch32_entry = CAST_FROM_FN_PTR(address, StubGenerator::SafeFetch32); omajid@5497: StubRoutines::_safefetch32_fault_pc = NULL; omajid@5497: StubRoutines::_safefetch32_continuation_pc = NULL; omajid@5497: omajid@5497: StubRoutines::_safefetchN_entry = CAST_FROM_FN_PTR(address, StubGenerator::SafeFetchN); omajid@5497: StubRoutines::_safefetchN_fault_pc = NULL; omajid@5497: StubRoutines::_safefetchN_continuation_pc = NULL; never@1445: } never@1445: never@1445: public: never@1445: StubGenerator(CodeBuffer* code, bool all) : StubCodeGenerator(code) { never@1445: if (all) { never@1445: generate_all(); never@1445: } else { never@1445: generate_initial(); never@1445: } never@1445: } never@1445: }; never@1445: never@1445: void StubGenerator_generate(CodeBuffer* code, bool all) { never@1445: StubGenerator g(code, all); never@1445: } never@1445: twisti@1814: EntryFrame *EntryFrame::build(const intptr_t* parameters, never@1445: int parameter_words, twisti@1814: JavaCallWrapper* call_wrapper, twisti@1814: TRAPS) { twisti@1814: twisti@1814: ZeroStack *stack = ((JavaThread *) THREAD)->zero_stack(); twisti@1814: stack->overflow_check(header_words + parameter_words, CHECK_NULL); never@1445: never@1445: stack->push(0); // next_frame, filled in later never@1445: intptr_t *fp = stack->sp(); never@1445: assert(fp - stack->sp() == next_frame_off, "should be"); never@1445: never@1445: stack->push(ENTRY_FRAME); never@1445: assert(fp - stack->sp() == frame_type_off, "should be"); never@1445: never@1445: stack->push((intptr_t) call_wrapper); never@1445: assert(fp - stack->sp() == call_wrapper_off, "should be"); never@1445: never@1445: for (int i = 0; i < parameter_words; i++) never@1445: stack->push(parameters[i]); never@1445: never@1445: return (EntryFrame *) fp; never@1445: }