annotate src/share/vm/runtime/javaCalls.hpp @ 1145:e018e6884bd8

6631166: CMS: better heuristics when combatting fragmentation Summary: Autonomic per-worker free block cache sizing, tunable coalition policies, fixes to per-size block statistics, retuned gain and bandwidth of some feedback loop filters to allow quicker reactivity to abrupt changes in ambient demand, and other heuristics to reduce fragmentation of the CMS old gen. Also tightened some assertions, including those related to locking. Reviewed-by: jmasa
author ysr
date Wed, 23 Dec 2009 09:23:54 -0800
parents ad8c8ca4ab0f
children 6223633ce7dd 2338d41fbd81
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
470
ad8c8ca4ab0f 6785258: Update copyright year
xdono
parents: 465
diff changeset
2 * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 // A JavaCallWrapper is constructed before each JavaCall and destructed after the call.
a61af66fc99e Initial load
duke
parents:
diff changeset
26 // Its purpose is to allocate/deallocate a new handle block and to save/restore the last
a61af66fc99e Initial load
duke
parents:
diff changeset
27 // Java fp/sp. A pointer to the JavaCallWrapper is stored on the stack.
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 class JavaCallWrapper: StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
30 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
32 JavaThread* _thread; // the thread to which this call belongs
a61af66fc99e Initial load
duke
parents:
diff changeset
33 JNIHandleBlock* _handles; // the saved handle block
a61af66fc99e Initial load
duke
parents:
diff changeset
34 methodOop _callee_method; // to be able to collect arguments if entry frame is top frame
a61af66fc99e Initial load
duke
parents:
diff changeset
35 oop _receiver; // the receiver of the call (if a non-static call)
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 JavaFrameAnchor _anchor; // last thread anchor state that we must restore
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 JavaValue* _result; // result value
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // Construction/destruction
a61af66fc99e Initial load
duke
parents:
diff changeset
43 JavaCallWrapper(methodHandle callee_method, Handle receiver, JavaValue* result, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
44 ~JavaCallWrapper();
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // Accessors
a61af66fc99e Initial load
duke
parents:
diff changeset
47 JavaThread* thread() const { return _thread; }
a61af66fc99e Initial load
duke
parents:
diff changeset
48 JNIHandleBlock* handles() const { return _handles; }
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 JavaFrameAnchor* anchor(void) { return &_anchor; }
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 JavaValue* result() const { return _result; }
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // GC support
a61af66fc99e Initial load
duke
parents:
diff changeset
54 methodOop callee_method() { return _callee_method; }
a61af66fc99e Initial load
duke
parents:
diff changeset
55 oop receiver() { return _receiver; }
a61af66fc99e Initial load
duke
parents:
diff changeset
56 void oops_do(OopClosure* f);
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 };
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 // Encapsulates arguments to a JavaCall (faster, safer, and more convenient than using var-args)
a61af66fc99e Initial load
duke
parents:
diff changeset
62 class JavaCallArguments : public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
63 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
64 enum Constants {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 _default_size = 8 // Must be at least # of arguments in JavaCalls methods
a61af66fc99e Initial load
duke
parents:
diff changeset
66 };
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 intptr_t _value_buffer [_default_size + 1];
a61af66fc99e Initial load
duke
parents:
diff changeset
69 intptr_t _parameter_buffer [_default_size*2 + 1];
a61af66fc99e Initial load
duke
parents:
diff changeset
70 bool _is_oop_buffer[_default_size + 1];
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 intptr_t* _value;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 intptr_t* _parameters;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 bool* _is_oop;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 int _size;
a61af66fc99e Initial load
duke
parents:
diff changeset
76 int _max_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
77 bool _start_at_zero; // Support late setting of receiver
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 void initialize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // Starts at first element to support set_receiver.
a61af66fc99e Initial load
duke
parents:
diff changeset
81 _value = &_value_buffer[1];
a61af66fc99e Initial load
duke
parents:
diff changeset
82 _is_oop = &_is_oop_buffer[1];
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 _parameters = &_parameter_buffer[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
85 _max_size = _default_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
86 _size = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
87 _start_at_zero = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 }
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
91 JavaCallArguments() { initialize(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 JavaCallArguments(Handle receiver) {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 initialize();
a61af66fc99e Initial load
duke
parents:
diff changeset
95 push_oop(receiver);
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97
a61af66fc99e Initial load
duke
parents:
diff changeset
98 JavaCallArguments(int max_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
99 if (max_size > _default_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 _value = NEW_RESOURCE_ARRAY(intptr_t, max_size + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
101 _is_oop = NEW_RESOURCE_ARRAY(bool, max_size + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
102 if (TaggedStackInterpreter) {
a61af66fc99e Initial load
duke
parents:
diff changeset
103 _parameters = NEW_RESOURCE_ARRAY(intptr_t, max_size*2 + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
104 }
a61af66fc99e Initial load
duke
parents:
diff changeset
105 // Reserve room for potential receiver in value and is_oop
a61af66fc99e Initial load
duke
parents:
diff changeset
106 _value++; _is_oop++;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 _max_size = max_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
108 _size = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 _start_at_zero = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
110 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 initialize();
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 inline void push_oop(Handle h) { _is_oop[_size] = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 JNITypes::put_obj((oop)h.raw_value(), _value, _size); }
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 inline void push_int(int i) { _is_oop[_size] = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
119 JNITypes::put_int(i, _value, _size); }
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 inline void push_double(double d) { _is_oop[_size] = false; _is_oop[_size + 1] = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
122 JNITypes::put_double(d, _value, _size); }
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 inline void push_long(jlong l) { _is_oop[_size] = false; _is_oop[_size + 1] = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
125 JNITypes::put_long(l, _value, _size); }
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 inline void push_float(float f) { _is_oop[_size] = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 JNITypes::put_float(f, _value, _size); }
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 // receiver
a61af66fc99e Initial load
duke
parents:
diff changeset
131 Handle receiver() {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 assert(_size > 0, "must at least be one argument");
a61af66fc99e Initial load
duke
parents:
diff changeset
133 assert(_is_oop[0], "first argument must be an oop");
a61af66fc99e Initial load
duke
parents:
diff changeset
134 assert(_value[0] != 0, "receiver must be not-null");
a61af66fc99e Initial load
duke
parents:
diff changeset
135 return Handle((oop*)_value[0], false);
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 void set_receiver(Handle h) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 assert(_start_at_zero == false, "can only be called once");
a61af66fc99e Initial load
duke
parents:
diff changeset
140 _start_at_zero = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 _is_oop--;
a61af66fc99e Initial load
duke
parents:
diff changeset
142 _value--;
a61af66fc99e Initial load
duke
parents:
diff changeset
143 _size++;
a61af66fc99e Initial load
duke
parents:
diff changeset
144 _is_oop[0] = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
145 _value[0] = (intptr_t)h.raw_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // Converts all Handles to oops, and returns a reference to parameter vector
a61af66fc99e Initial load
duke
parents:
diff changeset
149 intptr_t* parameters() ;
a61af66fc99e Initial load
duke
parents:
diff changeset
150 int size_of_parameters() const { return _size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // Verify that pushed arguments fits a given method
465
dc16daa0329d 6739363: Xcheck jni doesn't check native function arguments
poonam
parents: 0
diff changeset
153 void verify(methodHandle method, BasicType return_type, Thread *thread);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
154 };
a61af66fc99e Initial load
duke
parents:
diff changeset
155
a61af66fc99e Initial load
duke
parents:
diff changeset
156 // All calls to Java have to go via JavaCalls. Sets up the stack frame
a61af66fc99e Initial load
duke
parents:
diff changeset
157 // and makes sure that the last_Java_frame pointers are chained correctly.
a61af66fc99e Initial load
duke
parents:
diff changeset
158 //
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 class JavaCalls: AllStatic {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 static void call_helper(JavaValue* result, methodHandle* method, JavaCallArguments* args, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
162 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
163 // Optimized Constuctor call
a61af66fc99e Initial load
duke
parents:
diff changeset
164 static void call_default_constructor(JavaThread* thread, methodHandle method, Handle receiver, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 // call_special
a61af66fc99e Initial load
duke
parents:
diff changeset
167 // ------------
a61af66fc99e Initial load
duke
parents:
diff changeset
168 // The receiver must be first oop in argument list
a61af66fc99e Initial load
duke
parents:
diff changeset
169 static void call_special(JavaValue* result, KlassHandle klass, symbolHandle name, symbolHandle signature, JavaCallArguments* args, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171 static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, symbolHandle name, symbolHandle signature, TRAPS); // No args
a61af66fc99e Initial load
duke
parents:
diff changeset
172 static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, symbolHandle name, symbolHandle signature, Handle arg1, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
173 static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, symbolHandle name, symbolHandle signature, Handle arg1, Handle arg2, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 // virtual call
a61af66fc99e Initial load
duke
parents:
diff changeset
176 // ------------
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 // The receiver must be first oop in argument list
a61af66fc99e Initial load
duke
parents:
diff changeset
179 static void call_virtual(JavaValue* result, KlassHandle spec_klass, symbolHandle name, symbolHandle signature, JavaCallArguments* args, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
180
a61af66fc99e Initial load
duke
parents:
diff changeset
181 static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, symbolHandle name, symbolHandle signature, TRAPS); // No args
a61af66fc99e Initial load
duke
parents:
diff changeset
182 static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, symbolHandle name, symbolHandle signature, Handle arg1, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
183 static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, symbolHandle name, symbolHandle signature, Handle arg1, Handle arg2, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185 // Static call
a61af66fc99e Initial load
duke
parents:
diff changeset
186 // -----------
a61af66fc99e Initial load
duke
parents:
diff changeset
187 static void call_static(JavaValue* result, KlassHandle klass, symbolHandle name, symbolHandle signature, JavaCallArguments* args, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
188
a61af66fc99e Initial load
duke
parents:
diff changeset
189 static void call_static(JavaValue* result, KlassHandle klass, symbolHandle name, symbolHandle signature, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
190 static void call_static(JavaValue* result, KlassHandle klass, symbolHandle name, symbolHandle signature, Handle arg1, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
191 static void call_static(JavaValue* result, KlassHandle klass, symbolHandle name, symbolHandle signature, Handle arg1, Handle arg2, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
192
a61af66fc99e Initial load
duke
parents:
diff changeset
193 // Low-level interface
a61af66fc99e Initial load
duke
parents:
diff changeset
194 static void call(JavaValue* result, methodHandle method, JavaCallArguments* args, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
195 };