src/share/vm/runtime/javaCalls.hpp

Wed, 14 Oct 2020 17:44:48 +0800

author
aoqi
date
Wed, 14 Oct 2020 17:44:48 +0800
changeset 9931
fd44df5e3bc3
parent 9703
2fdf635bcf28
permissions
-rw-r--r--

Merge

     1 /*
     2  * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 /*
    26  * This file has been modified by Loongson Technology in 2015. These
    27  * modifications are Copyright (c) 2015 Loongson Technology, and are made
    28  * available on the same license terms set forth above.
    29  */
    31 #ifndef SHARE_VM_RUNTIME_JAVACALLS_HPP
    32 #define SHARE_VM_RUNTIME_JAVACALLS_HPP
    34 #include "memory/allocation.hpp"
    35 #include "oops/method.hpp"
    36 #include "runtime/handles.hpp"
    37 #include "runtime/javaFrameAnchor.hpp"
    38 #include "runtime/thread.inline.hpp"
    39 #include "runtime/vmThread.hpp"
    40 #ifdef TARGET_ARCH_x86
    41 # include "jniTypes_x86.hpp"
    42 #endif
    43 #ifdef TARGET_ARCH_sparc
    44 # include "jniTypes_sparc.hpp"
    45 #endif
    46 #ifdef TARGET_ARCH_zero
    47 # include "jniTypes_zero.hpp"
    48 #endif
    49 #ifdef TARGET_ARCH_arm
    50 # include "jniTypes_arm.hpp"
    51 #endif
    52 #ifdef TARGET_ARCH_ppc
    53 # include "jniTypes_ppc.hpp"
    54 #endif
    55 #ifdef TARGET_ARCH_mips
    56 # include "jniTypes_mips.hpp"
    57 #endif
    59 // A JavaCallWrapper is constructed before each JavaCall and destructed after the call.
    60 // Its purpose is to allocate/deallocate a new handle block and to save/restore the last
    61 // Java fp/sp. A pointer to the JavaCallWrapper is stored on the stack.
    63 class JavaCallWrapper: StackObj {
    64   friend class VMStructs;
    65  private:
    66   JavaThread*      _thread;                 // the thread to which this call belongs
    67   JNIHandleBlock*  _handles;                // the saved handle block
    68   Method*          _callee_method;          // to be able to collect arguments if entry frame is top frame
    69   oop              _receiver;               // the receiver of the call (if a non-static call)
    71   JavaFrameAnchor  _anchor;                 // last thread anchor state that we must restore
    73   JavaValue*       _result;                 // result value
    75  public:
    76   // Construction/destruction
    77    JavaCallWrapper(methodHandle callee_method, Handle receiver, JavaValue* result, TRAPS);
    78   ~JavaCallWrapper();
    80   // Accessors
    81   JavaThread*      thread() const           { return _thread; }
    82   JNIHandleBlock*  handles() const          { return _handles; }
    84   JavaFrameAnchor* anchor(void)             { return &_anchor; }
    86   JavaValue*       result() const           { return _result; }
    87   // GC support
    88   Method*          callee_method()          { return _callee_method; }
    89   oop              receiver()               { return _receiver; }
    90   void             oops_do(OopClosure* f);
    92   bool             is_first_frame() const   { return _anchor.last_Java_sp() == NULL; }
    94 };
    97 // Encapsulates arguments to a JavaCall (faster, safer, and more convenient than using var-args)
    98 class JavaCallArguments : public StackObj {
    99  private:
   100   enum Constants {
   101    _default_size = 8    // Must be at least # of arguments in JavaCalls methods
   102   };
   104   intptr_t    _value_buffer      [_default_size + 1];
   105   u_char      _value_state_buffer[_default_size + 1];
   107   intptr_t*   _value;
   108   u_char*     _value_state;
   109   int         _size;
   110   int         _max_size;
   111   bool        _start_at_zero;      // Support late setting of receiver
   113   void initialize() {
   114     // Starts at first element to support set_receiver.
   115     _value       = &_value_buffer[1];
   116     _value_state = &_value_state_buffer[1];
   118     _max_size = _default_size;
   119     _size = 0;
   120     _start_at_zero = false;
   121   }
   123   // Helper for push_oop and the like.  The value argument is a
   124   // "handle" that refers to an oop.  We record the address of the
   125   // handle rather than the designated oop.  The handle is later
   126   // resolved to the oop by parameters().  This delays the exposure of
   127   // naked oops until it is GC-safe.
   128   template<typename T>
   129   inline int push_oop_impl(T handle, int size) {
   130     // JNITypes::put_obj expects an oop value, so we play fast and
   131     // loose with the type system.  The cast from handle type to oop
   132     // *must* use a C-style cast.  In a product build it performs a
   133     // reinterpret_cast. In a debug build (more accurately, in a
   134     // CHECK_UNHANDLED_OOPS build) it performs a static_cast, invoking
   135     // the debug-only oop class's conversion from void* constructor.
   136     JNITypes::put_obj((oop)handle, _value, size); // Updates size.
   137     return size;                // Return the updated size.
   138   }
   140  public:
   141   JavaCallArguments() { initialize(); }
   143   JavaCallArguments(Handle receiver) {
   144     initialize();
   145     push_oop(receiver);
   146   }
   148   JavaCallArguments(int max_size) {
   149     if (max_size > _default_size) {
   150       _value = NEW_RESOURCE_ARRAY(intptr_t, max_size + 1);
   151       _value_state = NEW_RESOURCE_ARRAY(u_char, max_size + 1);
   153       // Reserve room for potential receiver in value and state
   154       _value++;
   155       _value_state++;
   157       _max_size = max_size;
   158       _size = 0;
   159       _start_at_zero = false;
   160     } else {
   161       initialize();
   162     }
   163   }
   165   // The possible values for _value_state elements.
   166   enum {
   167     value_state_primitive,
   168     value_state_oop,
   169     value_state_handle,
   170     value_state_jobject,
   171     value_state_limit
   172   };
   174   inline void push_oop(Handle h) {
   175     _value_state[_size] = value_state_handle;
   176     _size = push_oop_impl(h.raw_value(), _size);
   177   }
   179   inline void push_jobject(jobject h) {
   180     _value_state[_size] = value_state_jobject;
   181     _size = push_oop_impl(h, _size);
   182   }
   184   inline void push_int(int i) {
   185     _value_state[_size] = value_state_primitive;
   186     JNITypes::put_int(i, _value, _size);
   187   }
   189   inline void push_double(double d) {
   190     _value_state[_size] = value_state_primitive;
   191     _value_state[_size + 1] = value_state_primitive;
   192     JNITypes::put_double(d, _value, _size);
   193   }
   195   inline void push_long(jlong l) {
   196     _value_state[_size] = value_state_primitive;
   197     _value_state[_size + 1] = value_state_primitive;
   198     JNITypes::put_long(l, _value, _size);
   199   }
   201   inline void push_float(float f) {
   202     _value_state[_size] = value_state_primitive;
   203     JNITypes::put_float(f, _value, _size);
   204   }
   206   // receiver
   207   Handle receiver() {
   208     assert(_size > 0, "must at least be one argument");
   209     assert(_value_state[0] == value_state_handle,
   210            "first argument must be an oop");
   211     assert(_value[0] != 0, "receiver must be not-null");
   212     return Handle((oop*)_value[0], false);
   213   }
   215   void set_receiver(Handle h) {
   216     assert(_start_at_zero == false, "can only be called once");
   217     _start_at_zero = true;
   218     _value_state--;
   219     _value--;
   220     _size++;
   221     _value_state[0] = value_state_handle;
   222     push_oop_impl(h.raw_value(), 0);
   223   }
   225   // Converts all Handles to oops, and returns a reference to parameter vector
   226   intptr_t* parameters() ;
   227   int   size_of_parameters() const { return _size; }
   229   // Verify that pushed arguments fits a given method
   230   void verify(methodHandle method, BasicType return_type);
   231 };
   233 // All calls to Java have to go via JavaCalls. Sets up the stack frame
   234 // and makes sure that the last_Java_frame pointers are chained correctly.
   235 //
   237 class JavaCalls: AllStatic {
   238   static void call_helper(JavaValue* result, methodHandle* method, JavaCallArguments* args, TRAPS);
   239  public:
   240   // Optimized Constuctor call
   241   static void call_default_constructor(JavaThread* thread, methodHandle method, Handle receiver, TRAPS);
   243   // call_special
   244   // ------------
   245   // The receiver must be first oop in argument list
   246   static void call_special(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS);
   248   static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS); // No args
   249   static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS);
   250   static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS);
   252   // virtual call
   253   // ------------
   255   // The receiver must be first oop in argument list
   256   static void call_virtual(JavaValue* result, KlassHandle spec_klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS);
   258   static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, TRAPS); // No args
   259   static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS);
   260   static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS);
   262   // Static call
   263   // -----------
   264   static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS);
   266   static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
   267   static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS);
   268   static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS);
   270   // Low-level interface
   271   static void call(JavaValue* result, methodHandle method, JavaCallArguments* args, TRAPS);
   272 };
   274 #endif // SHARE_VM_RUNTIME_JAVACALLS_HPP

mercurial