src/cpu/zero/vm/interpreterRT_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/interpreterRT_zero.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,171 @@
     1.4 +/*
     1.5 + * Copyright (c) 2003, 2012, 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 "interpreter/interpreter.hpp"
    1.31 +#include "interpreter/interpreterRuntime.hpp"
    1.32 +#include "memory/allocation.inline.hpp"
    1.33 +#include "memory/universe.inline.hpp"
    1.34 +#include "oops/method.hpp"
    1.35 +#include "oops/oop.inline.hpp"
    1.36 +#include "runtime/handles.inline.hpp"
    1.37 +#include "runtime/icache.hpp"
    1.38 +#include "runtime/interfaceSupport.hpp"
    1.39 +#include "runtime/signature.hpp"
    1.40 +#include "stack_zero.inline.hpp"
    1.41 +
    1.42 +void InterpreterRuntime::SignatureHandlerGeneratorBase::pass_int() {
    1.43 +  push(T_INT);
    1.44 +  _cif->nargs++;
    1.45 +}
    1.46 +
    1.47 +void InterpreterRuntime::SignatureHandlerGeneratorBase::pass_long() {
    1.48 +  push(T_LONG);
    1.49 +  _cif->nargs++;
    1.50 +}
    1.51 +
    1.52 +void InterpreterRuntime::SignatureHandlerGeneratorBase::pass_float() {
    1.53 +  push(T_FLOAT);
    1.54 +  _cif->nargs++;
    1.55 +}
    1.56 +
    1.57 +void InterpreterRuntime::SignatureHandlerGeneratorBase::pass_double() {
    1.58 +  push(T_DOUBLE);
    1.59 +  _cif->nargs++;
    1.60 +}
    1.61 +
    1.62 +void InterpreterRuntime::SignatureHandlerGeneratorBase::pass_object() {
    1.63 +  push(T_OBJECT);
    1.64 +  _cif->nargs++;
    1.65 +}
    1.66 +
    1.67 +void InterpreterRuntime::SignatureHandlerGeneratorBase::push(BasicType type) {
    1.68 +  ffi_type *ftype;
    1.69 +  switch (type) {
    1.70 +  case T_VOID:
    1.71 +    ftype = &ffi_type_void;
    1.72 +    break;
    1.73 +
    1.74 +  case T_BOOLEAN:
    1.75 +    ftype = &ffi_type_uint8;
    1.76 +    break;
    1.77 +
    1.78 +  case T_CHAR:
    1.79 +    ftype = &ffi_type_uint16;
    1.80 +    break;
    1.81 +
    1.82 +  case T_BYTE:
    1.83 +    ftype = &ffi_type_sint8;
    1.84 +    break;
    1.85 +
    1.86 +  case T_SHORT:
    1.87 +    ftype = &ffi_type_sint16;
    1.88 +    break;
    1.89 +
    1.90 +  case T_INT:
    1.91 +    ftype = &ffi_type_sint32;
    1.92 +    break;
    1.93 +
    1.94 +  case T_LONG:
    1.95 +    ftype = &ffi_type_sint64;
    1.96 +    break;
    1.97 +
    1.98 +  case T_FLOAT:
    1.99 +    ftype = &ffi_type_float;
   1.100 +    break;
   1.101 +
   1.102 +  case T_DOUBLE:
   1.103 +    ftype = &ffi_type_double;
   1.104 +    break;
   1.105 +
   1.106 +  case T_OBJECT:
   1.107 +  case T_ARRAY:
   1.108 +    ftype = &ffi_type_pointer;
   1.109 +    break;
   1.110 +
   1.111 +  default:
   1.112 +    ShouldNotReachHere();
   1.113 +  }
   1.114 +  push((intptr_t) ftype);
   1.115 +}
   1.116 +
   1.117 +// For fast signature handlers the "signature handler" is generated
   1.118 +// into a temporary buffer.  It is then copied to its final location,
   1.119 +// and pd_set_handler is called on it.  We have this two stage thing
   1.120 +// to accomodate this.
   1.121 +
   1.122 +void InterpreterRuntime::SignatureHandlerGeneratorBase::generate(
   1.123 +  uint64_t fingerprint) {
   1.124 +
   1.125 +  // Build the argument types list
   1.126 +  pass_object();
   1.127 +  if (method()->is_static())
   1.128 +    pass_object();
   1.129 +  iterate(fingerprint);
   1.130 +
   1.131 +  // Tack on the result type
   1.132 +  push(method()->result_type());
   1.133 +}
   1.134 +
   1.135 +void InterpreterRuntime::SignatureHandler::finalize() {
   1.136 +  ffi_status status =
   1.137 +    ffi_prep_cif(cif(),
   1.138 +                 FFI_DEFAULT_ABI,
   1.139 +                 argument_count(),
   1.140 +                 result_type(),
   1.141 +                 argument_types());
   1.142 +
   1.143 +  assert(status == FFI_OK, "should be");
   1.144 +}
   1.145 +
   1.146 +IRT_ENTRY(address,
   1.147 +          InterpreterRuntime::slow_signature_handler(JavaThread* thread,
   1.148 +                                                     Method*     method,
   1.149 +                                                     intptr_t*   unused1,
   1.150 +                                                     intptr_t*   unused2))
   1.151 +  ZeroStack *stack = thread->zero_stack();
   1.152 +
   1.153 +  int required_words =
   1.154 +    (align_size_up(sizeof(ffi_cif), wordSize) >> LogBytesPerWord) +
   1.155 +    (method->is_static() ? 2 : 1) + method->size_of_parameters() + 1;
   1.156 +
   1.157 +  stack->overflow_check(required_words, CHECK_NULL);
   1.158 +
   1.159 +  intptr_t *buf = (intptr_t *) stack->alloc(required_words * wordSize);
   1.160 +  SlowSignatureHandlerGenerator sshg(methodHandle(thread, method), buf);
   1.161 +  sshg.generate(UCONST64(-1));
   1.162 +
   1.163 +  SignatureHandler *handler = sshg.handler();
   1.164 +  handler->finalize();
   1.165 +
   1.166 +  return (address) handler;
   1.167 +IRT_END
   1.168 +
   1.169 +void SignatureHandlerLibrary::pd_set_handler(address handlerAddr) {
   1.170 +  InterpreterRuntime::SignatureHandler *handler =
   1.171 +    InterpreterRuntime::SignatureHandler::from_handlerAddr(handlerAddr);
   1.172 +
   1.173 +  handler->finalize();
   1.174 +}

mercurial