src/share/vm/runtime/javaCalls.hpp

changeset 435
a61af66fc99e
child 900
dc16daa0329d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/runtime/javaCalls.hpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,195 @@
     1.4 +/*
     1.5 + * Copyright 1997-2005 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +// A JavaCallWrapper is constructed before each JavaCall and destructed after the call.
    1.29 +// Its purpose is to allocate/deallocate a new handle block and to save/restore the last
    1.30 +// Java fp/sp. A pointer to the JavaCallWrapper is stored on the stack.
    1.31 +
    1.32 +class JavaCallWrapper: StackObj {
    1.33 +  friend class VMStructs;
    1.34 + private:
    1.35 +  JavaThread*      _thread;                 // the thread to which this call belongs
    1.36 +  JNIHandleBlock*  _handles;                // the saved handle block
    1.37 +  methodOop        _callee_method;          // to be able to collect arguments if entry frame is top frame
    1.38 +  oop              _receiver;               // the receiver of the call (if a non-static call)
    1.39 +
    1.40 +  JavaFrameAnchor  _anchor;                 // last thread anchor state that we must restore
    1.41 +
    1.42 +  JavaValue*       _result;                 // result value
    1.43 +
    1.44 + public:
    1.45 +  // Construction/destruction
    1.46 +   JavaCallWrapper(methodHandle callee_method, Handle receiver, JavaValue* result, TRAPS);
    1.47 +  ~JavaCallWrapper();
    1.48 +
    1.49 +  // Accessors
    1.50 +  JavaThread*      thread() const           { return _thread; }
    1.51 +  JNIHandleBlock*  handles() const          { return _handles; }
    1.52 +
    1.53 +  JavaFrameAnchor* anchor(void)             { return &_anchor; }
    1.54 +
    1.55 +  JavaValue*       result() const           { return _result; }
    1.56 +  // GC support
    1.57 +  methodOop        callee_method()          { return _callee_method; }
    1.58 +  oop              receiver()               { return _receiver; }
    1.59 +  void             oops_do(OopClosure* f);
    1.60 +
    1.61 +};
    1.62 +
    1.63 +
    1.64 +// Encapsulates arguments to a JavaCall (faster, safer, and more convenient than using var-args)
    1.65 +class JavaCallArguments : public StackObj {
    1.66 + private:
    1.67 +  enum Constants {
    1.68 +   _default_size = 8    // Must be at least # of arguments in JavaCalls methods
    1.69 +  };
    1.70 +
    1.71 +  intptr_t    _value_buffer [_default_size + 1];
    1.72 +  intptr_t    _parameter_buffer [_default_size*2 + 1];
    1.73 +  bool        _is_oop_buffer[_default_size + 1];
    1.74 +
    1.75 +  intptr_t*   _value;
    1.76 +  intptr_t*   _parameters;
    1.77 +  bool*       _is_oop;
    1.78 +  int         _size;
    1.79 +  int         _max_size;
    1.80 +  bool        _start_at_zero;      // Support late setting of receiver
    1.81 +
    1.82 +  void initialize() {
    1.83 +    // Starts at first element to support set_receiver.
    1.84 +    _value    = &_value_buffer[1];
    1.85 +    _is_oop   = &_is_oop_buffer[1];
    1.86 +
    1.87 +    _parameters = &_parameter_buffer[0];
    1.88 +    _max_size = _default_size;
    1.89 +    _size = 0;
    1.90 +    _start_at_zero = false;
    1.91 +  }
    1.92 +
    1.93 + public:
    1.94 +  JavaCallArguments() { initialize(); }
    1.95 +
    1.96 +  JavaCallArguments(Handle receiver) {
    1.97 +    initialize();
    1.98 +    push_oop(receiver);
    1.99 +  }
   1.100 +
   1.101 +  JavaCallArguments(int max_size) {
   1.102 +    if (max_size > _default_size) {
   1.103 +      _value  = NEW_RESOURCE_ARRAY(intptr_t, max_size + 1);
   1.104 +      _is_oop = NEW_RESOURCE_ARRAY(bool, max_size + 1);
   1.105 +      if (TaggedStackInterpreter) {
   1.106 +        _parameters  = NEW_RESOURCE_ARRAY(intptr_t, max_size*2 + 1);
   1.107 +      }
   1.108 +      // Reserve room for potential receiver in value and is_oop
   1.109 +      _value++; _is_oop++;
   1.110 +      _max_size = max_size;
   1.111 +      _size = 0;
   1.112 +      _start_at_zero = false;
   1.113 +    } else {
   1.114 +      initialize();
   1.115 +    }
   1.116 +  }
   1.117 +
   1.118 +  inline void push_oop(Handle h)    { _is_oop[_size] = true;
   1.119 +                               JNITypes::put_obj((oop)h.raw_value(), _value, _size); }
   1.120 +
   1.121 +  inline void push_int(int i)       { _is_oop[_size] = false;
   1.122 +                               JNITypes::put_int(i, _value, _size); }
   1.123 +
   1.124 +  inline void push_double(double d) { _is_oop[_size] = false; _is_oop[_size + 1] = false;
   1.125 +                               JNITypes::put_double(d, _value, _size); }
   1.126 +
   1.127 +  inline void push_long(jlong l)    { _is_oop[_size] = false; _is_oop[_size + 1] = false;
   1.128 +                               JNITypes::put_long(l, _value, _size); }
   1.129 +
   1.130 +  inline void push_float(float f)   { _is_oop[_size] = false;
   1.131 +                               JNITypes::put_float(f, _value, _size); }
   1.132 +
   1.133 +  // receiver
   1.134 +  Handle receiver() {
   1.135 +    assert(_size > 0, "must at least be one argument");
   1.136 +    assert(_is_oop[0], "first argument must be an oop");
   1.137 +    assert(_value[0] != 0, "receiver must be not-null");
   1.138 +    return Handle((oop*)_value[0], false);
   1.139 +  }
   1.140 +
   1.141 +  void set_receiver(Handle h) {
   1.142 +    assert(_start_at_zero == false, "can only be called once");
   1.143 +    _start_at_zero = true;
   1.144 +    _is_oop--;
   1.145 +    _value--;
   1.146 +    _size++;
   1.147 +    _is_oop[0] = true;
   1.148 +    _value[0] = (intptr_t)h.raw_value();
   1.149 +  }
   1.150 +
   1.151 +  // Converts all Handles to oops, and returns a reference to parameter vector
   1.152 +  intptr_t* parameters() ;
   1.153 +  int   size_of_parameters() const { return _size; }
   1.154 +
   1.155 +  // Verify that pushed arguments fits a given method
   1.156 +  void verify(methodHandle method, BasicType return_type, Thread *thread) PRODUCT_RETURN;
   1.157 +};
   1.158 +
   1.159 +// All calls to Java have to go via JavaCalls. Sets up the stack frame
   1.160 +// and makes sure that the last_Java_frame pointers are chained correctly.
   1.161 +//
   1.162 +
   1.163 +class JavaCalls: AllStatic {
   1.164 +  static void call_helper(JavaValue* result, methodHandle* method, JavaCallArguments* args, TRAPS);
   1.165 + public:
   1.166 +  // Optimized Constuctor call
   1.167 +  static void call_default_constructor(JavaThread* thread, methodHandle method, Handle receiver, TRAPS);
   1.168 +
   1.169 +  // call_special
   1.170 +  // ------------
   1.171 +  // The receiver must be first oop in argument list
   1.172 +  static void call_special(JavaValue* result, KlassHandle klass, symbolHandle name, symbolHandle signature, JavaCallArguments* args, TRAPS);
   1.173 +
   1.174 +  static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, symbolHandle name, symbolHandle signature, TRAPS); // No args
   1.175 +  static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, symbolHandle name, symbolHandle signature, Handle arg1, TRAPS);
   1.176 +  static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, symbolHandle name, symbolHandle signature, Handle arg1, Handle arg2, TRAPS);
   1.177 +
   1.178 +  // virtual call
   1.179 +  // ------------
   1.180 +
   1.181 +  // The receiver must be first oop in argument list
   1.182 +  static void call_virtual(JavaValue* result, KlassHandle spec_klass, symbolHandle name, symbolHandle signature, JavaCallArguments* args, TRAPS);
   1.183 +
   1.184 +  static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, symbolHandle name, symbolHandle signature, TRAPS); // No args
   1.185 +  static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, symbolHandle name, symbolHandle signature, Handle arg1, TRAPS);
   1.186 +  static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, symbolHandle name, symbolHandle signature, Handle arg1, Handle arg2, TRAPS);
   1.187 +
   1.188 +  // Static call
   1.189 +  // -----------
   1.190 +  static void call_static(JavaValue* result, KlassHandle klass, symbolHandle name, symbolHandle signature, JavaCallArguments* args, TRAPS);
   1.191 +
   1.192 +  static void call_static(JavaValue* result, KlassHandle klass, symbolHandle name, symbolHandle signature, TRAPS);
   1.193 +  static void call_static(JavaValue* result, KlassHandle klass, symbolHandle name, symbolHandle signature, Handle arg1, TRAPS);
   1.194 +  static void call_static(JavaValue* result, KlassHandle klass, symbolHandle name, symbolHandle signature, Handle arg1, Handle arg2, TRAPS);
   1.195 +
   1.196 +  // Low-level interface
   1.197 +  static void call(JavaValue* result, methodHandle method, JavaCallArguments* args, TRAPS);
   1.198 +};

mercurial