src/cpu/zero/vm/interpreterRT_zero.cpp

Wed, 22 Jan 2014 17:42:23 -0800

author
kvn
date
Wed, 22 Jan 2014 17:42:23 -0800
changeset 6503
a9becfeecd1b
parent 4037
da91efe96a93
child 6876
710a3c8b516e
permissions
-rw-r--r--

Merge

     1 /*
     2  * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * Copyright 2007, 2008, 2010 Red Hat, Inc.
     4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5  *
     6  * This code is free software; you can redistribute it and/or modify it
     7  * under the terms of the GNU General Public License version 2 only, as
     8  * published by the Free Software Foundation.
     9  *
    10  * This code is distributed in the hope that it will be useful, but WITHOUT
    11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    13  * version 2 for more details (a copy is included in the LICENSE file that
    14  * accompanied this code).
    15  *
    16  * You should have received a copy of the GNU General Public License version
    17  * 2 along with this work; if not, write to the Free Software Foundation,
    18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    19  *
    20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    21  * or visit www.oracle.com if you need additional information or have any
    22  * questions.
    23  *
    24  */
    26 #include "precompiled.hpp"
    27 #include "interpreter/interpreter.hpp"
    28 #include "interpreter/interpreterRuntime.hpp"
    29 #include "memory/allocation.inline.hpp"
    30 #include "memory/universe.inline.hpp"
    31 #include "oops/method.hpp"
    32 #include "oops/oop.inline.hpp"
    33 #include "runtime/handles.inline.hpp"
    34 #include "runtime/icache.hpp"
    35 #include "runtime/interfaceSupport.hpp"
    36 #include "runtime/signature.hpp"
    37 #include "stack_zero.inline.hpp"
    39 void InterpreterRuntime::SignatureHandlerGeneratorBase::pass_int() {
    40   push(T_INT);
    41   _cif->nargs++;
    42 }
    44 void InterpreterRuntime::SignatureHandlerGeneratorBase::pass_long() {
    45   push(T_LONG);
    46   _cif->nargs++;
    47 }
    49 void InterpreterRuntime::SignatureHandlerGeneratorBase::pass_float() {
    50   push(T_FLOAT);
    51   _cif->nargs++;
    52 }
    54 void InterpreterRuntime::SignatureHandlerGeneratorBase::pass_double() {
    55   push(T_DOUBLE);
    56   _cif->nargs++;
    57 }
    59 void InterpreterRuntime::SignatureHandlerGeneratorBase::pass_object() {
    60   push(T_OBJECT);
    61   _cif->nargs++;
    62 }
    64 void InterpreterRuntime::SignatureHandlerGeneratorBase::push(BasicType type) {
    65   ffi_type *ftype;
    66   switch (type) {
    67   case T_VOID:
    68     ftype = &ffi_type_void;
    69     break;
    71   case T_BOOLEAN:
    72     ftype = &ffi_type_uint8;
    73     break;
    75   case T_CHAR:
    76     ftype = &ffi_type_uint16;
    77     break;
    79   case T_BYTE:
    80     ftype = &ffi_type_sint8;
    81     break;
    83   case T_SHORT:
    84     ftype = &ffi_type_sint16;
    85     break;
    87   case T_INT:
    88     ftype = &ffi_type_sint32;
    89     break;
    91   case T_LONG:
    92     ftype = &ffi_type_sint64;
    93     break;
    95   case T_FLOAT:
    96     ftype = &ffi_type_float;
    97     break;
    99   case T_DOUBLE:
   100     ftype = &ffi_type_double;
   101     break;
   103   case T_OBJECT:
   104   case T_ARRAY:
   105     ftype = &ffi_type_pointer;
   106     break;
   108   default:
   109     ShouldNotReachHere();
   110   }
   111   push((intptr_t) ftype);
   112 }
   114 // For fast signature handlers the "signature handler" is generated
   115 // into a temporary buffer.  It is then copied to its final location,
   116 // and pd_set_handler is called on it.  We have this two stage thing
   117 // to accomodate this.
   119 void InterpreterRuntime::SignatureHandlerGeneratorBase::generate(
   120   uint64_t fingerprint) {
   122   // Build the argument types list
   123   pass_object();
   124   if (method()->is_static())
   125     pass_object();
   126   iterate(fingerprint);
   128   // Tack on the result type
   129   push(method()->result_type());
   130 }
   132 void InterpreterRuntime::SignatureHandler::finalize() {
   133   ffi_status status =
   134     ffi_prep_cif(cif(),
   135                  FFI_DEFAULT_ABI,
   136                  argument_count(),
   137                  result_type(),
   138                  argument_types());
   140   assert(status == FFI_OK, "should be");
   141 }
   143 IRT_ENTRY(address,
   144           InterpreterRuntime::slow_signature_handler(JavaThread* thread,
   145                                                      Method*     method,
   146                                                      intptr_t*   unused1,
   147                                                      intptr_t*   unused2))
   148   ZeroStack *stack = thread->zero_stack();
   150   int required_words =
   151     (align_size_up(sizeof(ffi_cif), wordSize) >> LogBytesPerWord) +
   152     (method->is_static() ? 2 : 1) + method->size_of_parameters() + 1;
   154   stack->overflow_check(required_words, CHECK_NULL);
   156   intptr_t *buf = (intptr_t *) stack->alloc(required_words * wordSize);
   157   SlowSignatureHandlerGenerator sshg(methodHandle(thread, method), buf);
   158   sshg.generate(UCONST64(-1));
   160   SignatureHandler *handler = sshg.handler();
   161   handler->finalize();
   163   return (address) handler;
   164 IRT_END
   166 void SignatureHandlerLibrary::pd_set_handler(address handlerAddr) {
   167   InterpreterRuntime::SignatureHandler *handler =
   168     InterpreterRuntime::SignatureHandler::from_handlerAddr(handlerAddr);
   170   handler->finalize();
   171 }

mercurial