src/cpu/zero/vm/stubGenerator_zero.cpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/cpu/zero/vm/stubGenerator_zero.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,288 @@
     1.4 +/*
     1.5 + * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright 2007, 2008, 2010 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.24 + * or visit www.oracle.com if you need additional information or have any
    1.25 + * questions.
    1.26 + *
    1.27 + */
    1.28 +
    1.29 +#include "precompiled.hpp"
    1.30 +#include "asm/assembler.hpp"
    1.31 +#include "assembler_zero.inline.hpp"
    1.32 +#include "interpreter/interpreter.hpp"
    1.33 +#include "nativeInst_zero.hpp"
    1.34 +#include "oops/instanceOop.hpp"
    1.35 +#include "oops/method.hpp"
    1.36 +#include "oops/objArrayKlass.hpp"
    1.37 +#include "oops/oop.inline.hpp"
    1.38 +#include "prims/methodHandles.hpp"
    1.39 +#include "runtime/frame.inline.hpp"
    1.40 +#include "runtime/handles.inline.hpp"
    1.41 +#include "runtime/sharedRuntime.hpp"
    1.42 +#include "runtime/stubCodeGenerator.hpp"
    1.43 +#include "runtime/stubRoutines.hpp"
    1.44 +#include "runtime/thread.inline.hpp"
    1.45 +#include "stack_zero.inline.hpp"
    1.46 +#include "utilities/top.hpp"
    1.47 +#ifdef COMPILER2
    1.48 +#include "opto/runtime.hpp"
    1.49 +#endif
    1.50 +
    1.51 +// Declaration and definition of StubGenerator (no .hpp file).
    1.52 +// For a more detailed description of the stub routine structure
    1.53 +// see the comment in stubRoutines.hpp
    1.54 +
    1.55 +class StubGenerator: public StubCodeGenerator {
    1.56 + private:
    1.57 +  // The call stub is used to call Java from C
    1.58 +  static void call_stub(
    1.59 +    JavaCallWrapper *call_wrapper,
    1.60 +    intptr_t*        result,
    1.61 +    BasicType        result_type,
    1.62 +    Method*          method,
    1.63 +    address          entry_point,
    1.64 +    intptr_t*        parameters,
    1.65 +    int              parameter_words,
    1.66 +    TRAPS) {
    1.67 +    JavaThread *thread = (JavaThread *) THREAD;
    1.68 +    ZeroStack *stack = thread->zero_stack();
    1.69 +
    1.70 +    // Make sure we have no pending exceptions
    1.71 +    assert(!HAS_PENDING_EXCEPTION, "call_stub called with pending exception");
    1.72 +
    1.73 +    // Set up the stack if necessary
    1.74 +    bool stack_needs_teardown = false;
    1.75 +    if (stack->needs_setup()) {
    1.76 +      size_t zero_stack_size = stack->suggest_size(thread);
    1.77 +      stack->setup(alloca(zero_stack_size), zero_stack_size);
    1.78 +      stack_needs_teardown = true;
    1.79 +    }
    1.80 +
    1.81 +    // Allocate and initialize our frame
    1.82 +    EntryFrame *frame =
    1.83 +      EntryFrame::build(parameters, parameter_words, call_wrapper, THREAD);
    1.84 +
    1.85 +    if (!HAS_PENDING_EXCEPTION) {
    1.86 +      // Push the frame
    1.87 +      thread->push_zero_frame(frame);
    1.88 +
    1.89 +      // Make the call
    1.90 +      Interpreter::invoke_method(method, entry_point, THREAD);
    1.91 +
    1.92 +      // Store the result
    1.93 +      if (!HAS_PENDING_EXCEPTION) {
    1.94 +        switch (result_type) {
    1.95 +        case T_INT:
    1.96 +          *(jint *) result = *(jint *) stack->sp();
    1.97 +          break;
    1.98 +        case T_LONG:
    1.99 +          *(jlong *) result = *(jlong *) stack->sp();
   1.100 +          break;
   1.101 +        case T_FLOAT:
   1.102 +          *(jfloat *) result = *(jfloat *) stack->sp();
   1.103 +          break;
   1.104 +        case T_DOUBLE:
   1.105 +          *(jdouble *) result = *(jdouble *) stack->sp();
   1.106 +          break;
   1.107 +        case T_OBJECT:
   1.108 +          *(oop *) result = *(oop *) stack->sp();
   1.109 +          break;
   1.110 +        default:
   1.111 +          ShouldNotReachHere();
   1.112 +        }
   1.113 +      }
   1.114 +
   1.115 +      // Unwind the frame
   1.116 +      thread->pop_zero_frame();
   1.117 +    }
   1.118 +
   1.119 +    // Tear down the stack if necessary
   1.120 +    if (stack_needs_teardown)
   1.121 +      stack->teardown();
   1.122 +  }
   1.123 +
   1.124 +  // These stubs get called from some dumb test routine.
   1.125 +  // I'll write them properly when they're called from
   1.126 +  // something that's actually doing something.
   1.127 +  static void fake_arraycopy_stub(address src, address dst, int count) {
   1.128 +    assert(count == 0, "huh?");
   1.129 +  }
   1.130 +
   1.131 +  void generate_arraycopy_stubs() {
   1.132 +    // Call the conjoint generation methods immediately after
   1.133 +    // the disjoint ones so that short branches from the former
   1.134 +    // to the latter can be generated.
   1.135 +    StubRoutines::_jbyte_disjoint_arraycopy  = (address) fake_arraycopy_stub;
   1.136 +    StubRoutines::_jbyte_arraycopy           = (address) fake_arraycopy_stub;
   1.137 +
   1.138 +    StubRoutines::_jshort_disjoint_arraycopy = (address) fake_arraycopy_stub;
   1.139 +    StubRoutines::_jshort_arraycopy          = (address) fake_arraycopy_stub;
   1.140 +
   1.141 +    StubRoutines::_jint_disjoint_arraycopy   = (address) fake_arraycopy_stub;
   1.142 +    StubRoutines::_jint_arraycopy            = (address) fake_arraycopy_stub;
   1.143 +
   1.144 +    StubRoutines::_jlong_disjoint_arraycopy  = (address) fake_arraycopy_stub;
   1.145 +    StubRoutines::_jlong_arraycopy           = (address) fake_arraycopy_stub;
   1.146 +
   1.147 +    StubRoutines::_oop_disjoint_arraycopy    = ShouldNotCallThisStub();
   1.148 +    StubRoutines::_oop_arraycopy             = ShouldNotCallThisStub();
   1.149 +
   1.150 +    StubRoutines::_checkcast_arraycopy       = ShouldNotCallThisStub();
   1.151 +    StubRoutines::_unsafe_arraycopy          = ShouldNotCallThisStub();
   1.152 +    StubRoutines::_generic_arraycopy         = ShouldNotCallThisStub();
   1.153 +
   1.154 +    // We don't generate specialized code for HeapWord-aligned source
   1.155 +    // arrays, so just use the code we've already generated
   1.156 +    StubRoutines::_arrayof_jbyte_disjoint_arraycopy =
   1.157 +      StubRoutines::_jbyte_disjoint_arraycopy;
   1.158 +    StubRoutines::_arrayof_jbyte_arraycopy =
   1.159 +      StubRoutines::_jbyte_arraycopy;
   1.160 +
   1.161 +    StubRoutines::_arrayof_jshort_disjoint_arraycopy =
   1.162 +      StubRoutines::_jshort_disjoint_arraycopy;
   1.163 +    StubRoutines::_arrayof_jshort_arraycopy =
   1.164 +      StubRoutines::_jshort_arraycopy;
   1.165 +
   1.166 +    StubRoutines::_arrayof_jint_disjoint_arraycopy =
   1.167 +      StubRoutines::_jint_disjoint_arraycopy;
   1.168 +    StubRoutines::_arrayof_jint_arraycopy =
   1.169 +      StubRoutines::_jint_arraycopy;
   1.170 +
   1.171 +    StubRoutines::_arrayof_jlong_disjoint_arraycopy =
   1.172 +      StubRoutines::_jlong_disjoint_arraycopy;
   1.173 +    StubRoutines::_arrayof_jlong_arraycopy =
   1.174 +      StubRoutines::_jlong_arraycopy;
   1.175 +
   1.176 +    StubRoutines::_arrayof_oop_disjoint_arraycopy =
   1.177 +      StubRoutines::_oop_disjoint_arraycopy;
   1.178 +    StubRoutines::_arrayof_oop_arraycopy =
   1.179 +      StubRoutines::_oop_arraycopy;
   1.180 +  }
   1.181 +
   1.182 +  static int SafeFetch32(int *adr, int errValue) {
   1.183 +    int value = errValue;
   1.184 +    value = *adr;
   1.185 +    return value;
   1.186 +  }
   1.187 +
   1.188 +  static intptr_t SafeFetchN(intptr_t *adr, intptr_t errValue) {
   1.189 +    intptr_t value = errValue;
   1.190 +    value = *adr;
   1.191 +    return value;
   1.192 +  }
   1.193 +
   1.194 +
   1.195 +  void generate_initial() {
   1.196 +    // Generates all stubs and initializes the entry points
   1.197 +
   1.198 +    // entry points that exist in all platforms Note: This is code
   1.199 +    // that could be shared among different platforms - however the
   1.200 +    // benefit seems to be smaller than the disadvantage of having a
   1.201 +    // much more complicated generator structure. See also comment in
   1.202 +    // stubRoutines.hpp.
   1.203 +
   1.204 +    StubRoutines::_forward_exception_entry   = ShouldNotCallThisStub();
   1.205 +    StubRoutines::_call_stub_entry           = (address) call_stub;
   1.206 +    StubRoutines::_catch_exception_entry     = ShouldNotCallThisStub();
   1.207 +
   1.208 +    // atomic calls
   1.209 +    StubRoutines::_atomic_xchg_entry         = ShouldNotCallThisStub();
   1.210 +    StubRoutines::_atomic_xchg_ptr_entry     = ShouldNotCallThisStub();
   1.211 +    StubRoutines::_atomic_cmpxchg_entry      = ShouldNotCallThisStub();
   1.212 +    StubRoutines::_atomic_cmpxchg_ptr_entry  = ShouldNotCallThisStub();
   1.213 +    StubRoutines::_atomic_cmpxchg_long_entry = ShouldNotCallThisStub();
   1.214 +    StubRoutines::_atomic_add_entry          = ShouldNotCallThisStub();
   1.215 +    StubRoutines::_atomic_add_ptr_entry      = ShouldNotCallThisStub();
   1.216 +    StubRoutines::_fence_entry               = ShouldNotCallThisStub();
   1.217 +
   1.218 +    // amd64 does this here, sparc does it in generate_all()
   1.219 +    StubRoutines::_handler_for_unsafe_access_entry =
   1.220 +      ShouldNotCallThisStub();
   1.221 +  }
   1.222 +
   1.223 +  void generate_all() {
   1.224 +    // Generates all stubs and initializes the entry points
   1.225 +
   1.226 +    // These entry points require SharedInfo::stack0 to be set up in
   1.227 +    // non-core builds and need to be relocatable, so they each
   1.228 +    // fabricate a RuntimeStub internally.
   1.229 +    StubRoutines::_throw_AbstractMethodError_entry =
   1.230 +      ShouldNotCallThisStub();
   1.231 +
   1.232 +    StubRoutines::_throw_NullPointerException_at_call_entry =
   1.233 +      ShouldNotCallThisStub();
   1.234 +
   1.235 +    StubRoutines::_throw_StackOverflowError_entry =
   1.236 +      ShouldNotCallThisStub();
   1.237 +
   1.238 +    // support for verify_oop (must happen after universe_init)
   1.239 +    StubRoutines::_verify_oop_subroutine_entry =
   1.240 +      ShouldNotCallThisStub();
   1.241 +
   1.242 +    // arraycopy stubs used by compilers
   1.243 +    generate_arraycopy_stubs();
   1.244 +
   1.245 +    // Safefetch stubs.
   1.246 +    StubRoutines::_safefetch32_entry = CAST_FROM_FN_PTR(address, StubGenerator::SafeFetch32);
   1.247 +    StubRoutines::_safefetch32_fault_pc = NULL;
   1.248 +    StubRoutines::_safefetch32_continuation_pc = NULL;
   1.249 +
   1.250 +    StubRoutines::_safefetchN_entry = CAST_FROM_FN_PTR(address, StubGenerator::SafeFetchN);
   1.251 +    StubRoutines::_safefetchN_fault_pc = NULL;
   1.252 +    StubRoutines::_safefetchN_continuation_pc = NULL;
   1.253 +  }
   1.254 +
   1.255 + public:
   1.256 +  StubGenerator(CodeBuffer* code, bool all) : StubCodeGenerator(code) {
   1.257 +    if (all) {
   1.258 +      generate_all();
   1.259 +    } else {
   1.260 +      generate_initial();
   1.261 +    }
   1.262 +  }
   1.263 +};
   1.264 +
   1.265 +void StubGenerator_generate(CodeBuffer* code, bool all) {
   1.266 +  StubGenerator g(code, all);
   1.267 +}
   1.268 +
   1.269 +EntryFrame *EntryFrame::build(const intptr_t*  parameters,
   1.270 +                              int              parameter_words,
   1.271 +                              JavaCallWrapper* call_wrapper,
   1.272 +                              TRAPS) {
   1.273 +
   1.274 +  ZeroStack *stack = ((JavaThread *) THREAD)->zero_stack();
   1.275 +  stack->overflow_check(header_words + parameter_words, CHECK_NULL);
   1.276 +
   1.277 +  stack->push(0); // next_frame, filled in later
   1.278 +  intptr_t *fp = stack->sp();
   1.279 +  assert(fp - stack->sp() == next_frame_off, "should be");
   1.280 +
   1.281 +  stack->push(ENTRY_FRAME);
   1.282 +  assert(fp - stack->sp() == frame_type_off, "should be");
   1.283 +
   1.284 +  stack->push((intptr_t) call_wrapper);
   1.285 +  assert(fp - stack->sp() == call_wrapper_off, "should be");
   1.286 +
   1.287 +  for (int i = 0; i < parameter_words; i++)
   1.288 +    stack->push(parameters[i]);
   1.289 +
   1.290 +  return (EntryFrame *) fp;
   1.291 +}

mercurial