author | coleenp |
Mon, 17 Nov 2014 11:26:43 -0500 | |
changeset 27667 | 3c814b51da6c |
parent 27612 | 7201412afbd0 |
child 27674 | 00cabfc45357 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
22753
749328896281
8028073: race condition in ObjectMonitor implementation causing deadlocks
dcubed
parents:
22189
diff
changeset
|
2 |
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5089
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5089
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5089
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "classfile/classLoader.hpp" |
|
27 |
#include "classfile/javaAssertions.hpp" |
|
28 |
#include "classfile/javaClasses.hpp" |
|
24426
0a69c8cdfca9
8038654: Separate SymbolTable and StringTable code
gziemski
parents:
24242
diff
changeset
|
29 |
#include "classfile/stringTable.hpp" |
7397 | 30 |
#include "classfile/systemDictionary.hpp" |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25716
diff
changeset
|
31 |
#if INCLUDE_CDS |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25716
diff
changeset
|
32 |
#include "classfile/sharedClassUtil.hpp" |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25716
diff
changeset
|
33 |
#include "classfile/systemDictionaryShared.hpp" |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25716
diff
changeset
|
34 |
#endif |
7397 | 35 |
#include "classfile/vmSymbols.hpp" |
36 |
#include "gc_interface/collectedHeap.inline.hpp" |
|
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
37 |
#include "interpreter/bytecode.hpp" |
7397 | 38 |
#include "memory/oopFactory.hpp" |
39 |
#include "memory/universe.inline.hpp" |
|
10546 | 40 |
#include "oops/fieldStreams.hpp" |
7397 | 41 |
#include "oops/instanceKlass.hpp" |
42 |
#include "oops/objArrayKlass.hpp" |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
43 |
#include "oops/method.hpp" |
7397 | 44 |
#include "prims/jvm.h" |
45 |
#include "prims/jvm_misc.hpp" |
|
46 |
#include "prims/jvmtiExport.hpp" |
|
47 |
#include "prims/jvmtiThreadState.hpp" |
|
48 |
#include "prims/nativeLookup.hpp" |
|
49 |
#include "prims/privilegedStack.hpp" |
|
50 |
#include "runtime/arguments.hpp" |
|
25351
7c198a690050
8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents:
25057
diff
changeset
|
51 |
#include "runtime/atomic.inline.hpp" |
7397 | 52 |
#include "runtime/dtraceJSDT.hpp" |
53 |
#include "runtime/handles.inline.hpp" |
|
54 |
#include "runtime/init.hpp" |
|
55 |
#include "runtime/interfaceSupport.hpp" |
|
56 |
#include "runtime/java.hpp" |
|
57 |
#include "runtime/javaCalls.hpp" |
|
58 |
#include "runtime/jfieldIDWorkaround.hpp" |
|
24351
61b33cc6d3cf
8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents:
24242
diff
changeset
|
59 |
#include "runtime/orderAccess.inline.hpp" |
25468
5331df506290
8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents:
25351
diff
changeset
|
60 |
#include "runtime/os.inline.hpp" |
7397 | 61 |
#include "runtime/perfData.hpp" |
62 |
#include "runtime/reflection.hpp" |
|
25351
7c198a690050
8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents:
25057
diff
changeset
|
63 |
#include "runtime/thread.inline.hpp" |
7397 | 64 |
#include "runtime/vframe.hpp" |
65 |
#include "runtime/vm_operations.hpp" |
|
25715
d5a8dbdc5150
8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents:
25468
diff
changeset
|
66 |
#include "runtime/vm_version.hpp" |
7397 | 67 |
#include "services/attachListener.hpp" |
68 |
#include "services/management.hpp" |
|
69 |
#include "services/threadService.hpp" |
|
18025 | 70 |
#include "trace/tracing.hpp" |
7397 | 71 |
#include "utilities/copy.hpp" |
72 |
#include "utilities/defaultStream.hpp" |
|
73 |
#include "utilities/dtrace.hpp" |
|
74 |
#include "utilities/events.hpp" |
|
75 |
#include "utilities/histogram.hpp" |
|
76 |
#include "utilities/top.hpp" |
|
77 |
#include "utilities/utf8.hpp" |
|
78 |
#ifdef TARGET_OS_FAMILY_linux |
|
79 |
# include "jvm_linux.h" |
|
80 |
#endif |
|
81 |
#ifdef TARGET_OS_FAMILY_solaris |
|
82 |
# include "jvm_solaris.h" |
|
83 |
#endif |
|
84 |
#ifdef TARGET_OS_FAMILY_windows |
|
85 |
# include "jvm_windows.h" |
|
86 |
#endif |
|
22827 | 87 |
#ifdef TARGET_OS_FAMILY_aix |
88 |
# include "jvm_aix.h" |
|
89 |
#endif |
|
10565 | 90 |
#ifdef TARGET_OS_FAMILY_bsd |
91 |
# include "jvm_bsd.h" |
|
92 |
#endif |
|
7397 | 93 |
|
1 | 94 |
#include <errno.h> |
95 |
||
96 |
/* |
|
97 |
NOTE about use of any ctor or function call that can trigger a safepoint/GC: |
|
98 |
such ctors and calls MUST NOT come between an oop declaration/init and its |
|
99 |
usage because if objects are move this may cause various memory stomps, bus |
|
100 |
errors and segfaults. Here is a cookbook for causing so called "naked oop |
|
101 |
failures": |
|
102 |
||
103 |
JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredFields<etc> { |
|
104 |
JVMWrapper("JVM_GetClassDeclaredFields"); |
|
105 |
||
106 |
// Object address to be held directly in mirror & not visible to GC |
|
107 |
oop mirror = JNIHandles::resolve_non_null(ofClass); |
|
108 |
||
109 |
// If this ctor can hit a safepoint, moving objects around, then |
|
110 |
ComplexConstructor foo; |
|
111 |
||
112 |
// Boom! mirror may point to JUNK instead of the intended object |
|
113 |
(some dereference of mirror) |
|
114 |
||
115 |
// Here's another call that may block for GC, making mirror stale |
|
116 |
MutexLocker ml(some_lock); |
|
117 |
||
118 |
// And here's an initializer that can result in a stale oop |
|
119 |
// all in one step. |
|
120 |
oop o = call_that_can_throw_exception(TRAPS); |
|
121 |
||
122 |
||
123 |
The solution is to keep the oop declaration BELOW the ctor or function |
|
124 |
call that might cause a GC, do another resolve to reassign the oop, or |
|
125 |
consider use of a Handle instead of an oop so there is immunity from object |
|
126 |
motion. But note that the "QUICK" entries below do not have a handlemark |
|
127 |
and thus can only support use of handles passed in. |
|
128 |
*/ |
|
129 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
130 |
static void trace_class_resolution_impl(Klass* to_class, TRAPS) { |
1 | 131 |
ResourceMark rm; |
132 |
int line_number = -1; |
|
133 |
const char * source_file = NULL; |
|
2269
ee9da33d43ab
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
2105
diff
changeset
|
134 |
const char * trace = "explicit"; |
14391
df0a1573d5bd
8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents:
13952
diff
changeset
|
135 |
InstanceKlass* caller = NULL; |
1 | 136 |
JavaThread* jthread = JavaThread::current(); |
137 |
if (jthread->has_last_Java_frame()) { |
|
138 |
vframeStream vfst(jthread); |
|
139 |
||
140 |
// scan up the stack skipping ClassLoader, AccessController and PrivilegedAction frames |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
141 |
TempNewSymbol access_controller = SymbolTable::new_symbol("java/security/AccessController", CHECK); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
142 |
Klass* access_controller_klass = SystemDictionary::resolve_or_fail(access_controller, false, CHECK); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
143 |
TempNewSymbol privileged_action = SymbolTable::new_symbol("java/security/PrivilegedAction", CHECK); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
144 |
Klass* privileged_action_klass = SystemDictionary::resolve_or_fail(privileged_action, false, CHECK); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
145 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
146 |
Method* last_caller = NULL; |
1 | 147 |
|
148 |
while (!vfst.at_end()) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
149 |
Method* m = vfst.method(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
150 |
if (!vfst.method()->method_holder()->is_subclass_of(SystemDictionary::ClassLoader_klass())&& |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
151 |
!vfst.method()->method_holder()->is_subclass_of(access_controller_klass) && |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
152 |
!vfst.method()->method_holder()->is_subclass_of(privileged_action_klass)) { |
1 | 153 |
break; |
154 |
} |
|
155 |
last_caller = m; |
|
156 |
vfst.next(); |
|
157 |
} |
|
158 |
// if this is called from Class.forName0 and that is called from Class.forName, |
|
159 |
// then print the caller of Class.forName. If this is Class.loadClass, then print |
|
160 |
// that caller, otherwise keep quiet since this should be picked up elsewhere. |
|
161 |
bool found_it = false; |
|
162 |
if (!vfst.at_end() && |
|
14391
df0a1573d5bd
8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents:
13952
diff
changeset
|
163 |
vfst.method()->method_holder()->name() == vmSymbols::java_lang_Class() && |
1 | 164 |
vfst.method()->name() == vmSymbols::forName0_name()) { |
165 |
vfst.next(); |
|
166 |
if (!vfst.at_end() && |
|
14391
df0a1573d5bd
8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents:
13952
diff
changeset
|
167 |
vfst.method()->method_holder()->name() == vmSymbols::java_lang_Class() && |
1 | 168 |
vfst.method()->name() == vmSymbols::forName_name()) { |
169 |
vfst.next(); |
|
170 |
found_it = true; |
|
171 |
} |
|
172 |
} else if (last_caller != NULL && |
|
14391
df0a1573d5bd
8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents:
13952
diff
changeset
|
173 |
last_caller->method_holder()->name() == |
1 | 174 |
vmSymbols::java_lang_ClassLoader() && |
175 |
(last_caller->name() == vmSymbols::loadClassInternal_name() || |
|
176 |
last_caller->name() == vmSymbols::loadClass_name())) { |
|
177 |
found_it = true; |
|
2269
ee9da33d43ab
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
2105
diff
changeset
|
178 |
} else if (!vfst.at_end()) { |
ee9da33d43ab
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
2105
diff
changeset
|
179 |
if (vfst.method()->is_native()) { |
ee9da33d43ab
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
2105
diff
changeset
|
180 |
// JNI call |
ee9da33d43ab
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
2105
diff
changeset
|
181 |
found_it = true; |
ee9da33d43ab
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
2105
diff
changeset
|
182 |
} |
1 | 183 |
} |
184 |
if (found_it && !vfst.at_end()) { |
|
185 |
// found the caller |
|
186 |
caller = vfst.method()->method_holder(); |
|
187 |
line_number = vfst.method()->line_number_from_bci(vfst.bci()); |
|
2269
ee9da33d43ab
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
2105
diff
changeset
|
188 |
if (line_number == -1) { |
ee9da33d43ab
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
2105
diff
changeset
|
189 |
// show method name if it's a native method |
ee9da33d43ab
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
2105
diff
changeset
|
190 |
trace = vfst.method()->name_and_sig_as_C_string(); |
ee9da33d43ab
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
2105
diff
changeset
|
191 |
} |
14391
df0a1573d5bd
8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents:
13952
diff
changeset
|
192 |
Symbol* s = caller->source_file_name(); |
1 | 193 |
if (s != NULL) { |
194 |
source_file = s->as_C_string(); |
|
195 |
} |
|
196 |
} |
|
197 |
} |
|
198 |
if (caller != NULL) { |
|
199 |
if (to_class != caller) { |
|
14391
df0a1573d5bd
8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents:
13952
diff
changeset
|
200 |
const char * from = caller->external_name(); |
df0a1573d5bd
8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents:
13952
diff
changeset
|
201 |
const char * to = to_class->external_name(); |
1 | 202 |
// print in a single call to reduce interleaving between threads |
203 |
if (source_file != NULL) { |
|
2269
ee9da33d43ab
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
2105
diff
changeset
|
204 |
tty->print("RESOLVE %s %s %s:%d (%s)\n", from, to, source_file, line_number, trace); |
1 | 205 |
} else { |
2269
ee9da33d43ab
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
2105
diff
changeset
|
206 |
tty->print("RESOLVE %s %s (%s)\n", from, to, trace); |
1 | 207 |
} |
208 |
} |
|
209 |
} |
|
210 |
} |
|
211 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
212 |
void trace_class_resolution(Klass* to_class) { |
1 | 213 |
EXCEPTION_MARK; |
214 |
trace_class_resolution_impl(to_class, THREAD); |
|
215 |
if (HAS_PENDING_EXCEPTION) { |
|
216 |
CLEAR_PENDING_EXCEPTION; |
|
217 |
} |
|
218 |
} |
|
219 |
||
220 |
// Wrapper to trace JVM functions |
|
221 |
||
222 |
#ifdef ASSERT |
|
223 |
class JVMTraceWrapper : public StackObj { |
|
224 |
public: |
|
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
24351
diff
changeset
|
225 |
JVMTraceWrapper(const char* format, ...) ATTRIBUTE_PRINTF(2, 3) { |
1 | 226 |
if (TraceJVMCalls) { |
227 |
va_list ap; |
|
228 |
va_start(ap, format); |
|
229 |
tty->print("JVM "); |
|
230 |
tty->vprint_cr(format, ap); |
|
231 |
va_end(ap); |
|
232 |
} |
|
233 |
} |
|
234 |
}; |
|
235 |
||
236 |
Histogram* JVMHistogram; |
|
237 |
volatile jint JVMHistogram_lock = 0; |
|
238 |
||
239 |
class JVMHistogramElement : public HistogramElement { |
|
240 |
public: |
|
241 |
JVMHistogramElement(const char* name); |
|
242 |
}; |
|
243 |
||
244 |
JVMHistogramElement::JVMHistogramElement(const char* elementName) { |
|
245 |
_name = elementName; |
|
246 |
uintx count = 0; |
|
247 |
||
248 |
while (Atomic::cmpxchg(1, &JVMHistogram_lock, 0) != 0) { |
|
249 |
while (OrderAccess::load_acquire(&JVMHistogram_lock) != 0) { |
|
250 |
count +=1; |
|
251 |
if ( (WarnOnStalledSpinLock > 0) |
|
252 |
&& (count % WarnOnStalledSpinLock == 0)) { |
|
253 |
warning("JVMHistogram_lock seems to be stalled"); |
|
254 |
} |
|
255 |
} |
|
256 |
} |
|
257 |
||
258 |
if(JVMHistogram == NULL) |
|
259 |
JVMHistogram = new Histogram("JVM Call Counts",100); |
|
260 |
||
261 |
JVMHistogram->add_element(this); |
|
262 |
Atomic::dec(&JVMHistogram_lock); |
|
263 |
} |
|
264 |
||
265 |
#define JVMCountWrapper(arg) \ |
|
266 |
static JVMHistogramElement* e = new JVMHistogramElement(arg); \ |
|
267 |
if (e != NULL) e->increment_count(); // Due to bug in VC++, we need a NULL check here eventhough it should never happen! |
|
268 |
||
269 |
#define JVMWrapper(arg1) JVMCountWrapper(arg1); JVMTraceWrapper(arg1) |
|
270 |
#define JVMWrapper2(arg1, arg2) JVMCountWrapper(arg1); JVMTraceWrapper(arg1, arg2) |
|
271 |
#define JVMWrapper3(arg1, arg2, arg3) JVMCountWrapper(arg1); JVMTraceWrapper(arg1, arg2, arg3) |
|
272 |
#define JVMWrapper4(arg1, arg2, arg3, arg4) JVMCountWrapper(arg1); JVMTraceWrapper(arg1, arg2, arg3, arg4) |
|
273 |
#else |
|
274 |
#define JVMWrapper(arg1) |
|
275 |
#define JVMWrapper2(arg1, arg2) |
|
276 |
#define JVMWrapper3(arg1, arg2, arg3) |
|
277 |
#define JVMWrapper4(arg1, arg2, arg3, arg4) |
|
278 |
#endif |
|
279 |
||
280 |
||
281 |
// Interface version ///////////////////////////////////////////////////////////////////// |
|
282 |
||
283 |
||
284 |
JVM_LEAF(jint, JVM_GetInterfaceVersion()) |
|
285 |
return JVM_INTERFACE_VERSION; |
|
286 |
JVM_END |
|
287 |
||
288 |
||
289 |
// java.lang.System ////////////////////////////////////////////////////////////////////// |
|
290 |
||
291 |
||
292 |
JVM_LEAF(jlong, JVM_CurrentTimeMillis(JNIEnv *env, jclass ignored)) |
|
293 |
JVMWrapper("JVM_CurrentTimeMillis"); |
|
294 |
return os::javaTimeMillis(); |
|
295 |
JVM_END |
|
296 |
||
297 |
JVM_LEAF(jlong, JVM_NanoTime(JNIEnv *env, jclass ignored)) |
|
298 |
JVMWrapper("JVM_NanoTime"); |
|
299 |
return os::javaTimeNanos(); |
|
300 |
JVM_END |
|
301 |
||
302 |
||
303 |
JVM_ENTRY(void, JVM_ArrayCopy(JNIEnv *env, jclass ignored, jobject src, jint src_pos, |
|
304 |
jobject dst, jint dst_pos, jint length)) |
|
305 |
JVMWrapper("JVM_ArrayCopy"); |
|
306 |
// Check if we have null pointers |
|
307 |
if (src == NULL || dst == NULL) { |
|
308 |
THROW(vmSymbols::java_lang_NullPointerException()); |
|
309 |
} |
|
310 |
arrayOop s = arrayOop(JNIHandles::resolve_non_null(src)); |
|
311 |
arrayOop d = arrayOop(JNIHandles::resolve_non_null(dst)); |
|
312 |
assert(s->is_oop(), "JVM_ArrayCopy: src not an oop"); |
|
313 |
assert(d->is_oop(), "JVM_ArrayCopy: dst not an oop"); |
|
314 |
// Do copy |
|
14488 | 315 |
s->klass()->copy_array(s, src_pos, d, dst_pos, length, thread); |
1 | 316 |
JVM_END |
317 |
||
318 |
||
319 |
static void set_property(Handle props, const char* key, const char* value, TRAPS) { |
|
320 |
JavaValue r(T_OBJECT); |
|
321 |
// public synchronized Object put(Object key, Object value); |
|
322 |
HandleMark hm(THREAD); |
|
323 |
Handle key_str = java_lang_String::create_from_platform_dependent_str(key, CHECK); |
|
324 |
Handle value_str = java_lang_String::create_from_platform_dependent_str((value != NULL ? value : ""), CHECK); |
|
325 |
JavaCalls::call_virtual(&r, |
|
326 |
props, |
|
4571 | 327 |
KlassHandle(THREAD, SystemDictionary::Properties_klass()), |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
328 |
vmSymbols::put_name(), |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
329 |
vmSymbols::object_object_object_signature(), |
1 | 330 |
key_str, |
331 |
value_str, |
|
332 |
THREAD); |
|
333 |
} |
|
334 |
||
335 |
||
336 |
#define PUTPROP(props, name, value) set_property((props), (name), (value), CHECK_(properties)); |
|
337 |
||
338 |
||
339 |
JVM_ENTRY(jobject, JVM_InitProperties(JNIEnv *env, jobject properties)) |
|
340 |
JVMWrapper("JVM_InitProperties"); |
|
341 |
ResourceMark rm; |
|
342 |
||
343 |
Handle props(THREAD, JNIHandles::resolve_non_null(properties)); |
|
344 |
||
345 |
// System property list includes both user set via -D option and |
|
346 |
// jvm system specific properties. |
|
347 |
for (SystemProperty* p = Arguments::system_properties(); p != NULL; p = p->next()) { |
|
348 |
PUTPROP(props, p->key(), p->value()); |
|
349 |
} |
|
350 |
||
351 |
// Convert the -XX:MaxDirectMemorySize= command line flag |
|
352 |
// to the sun.nio.MaxDirectMemorySize property. |
|
353 |
// Do this after setting user properties to prevent people |
|
354 |
// from setting the value with a -D option, as requested. |
|
355 |
{ |
|
13197
b552dfeffb3c
7179383: MaxDirectMemorySize argument parsing is broken for values >2G
dholmes
parents:
12231
diff
changeset
|
356 |
if (FLAG_IS_DEFAULT(MaxDirectMemorySize)) { |
b552dfeffb3c
7179383: MaxDirectMemorySize argument parsing is broken for values >2G
dholmes
parents:
12231
diff
changeset
|
357 |
PUTPROP(props, "sun.nio.MaxDirectMemorySize", "-1"); |
b552dfeffb3c
7179383: MaxDirectMemorySize argument parsing is broken for values >2G
dholmes
parents:
12231
diff
changeset
|
358 |
} else { |
b552dfeffb3c
7179383: MaxDirectMemorySize argument parsing is broken for values >2G
dholmes
parents:
12231
diff
changeset
|
359 |
char as_chars[256]; |
b552dfeffb3c
7179383: MaxDirectMemorySize argument parsing is broken for values >2G
dholmes
parents:
12231
diff
changeset
|
360 |
jio_snprintf(as_chars, sizeof(as_chars), UINTX_FORMAT, MaxDirectMemorySize); |
b552dfeffb3c
7179383: MaxDirectMemorySize argument parsing is broken for values >2G
dholmes
parents:
12231
diff
changeset
|
361 |
PUTPROP(props, "sun.nio.MaxDirectMemorySize", as_chars); |
b552dfeffb3c
7179383: MaxDirectMemorySize argument parsing is broken for values >2G
dholmes
parents:
12231
diff
changeset
|
362 |
} |
1 | 363 |
} |
364 |
||
365 |
// JVM monitoring and management support |
|
366 |
// Add the sun.management.compiler property for the compiler's name |
|
367 |
{ |
|
368 |
#undef CSIZE |
|
369 |
#if defined(_LP64) || defined(_WIN64) |
|
370 |
#define CSIZE "64-Bit " |
|
371 |
#else |
|
372 |
#define CSIZE |
|
373 |
#endif // 64bit |
|
374 |
||
375 |
#ifdef TIERED |
|
376 |
const char* compiler_name = "HotSpot " CSIZE "Tiered Compilers"; |
|
377 |
#else |
|
378 |
#if defined(COMPILER1) |
|
379 |
const char* compiler_name = "HotSpot " CSIZE "Client Compiler"; |
|
380 |
#elif defined(COMPILER2) |
|
381 |
const char* compiler_name = "HotSpot " CSIZE "Server Compiler"; |
|
382 |
#else |
|
383 |
const char* compiler_name = ""; |
|
384 |
#endif // compilers |
|
385 |
#endif // TIERED |
|
386 |
||
387 |
if (*compiler_name != '\0' && |
|
388 |
(Arguments::mode() != Arguments::_int)) { |
|
389 |
PUTPROP(props, "sun.management.compiler", compiler_name); |
|
390 |
} |
|
391 |
} |
|
392 |
||
393 |
return properties; |
|
394 |
JVM_END |
|
395 |
||
396 |
||
24242
73337a12595a
8041980: (hotspot) sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents:
23999
diff
changeset
|
397 |
/* |
73337a12595a
8041980: (hotspot) sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents:
23999
diff
changeset
|
398 |
* Return the temporary directory that the VM uses for the attach |
73337a12595a
8041980: (hotspot) sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents:
23999
diff
changeset
|
399 |
* and perf data files. |
73337a12595a
8041980: (hotspot) sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents:
23999
diff
changeset
|
400 |
* |
73337a12595a
8041980: (hotspot) sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents:
23999
diff
changeset
|
401 |
* It is important that this directory is well-known and the |
73337a12595a
8041980: (hotspot) sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents:
23999
diff
changeset
|
402 |
* same for all VM instances. It cannot be affected by configuration |
73337a12595a
8041980: (hotspot) sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents:
23999
diff
changeset
|
403 |
* variables such as java.io.tmpdir. |
73337a12595a
8041980: (hotspot) sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents:
23999
diff
changeset
|
404 |
*/ |
73337a12595a
8041980: (hotspot) sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents:
23999
diff
changeset
|
405 |
JVM_ENTRY(jstring, JVM_GetTemporaryDirectory(JNIEnv *env)) |
73337a12595a
8041980: (hotspot) sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents:
23999
diff
changeset
|
406 |
JVMWrapper("JVM_GetTemporaryDirectory"); |
73337a12595a
8041980: (hotspot) sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents:
23999
diff
changeset
|
407 |
HandleMark hm(THREAD); |
73337a12595a
8041980: (hotspot) sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents:
23999
diff
changeset
|
408 |
const char* temp_dir = os::get_temp_directory(); |
73337a12595a
8041980: (hotspot) sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents:
23999
diff
changeset
|
409 |
Handle h = java_lang_String::create_from_platform_dependent_str(temp_dir, CHECK_NULL); |
73337a12595a
8041980: (hotspot) sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents:
23999
diff
changeset
|
410 |
return (jstring) JNIHandles::make_local(env, h()); |
73337a12595a
8041980: (hotspot) sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents:
23999
diff
changeset
|
411 |
JVM_END |
73337a12595a
8041980: (hotspot) sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents:
23999
diff
changeset
|
412 |
|
73337a12595a
8041980: (hotspot) sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents:
23999
diff
changeset
|
413 |
|
1 | 414 |
// java.lang.Runtime ///////////////////////////////////////////////////////////////////////// |
415 |
||
416 |
extern volatile jint vm_created; |
|
417 |
||
418 |
JVM_ENTRY_NO_ENV(void, JVM_Halt(jint code)) |
|
419 |
before_exit(thread); |
|
420 |
vm_exit(code); |
|
421 |
JVM_END |
|
422 |
||
423 |
||
424 |
JVM_ENTRY_NO_ENV(void, JVM_GC(void)) |
|
425 |
JVMWrapper("JVM_GC"); |
|
426 |
if (!DisableExplicitGC) { |
|
427 |
Universe::heap()->collect(GCCause::_java_lang_system_gc); |
|
428 |
} |
|
429 |
JVM_END |
|
430 |
||
431 |
||
432 |
JVM_LEAF(jlong, JVM_MaxObjectInspectionAge(void)) |
|
433 |
JVMWrapper("JVM_MaxObjectInspectionAge"); |
|
434 |
return Universe::heap()->millis_since_last_gc(); |
|
435 |
JVM_END |
|
436 |
||
437 |
||
438 |
static inline jlong convert_size_t_to_jlong(size_t val) { |
|
439 |
// In the 64-bit vm, a size_t can overflow a jlong (which is signed). |
|
440 |
NOT_LP64 (return (jlong)val;) |
|
441 |
LP64_ONLY(return (jlong)MIN2(val, (size_t)max_jlong);) |
|
442 |
} |
|
443 |
||
444 |
JVM_ENTRY_NO_ENV(jlong, JVM_TotalMemory(void)) |
|
445 |
JVMWrapper("JVM_TotalMemory"); |
|
446 |
size_t n = Universe::heap()->capacity(); |
|
447 |
return convert_size_t_to_jlong(n); |
|
448 |
JVM_END |
|
449 |
||
450 |
||
451 |
JVM_ENTRY_NO_ENV(jlong, JVM_FreeMemory(void)) |
|
452 |
JVMWrapper("JVM_FreeMemory"); |
|
453 |
CollectedHeap* ch = Universe::heap(); |
|
1374
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
363
diff
changeset
|
454 |
size_t n; |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
363
diff
changeset
|
455 |
{ |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
363
diff
changeset
|
456 |
MutexLocker x(Heap_lock); |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
363
diff
changeset
|
457 |
n = ch->capacity() - ch->used(); |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
363
diff
changeset
|
458 |
} |
1 | 459 |
return convert_size_t_to_jlong(n); |
460 |
JVM_END |
|
461 |
||
462 |
||
463 |
JVM_ENTRY_NO_ENV(jlong, JVM_MaxMemory(void)) |
|
464 |
JVMWrapper("JVM_MaxMemory"); |
|
465 |
size_t n = Universe::heap()->max_capacity(); |
|
466 |
return convert_size_t_to_jlong(n); |
|
467 |
JVM_END |
|
468 |
||
469 |
||
470 |
JVM_ENTRY_NO_ENV(jint, JVM_ActiveProcessorCount(void)) |
|
471 |
JVMWrapper("JVM_ActiveProcessorCount"); |
|
472 |
return os::active_processor_count(); |
|
473 |
JVM_END |
|
474 |
||
475 |
||
476 |
||
477 |
// java.lang.Throwable ////////////////////////////////////////////////////// |
|
478 |
||
479 |
||
480 |
JVM_ENTRY(void, JVM_FillInStackTrace(JNIEnv *env, jobject receiver)) |
|
481 |
JVMWrapper("JVM_FillInStackTrace"); |
|
482 |
Handle exception(thread, JNIHandles::resolve_non_null(receiver)); |
|
483 |
java_lang_Throwable::fill_in_stack_trace(exception); |
|
484 |
JVM_END |
|
485 |
||
486 |
||
487 |
JVM_ENTRY(jint, JVM_GetStackTraceDepth(JNIEnv *env, jobject throwable)) |
|
488 |
JVMWrapper("JVM_GetStackTraceDepth"); |
|
489 |
oop exception = JNIHandles::resolve(throwable); |
|
490 |
return java_lang_Throwable::get_stack_trace_depth(exception, THREAD); |
|
491 |
JVM_END |
|
492 |
||
493 |
||
494 |
JVM_ENTRY(jobject, JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index)) |
|
495 |
JVMWrapper("JVM_GetStackTraceElement"); |
|
496 |
JvmtiVMObjectAllocEventCollector oam; // This ctor (throughout this module) may trigger a safepoint/GC |
|
497 |
oop exception = JNIHandles::resolve(throwable); |
|
498 |
oop element = java_lang_Throwable::get_stack_trace_element(exception, index, CHECK_NULL); |
|
499 |
return JNIHandles::make_local(env, element); |
|
500 |
JVM_END |
|
501 |
||
502 |
||
503 |
// java.lang.Object /////////////////////////////////////////////// |
|
504 |
||
505 |
||
506 |
JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle)) |
|
507 |
JVMWrapper("JVM_IHashCode"); |
|
508 |
// as implemented in the classic virtual machine; return 0 if object is NULL |
|
509 |
return handle == NULL ? 0 : ObjectSynchronizer::FastHashCode (THREAD, JNIHandles::resolve_non_null(handle)) ; |
|
510 |
JVM_END |
|
511 |
||
512 |
||
513 |
JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms)) |
|
514 |
JVMWrapper("JVM_MonitorWait"); |
|
515 |
Handle obj(THREAD, JNIHandles::resolve_non_null(handle)); |
|
516 |
JavaThreadInObjectWaitState jtiows(thread, ms != 0); |
|
517 |
if (JvmtiExport::should_post_monitor_wait()) { |
|
518 |
JvmtiExport::post_monitor_wait((JavaThread *)THREAD, (oop)obj(), ms); |
|
22753
749328896281
8028073: race condition in ObjectMonitor implementation causing deadlocks
dcubed
parents:
22189
diff
changeset
|
519 |
|
749328896281
8028073: race condition in ObjectMonitor implementation causing deadlocks
dcubed
parents:
22189
diff
changeset
|
520 |
// The current thread already owns the monitor and it has not yet |
749328896281
8028073: race condition in ObjectMonitor implementation causing deadlocks
dcubed
parents:
22189
diff
changeset
|
521 |
// been added to the wait queue so the current thread cannot be |
749328896281
8028073: race condition in ObjectMonitor implementation causing deadlocks
dcubed
parents:
22189
diff
changeset
|
522 |
// made the successor. This means that the JVMTI_EVENT_MONITOR_WAIT |
749328896281
8028073: race condition in ObjectMonitor implementation causing deadlocks
dcubed
parents:
22189
diff
changeset
|
523 |
// event handler cannot accidentally consume an unpark() meant for |
749328896281
8028073: race condition in ObjectMonitor implementation causing deadlocks
dcubed
parents:
22189
diff
changeset
|
524 |
// the ParkEvent associated with this ObjectMonitor. |
1 | 525 |
} |
526 |
ObjectSynchronizer::wait(obj, ms, CHECK); |
|
527 |
JVM_END |
|
528 |
||
529 |
||
530 |
JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle)) |
|
531 |
JVMWrapper("JVM_MonitorNotify"); |
|
532 |
Handle obj(THREAD, JNIHandles::resolve_non_null(handle)); |
|
533 |
ObjectSynchronizer::notify(obj, CHECK); |
|
534 |
JVM_END |
|
535 |
||
536 |
||
537 |
JVM_ENTRY(void, JVM_MonitorNotifyAll(JNIEnv* env, jobject handle)) |
|
538 |
JVMWrapper("JVM_MonitorNotifyAll"); |
|
539 |
Handle obj(THREAD, JNIHandles::resolve_non_null(handle)); |
|
540 |
ObjectSynchronizer::notifyall(obj, CHECK); |
|
541 |
JVM_END |
|
542 |
||
543 |
||
544 |
JVM_ENTRY(jobject, JVM_Clone(JNIEnv* env, jobject handle)) |
|
545 |
JVMWrapper("JVM_Clone"); |
|
546 |
Handle obj(THREAD, JNIHandles::resolve_non_null(handle)); |
|
547 |
const KlassHandle klass (THREAD, obj->klass()); |
|
548 |
JvmtiVMObjectAllocEventCollector oam; |
|
549 |
||
550 |
#ifdef ASSERT |
|
551 |
// Just checking that the cloneable flag is set correct |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
552 |
if (obj->is_array()) { |
1 | 553 |
guarantee(klass->is_cloneable(), "all arrays are cloneable"); |
554 |
} else { |
|
555 |
guarantee(obj->is_instance(), "should be instanceOop"); |
|
4571 | 556 |
bool cloneable = klass->is_subtype_of(SystemDictionary::Cloneable_klass()); |
1 | 557 |
guarantee(cloneable == klass->is_cloneable(), "incorrect cloneable flag"); |
558 |
} |
|
559 |
#endif |
|
560 |
||
561 |
// Check if class of obj supports the Cloneable interface. |
|
562 |
// All arrays are considered to be cloneable (See JLS 20.1.5) |
|
563 |
if (!klass->is_cloneable()) { |
|
564 |
ResourceMark rm(THREAD); |
|
565 |
THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name()); |
|
566 |
} |
|
567 |
||
568 |
// Make shallow object copy |
|
569 |
const int size = obj->size(); |
|
570 |
oop new_obj = NULL; |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
571 |
if (obj->is_array()) { |
1 | 572 |
const int length = ((arrayOop)obj())->length(); |
573 |
new_obj = CollectedHeap::array_allocate(klass, size, length, CHECK_NULL); |
|
574 |
} else { |
|
575 |
new_obj = CollectedHeap::obj_allocate(klass, size, CHECK_NULL); |
|
576 |
} |
|
577 |
// 4839641 (4840070): We must do an oop-atomic copy, because if another thread |
|
578 |
// is modifying a reference field in the clonee, a non-oop-atomic copy might |
|
579 |
// be suspended in the middle of copying the pointer and end up with parts |
|
580 |
// of two different pointers in the field. Subsequent dereferences will crash. |
|
581 |
// 4846409: an oop-copy of objects with long or double fields or arrays of same |
|
582 |
// won't copy the longs/doubles atomically in 32-bit vm's, so we copy jlongs instead |
|
583 |
// of oops. We know objects are aligned on a minimum of an jlong boundary. |
|
584 |
// The same is true of StubRoutines::object_copy and the various oop_copy |
|
585 |
// variants, and of the code generated by the inline_native_clone intrinsic. |
|
586 |
assert(MinObjAlignmentInBytes >= BytesPerLong, "objects misaligned"); |
|
587 |
Copy::conjoint_jlongs_atomic((jlong*)obj(), (jlong*)new_obj, |
|
588 |
(size_t)align_object_size(size) / HeapWordsPerLong); |
|
589 |
// Clear the header |
|
590 |
new_obj->init_mark(); |
|
591 |
||
592 |
// Store check (mark entire object and let gc sort it out) |
|
593 |
BarrierSet* bs = Universe::heap()->barrier_set(); |
|
594 |
assert(bs->has_write_region_opt(), "Barrier set does not have write_region"); |
|
595 |
bs->write_region(MemRegion((HeapWord*)new_obj, size)); |
|
596 |
||
597 |
// Caution: this involves a java upcall, so the clone should be |
|
598 |
// "gc-robust" by this stage. |
|
599 |
if (klass->has_finalizer()) { |
|
600 |
assert(obj->is_instance(), "should be instanceOop"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
601 |
new_obj = InstanceKlass::register_finalizer(instanceOop(new_obj), CHECK_NULL); |
1 | 602 |
} |
603 |
||
604 |
return JNIHandles::make_local(env, oop(new_obj)); |
|
605 |
JVM_END |
|
606 |
||
607 |
// java.io.File /////////////////////////////////////////////////////////////// |
|
608 |
||
609 |
JVM_LEAF(char*, JVM_NativePath(char* path)) |
|
610 |
JVMWrapper2("JVM_NativePath (%s)", path); |
|
7405
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
611 |
return os::native_path(path); |
1 | 612 |
JVM_END |
613 |
||
614 |
||
615 |
// Misc. class handling /////////////////////////////////////////////////////////// |
|
616 |
||
617 |
||
618 |
JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env, int depth)) |
|
619 |
JVMWrapper("JVM_GetCallerClass"); |
|
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
620 |
|
20392
a61df72089e5
8026025: JVM_GetCallerClass allows Reflection.getCallerClass(int depth) to use
dholmes
parents:
20384
diff
changeset
|
621 |
// Pre-JDK 8 and early builds of JDK 8 don't have a CallerSensitive annotation; or |
a61df72089e5
8026025: JVM_GetCallerClass allows Reflection.getCallerClass(int depth) to use
dholmes
parents:
20384
diff
changeset
|
622 |
// sun.reflect.Reflection.getCallerClass with a depth parameter is provided |
a61df72089e5
8026025: JVM_GetCallerClass allows Reflection.getCallerClass(int depth) to use
dholmes
parents:
20384
diff
changeset
|
623 |
// temporarily for existing code to use until a replacement API is defined. |
a61df72089e5
8026025: JVM_GetCallerClass allows Reflection.getCallerClass(int depth) to use
dholmes
parents:
20384
diff
changeset
|
624 |
if (SystemDictionary::reflect_CallerSensitive_klass() == NULL || depth != JVM_CALLER_DEPTH) { |
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
625 |
Klass* k = thread->security_get_caller_class(depth); |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
626 |
return (k == NULL) ? NULL : (jclass) JNIHandles::make_local(env, k->java_mirror()); |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
627 |
} |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
628 |
|
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
629 |
// Getting the class of the caller frame. |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
630 |
// |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
631 |
// The call stack at this point looks something like this: |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
632 |
// |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
633 |
// [0] [ @CallerSensitive public sun.reflect.Reflection.getCallerClass ] |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
634 |
// [1] [ @CallerSensitive API.method ] |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
635 |
// [.] [ (skipped intermediate frames) ] |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
636 |
// [n] [ caller ] |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
637 |
vframeStream vfst(thread); |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
638 |
// Cf. LibraryCallKit::inline_native_Reflection_getCallerClass |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
639 |
for (int n = 0; !vfst.at_end(); vfst.security_next(), n++) { |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
640 |
Method* m = vfst.method(); |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
641 |
assert(m != NULL, "sanity"); |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
642 |
switch (n) { |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
643 |
case 0: |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
644 |
// This must only be called from Reflection.getCallerClass |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
645 |
if (m->intrinsic_id() != vmIntrinsics::_getCallerClass) { |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
646 |
THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "JVM_GetCallerClass must only be called from Reflection.getCallerClass"); |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
647 |
} |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
648 |
// fall-through |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
649 |
case 1: |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
650 |
// Frame 0 and 1 must be caller sensitive. |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
651 |
if (!m->caller_sensitive()) { |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
652 |
THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), err_msg("CallerSensitive annotation expected at frame %d", n)); |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
653 |
} |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
654 |
break; |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
655 |
default: |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
656 |
if (!m->is_ignored_by_security_stack_walk()) { |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
657 |
// We have reached the desired frame; return the holder class. |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
658 |
return (jclass) JNIHandles::make_local(env, m->method_holder()->java_mirror()); |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
659 |
} |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
660 |
break; |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
661 |
} |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
662 |
} |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
663 |
return NULL; |
1 | 664 |
JVM_END |
665 |
||
666 |
||
667 |
JVM_ENTRY(jclass, JVM_FindPrimitiveClass(JNIEnv* env, const char* utf)) |
|
668 |
JVMWrapper("JVM_FindPrimitiveClass"); |
|
669 |
oop mirror = NULL; |
|
670 |
BasicType t = name2type(utf); |
|
671 |
if (t != T_ILLEGAL && t != T_OBJECT && t != T_ARRAY) { |
|
672 |
mirror = Universe::java_mirror(t); |
|
673 |
} |
|
674 |
if (mirror == NULL) { |
|
675 |
THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), (char*) utf); |
|
676 |
} else { |
|
677 |
return (jclass) JNIHandles::make_local(env, mirror); |
|
678 |
} |
|
679 |
JVM_END |
|
680 |
||
681 |
||
3578
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
682 |
// Returns a class loaded by the bootstrap class loader; or null |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
683 |
// if not found. ClassNotFoundException is not thrown. |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
684 |
// |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
685 |
// Rationale behind JVM_FindClassFromBootLoader |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
686 |
// a> JVM_FindClassFromClassLoader was never exported in the export tables. |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
687 |
// b> because of (a) java.dll has a direct dependecy on the unexported |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
688 |
// private symbol "_JVM_FindClassFromClassLoader@20". |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
689 |
// c> the launcher cannot use the private symbol as it dynamically opens |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
690 |
// the entry point, so if something changes, the launcher will fail |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
691 |
// unexpectedly at runtime, it is safest for the launcher to dlopen a |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
692 |
// stable exported interface. |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
693 |
// d> re-exporting JVM_FindClassFromClassLoader as public, will cause its |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
694 |
// signature to change from _JVM_FindClassFromClassLoader@20 to |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
695 |
// JVM_FindClassFromClassLoader and will not be backward compatible |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
696 |
// with older JDKs. |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
697 |
// Thus a public/stable exported entry point is the right solution, |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
698 |
// public here means public in linker semantics, and is exported only |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
699 |
// to the JDK, and is not intended to be a public API. |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
700 |
|
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
701 |
JVM_ENTRY(jclass, JVM_FindClassFromBootLoader(JNIEnv* env, |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
702 |
const char* name)) |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
703 |
JVMWrapper2("JVM_FindClassFromBootLoader %s", name); |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
704 |
|
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
705 |
// Java libraries should ensure that name is never null... |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
706 |
if (name == NULL || (int)strlen(name) > Symbol::max_length()) { |
3578
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
707 |
// It's impossible to create this class; the name cannot fit |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
708 |
// into the constant pool. |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
709 |
return NULL; |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
710 |
} |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
711 |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
712 |
TempNewSymbol h_name = SymbolTable::new_symbol(name, CHECK_NULL); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
713 |
Klass* k = SystemDictionary::resolve_or_null(h_name, CHECK_NULL); |
3578
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
714 |
if (k == NULL) { |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
715 |
return NULL; |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
716 |
} |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
717 |
|
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
718 |
if (TraceClassResolution) { |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
719 |
trace_class_resolution(k); |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
720 |
} |
14488 | 721 |
return (jclass) JNIHandles::make_local(env, k->java_mirror()); |
3578
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
722 |
JVM_END |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
723 |
|
27021 | 724 |
// Not used; JVM_FindClassFromCaller replaces this. |
3578
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
725 |
JVM_ENTRY(jclass, JVM_FindClassFromClassLoader(JNIEnv* env, const char* name, |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
726 |
jboolean init, jobject loader, |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
727 |
jboolean throwError)) |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
728 |
JVMWrapper3("JVM_FindClassFromClassLoader %s throw %s", name, |
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
729 |
throwError ? "error" : "exception"); |
1420 | 730 |
// Java libraries should ensure that name is never null... |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
731 |
if (name == NULL || (int)strlen(name) > Symbol::max_length()) { |
1420 | 732 |
// It's impossible to create this class; the name cannot fit |
733 |
// into the constant pool. |
|
734 |
if (throwError) { |
|
735 |
THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name); |
|
736 |
} else { |
|
737 |
THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), name); |
|
738 |
} |
|
739 |
} |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
740 |
TempNewSymbol h_name = SymbolTable::new_symbol(name, CHECK_NULL); |
1420 | 741 |
Handle h_loader(THREAD, JNIHandles::resolve(loader)); |
742 |
jclass result = find_class_from_class_loader(env, h_name, init, h_loader, |
|
743 |
Handle(), throwError, THREAD); |
|
744 |
||
745 |
if (TraceClassResolution && result != NULL) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
746 |
trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result))); |
1420 | 747 |
} |
748 |
return result; |
|
1 | 749 |
JVM_END |
750 |
||
27021 | 751 |
// Find a class with this name in this loader, using the caller's protection domain. |
752 |
JVM_ENTRY(jclass, JVM_FindClassFromCaller(JNIEnv* env, const char* name, |
|
753 |
jboolean init, jobject loader, |
|
754 |
jclass caller)) |
|
755 |
JVMWrapper2("JVM_FindClassFromCaller %s throws ClassNotFoundException", name); |
|
756 |
// Java libraries should ensure that name is never null... |
|
757 |
if (name == NULL || (int)strlen(name) > Symbol::max_length()) { |
|
758 |
// It's impossible to create this class; the name cannot fit |
|
759 |
// into the constant pool. |
|
760 |
THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), name); |
|
761 |
} |
|
762 |
||
763 |
TempNewSymbol h_name = SymbolTable::new_symbol(name, CHECK_NULL); |
|
764 |
||
765 |
oop loader_oop = JNIHandles::resolve(loader); |
|
766 |
oop from_class = JNIHandles::resolve(caller); |
|
767 |
oop protection_domain = NULL; |
|
768 |
// If loader is null, shouldn't call ClassLoader.checkPackageAccess; otherwise get |
|
769 |
// NPE. Put it in another way, the bootstrap class loader has all permission and |
|
770 |
// thus no checkPackageAccess equivalence in the VM class loader. |
|
771 |
// The caller is also passed as NULL by the java code if there is no security |
|
772 |
// manager to avoid the performance cost of getting the calling class. |
|
773 |
if (from_class != NULL && loader_oop != NULL) { |
|
774 |
protection_domain = java_lang_Class::as_Klass(from_class)->protection_domain(); |
|
775 |
} |
|
776 |
||
777 |
Handle h_loader(THREAD, loader_oop); |
|
778 |
Handle h_prot(THREAD, protection_domain); |
|
779 |
jclass result = find_class_from_class_loader(env, h_name, init, h_loader, |
|
780 |
h_prot, false, THREAD); |
|
781 |
||
782 |
if (TraceClassResolution && result != NULL) { |
|
783 |
trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result))); |
|
784 |
} |
|
785 |
return result; |
|
786 |
JVM_END |
|
1 | 787 |
|
788 |
JVM_ENTRY(jclass, JVM_FindClassFromClass(JNIEnv *env, const char *name, |
|
789 |
jboolean init, jclass from)) |
|
790 |
JVMWrapper2("JVM_FindClassFromClass %s", name); |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
791 |
if (name == NULL || (int)strlen(name) > Symbol::max_length()) { |
1 | 792 |
// It's impossible to create this class; the name cannot fit |
793 |
// into the constant pool. |
|
794 |
THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name); |
|
795 |
} |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
796 |
TempNewSymbol h_name = SymbolTable::new_symbol(name, CHECK_NULL); |
1 | 797 |
oop from_class_oop = JNIHandles::resolve(from); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
798 |
Klass* from_class = (from_class_oop == NULL) |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
799 |
? (Klass*)NULL |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
800 |
: java_lang_Class::as_Klass(from_class_oop); |
1 | 801 |
oop class_loader = NULL; |
802 |
oop protection_domain = NULL; |
|
803 |
if (from_class != NULL) { |
|
14488 | 804 |
class_loader = from_class->class_loader(); |
805 |
protection_domain = from_class->protection_domain(); |
|
1 | 806 |
} |
807 |
Handle h_loader(THREAD, class_loader); |
|
808 |
Handle h_prot (THREAD, protection_domain); |
|
809 |
jclass result = find_class_from_class_loader(env, h_name, init, h_loader, |
|
810 |
h_prot, true, thread); |
|
811 |
||
812 |
if (TraceClassResolution && result != NULL) { |
|
813 |
// this function is generally only used for class loading during verification. |
|
814 |
ResourceMark rm; |
|
815 |
oop from_mirror = JNIHandles::resolve_non_null(from); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
816 |
Klass* from_class = java_lang_Class::as_Klass(from_mirror); |
14488 | 817 |
const char * from_name = from_class->external_name(); |
1 | 818 |
|
819 |
oop mirror = JNIHandles::resolve_non_null(result); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
820 |
Klass* to_class = java_lang_Class::as_Klass(mirror); |
14488 | 821 |
const char * to = to_class->external_name(); |
1 | 822 |
tty->print("RESOLVE %s %s (verification)\n", from_name, to); |
823 |
} |
|
824 |
||
825 |
return result; |
|
826 |
JVM_END |
|
827 |
||
828 |
static void is_lock_held_by_thread(Handle loader, PerfCounter* counter, TRAPS) { |
|
829 |
if (loader.is_null()) { |
|
830 |
return; |
|
831 |
} |
|
832 |
||
833 |
// check whether the current caller thread holds the lock or not. |
|
834 |
// If not, increment the corresponding counter |
|
835 |
if (ObjectSynchronizer::query_lock_ownership((JavaThread*)THREAD, loader) != |
|
836 |
ObjectSynchronizer::owner_self) { |
|
837 |
counter->inc(); |
|
838 |
} |
|
839 |
} |
|
840 |
||
841 |
// common code for JVM_DefineClass() and JVM_DefineClassWithSource() |
|
3820
0a8fbbe180db
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
3578
diff
changeset
|
842 |
// and JVM_DefineClassWithSourceCond() |
0a8fbbe180db
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
3578
diff
changeset
|
843 |
static jclass jvm_define_class_common(JNIEnv *env, const char *name, |
0a8fbbe180db
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
3578
diff
changeset
|
844 |
jobject loader, const jbyte *buf, |
0a8fbbe180db
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
3578
diff
changeset
|
845 |
jsize len, jobject pd, const char *source, |
0a8fbbe180db
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
3578
diff
changeset
|
846 |
jboolean verify, TRAPS) { |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1420
diff
changeset
|
847 |
if (source == NULL) source = "__JVM_DefineClass__"; |
1 | 848 |
|
3575
224791e7ecab
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
2570
diff
changeset
|
849 |
assert(THREAD->is_Java_thread(), "must be a JavaThread"); |
224791e7ecab
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
2570
diff
changeset
|
850 |
JavaThread* jt = (JavaThread*) THREAD; |
224791e7ecab
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
2570
diff
changeset
|
851 |
|
224791e7ecab
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
2570
diff
changeset
|
852 |
PerfClassTraceTime vmtimer(ClassLoader::perf_define_appclass_time(), |
224791e7ecab
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
2570
diff
changeset
|
853 |
ClassLoader::perf_define_appclass_selftime(), |
224791e7ecab
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
2570
diff
changeset
|
854 |
ClassLoader::perf_define_appclasses(), |
224791e7ecab
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
2570
diff
changeset
|
855 |
jt->get_thread_stat()->perf_recursion_counts_addr(), |
224791e7ecab
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
2570
diff
changeset
|
856 |
jt->get_thread_stat()->perf_timers_addr(), |
224791e7ecab
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
2570
diff
changeset
|
857 |
PerfClassTraceTime::DEFINE_CLASS); |
224791e7ecab
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
2570
diff
changeset
|
858 |
|
224791e7ecab
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
2570
diff
changeset
|
859 |
if (UsePerfData) { |
224791e7ecab
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
2570
diff
changeset
|
860 |
ClassLoader::perf_app_classfile_bytes_read()->inc(len); |
224791e7ecab
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
2570
diff
changeset
|
861 |
} |
224791e7ecab
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
2570
diff
changeset
|
862 |
|
1 | 863 |
// Since exceptions can be thrown, class initialization can take place |
864 |
// if name is NULL no check for class name in .class stream has to be made. |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
865 |
TempNewSymbol class_name = NULL; |
1 | 866 |
if (name != NULL) { |
867 |
const int str_len = (int)strlen(name); |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
868 |
if (str_len > Symbol::max_length()) { |
1 | 869 |
// It's impossible to create this class; the name cannot fit |
870 |
// into the constant pool. |
|
871 |
THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name); |
|
872 |
} |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
873 |
class_name = SymbolTable::new_symbol(name, str_len, CHECK_NULL); |
1 | 874 |
} |
875 |
||
876 |
ResourceMark rm(THREAD); |
|
877 |
ClassFileStream st((u1*) buf, len, (char *)source); |
|
878 |
Handle class_loader (THREAD, JNIHandles::resolve(loader)); |
|
879 |
if (UsePerfData) { |
|
880 |
is_lock_held_by_thread(class_loader, |
|
881 |
ClassLoader::sync_JVMDefineClassLockFreeCounter(), |
|
882 |
THREAD); |
|
883 |
} |
|
884 |
Handle protection_domain (THREAD, JNIHandles::resolve(pd)); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
885 |
Klass* k = SystemDictionary::resolve_from_stream(class_name, class_loader, |
1 | 886 |
protection_domain, &st, |
3820
0a8fbbe180db
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
3578
diff
changeset
|
887 |
verify != 0, |
1 | 888 |
CHECK_NULL); |
889 |
||
890 |
if (TraceClassResolution && k != NULL) { |
|
891 |
trace_class_resolution(k); |
|
892 |
} |
|
893 |
||
14488 | 894 |
return (jclass) JNIHandles::make_local(env, k->java_mirror()); |
1 | 895 |
} |
896 |
||
897 |
||
898 |
JVM_ENTRY(jclass, JVM_DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd)) |
|
899 |
JVMWrapper2("JVM_DefineClass %s", name); |
|
900 |
||
3820
0a8fbbe180db
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
3578
diff
changeset
|
901 |
return jvm_define_class_common(env, name, loader, buf, len, pd, NULL, true, THREAD); |
1 | 902 |
JVM_END |
903 |
||
904 |
||
905 |
JVM_ENTRY(jclass, JVM_DefineClassWithSource(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd, const char *source)) |
|
906 |
JVMWrapper2("JVM_DefineClassWithSource %s", name); |
|
907 |
||
3820
0a8fbbe180db
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
3578
diff
changeset
|
908 |
return jvm_define_class_common(env, name, loader, buf, len, pd, source, true, THREAD); |
0a8fbbe180db
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
3578
diff
changeset
|
909 |
JVM_END |
0a8fbbe180db
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
3578
diff
changeset
|
910 |
|
0a8fbbe180db
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
3578
diff
changeset
|
911 |
JVM_ENTRY(jclass, JVM_DefineClassWithSourceCond(JNIEnv *env, const char *name, |
0a8fbbe180db
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
3578
diff
changeset
|
912 |
jobject loader, const jbyte *buf, |
0a8fbbe180db
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
3578
diff
changeset
|
913 |
jsize len, jobject pd, |
0a8fbbe180db
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
3578
diff
changeset
|
914 |
const char *source, jboolean verify)) |
0a8fbbe180db
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
3578
diff
changeset
|
915 |
JVMWrapper2("JVM_DefineClassWithSourceCond %s", name); |
0a8fbbe180db
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
3578
diff
changeset
|
916 |
|
0a8fbbe180db
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
3578
diff
changeset
|
917 |
return jvm_define_class_common(env, name, loader, buf, len, pd, source, verify, THREAD); |
0a8fbbe180db
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
3578
diff
changeset
|
918 |
JVM_END |
1 | 919 |
|
920 |
JVM_ENTRY(jclass, JVM_FindLoadedClass(JNIEnv *env, jobject loader, jstring name)) |
|
921 |
JVMWrapper("JVM_FindLoadedClass"); |
|
922 |
ResourceMark rm(THREAD); |
|
923 |
||
924 |
Handle h_name (THREAD, JNIHandles::resolve_non_null(name)); |
|
925 |
Handle string = java_lang_String::internalize_classname(h_name, CHECK_NULL); |
|
926 |
||
927 |
const char* str = java_lang_String::as_utf8_string(string()); |
|
928 |
// Sanity check, don't expect null |
|
929 |
if (str == NULL) return NULL; |
|
930 |
||
931 |
const int str_len = (int)strlen(str); |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
932 |
if (str_len > Symbol::max_length()) { |
1 | 933 |
// It's impossible to create this class; the name cannot fit |
934 |
// into the constant pool. |
|
935 |
return NULL; |
|
936 |
} |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
937 |
TempNewSymbol klass_name = SymbolTable::new_symbol(str, str_len, CHECK_NULL); |
1 | 938 |
|
939 |
// Security Note: |
|
940 |
// The Java level wrapper will perform the necessary security check allowing |
|
941 |
// us to pass the NULL as the initiating class loader. |
|
942 |
Handle h_loader(THREAD, JNIHandles::resolve(loader)); |
|
943 |
if (UsePerfData) { |
|
944 |
is_lock_held_by_thread(h_loader, |
|
945 |
ClassLoader::sync_JVMFindLoadedClassLockFreeCounter(), |
|
946 |
THREAD); |
|
947 |
} |
|
948 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
949 |
Klass* k = SystemDictionary::find_instance_or_array_klass(klass_name, |
1 | 950 |
h_loader, |
951 |
Handle(), |
|
952 |
CHECK_NULL); |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25716
diff
changeset
|
953 |
#if INCLUDE_CDS |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25716
diff
changeset
|
954 |
if (k == NULL) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25716
diff
changeset
|
955 |
// If the class is not already loaded, try to see if it's in the shared |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25716
diff
changeset
|
956 |
// archive for the current classloader (h_loader). |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25716
diff
changeset
|
957 |
instanceKlassHandle ik = SystemDictionaryShared::find_or_load_shared_class( |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25716
diff
changeset
|
958 |
klass_name, h_loader, CHECK_NULL); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25716
diff
changeset
|
959 |
k = ik(); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25716
diff
changeset
|
960 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25716
diff
changeset
|
961 |
#endif |
1 | 962 |
return (k == NULL) ? NULL : |
14488 | 963 |
(jclass) JNIHandles::make_local(env, k->java_mirror()); |
1 | 964 |
JVM_END |
965 |
||
966 |
||
967 |
// Reflection support ////////////////////////////////////////////////////////////////////////////// |
|
968 |
||
969 |
JVM_ENTRY(jstring, JVM_GetClassName(JNIEnv *env, jclass cls)) |
|
970 |
assert (cls != NULL, "illegal class"); |
|
971 |
JVMWrapper("JVM_GetClassName"); |
|
972 |
JvmtiVMObjectAllocEventCollector oam; |
|
973 |
ResourceMark rm(THREAD); |
|
974 |
const char* name; |
|
975 |
if (java_lang_Class::is_primitive(JNIHandles::resolve(cls))) { |
|
976 |
name = type2name(java_lang_Class::primitive_type(JNIHandles::resolve(cls))); |
|
977 |
} else { |
|
978 |
// Consider caching interned string in Klass |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
979 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls)); |
1 | 980 |
assert(k->is_klass(), "just checking"); |
14488 | 981 |
name = k->external_name(); |
1 | 982 |
} |
983 |
oop result = StringTable::intern((char*) name, CHECK_NULL); |
|
984 |
return (jstring) JNIHandles::make_local(env, result); |
|
985 |
JVM_END |
|
986 |
||
987 |
||
988 |
JVM_ENTRY(jobjectArray, JVM_GetClassInterfaces(JNIEnv *env, jclass cls)) |
|
989 |
JVMWrapper("JVM_GetClassInterfaces"); |
|
990 |
JvmtiVMObjectAllocEventCollector oam; |
|
991 |
oop mirror = JNIHandles::resolve_non_null(cls); |
|
992 |
||
993 |
// Special handling for primitive objects |
|
994 |
if (java_lang_Class::is_primitive(mirror)) { |
|
995 |
// Primitive objects does not have any interfaces |
|
4571 | 996 |
objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_NULL); |
1 | 997 |
return (jobjectArray) JNIHandles::make_local(env, r); |
998 |
} |
|
999 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1000 |
KlassHandle klass(thread, java_lang_Class::as_Klass(mirror)); |
1 | 1001 |
// Figure size of result array |
1002 |
int size; |
|
1003 |
if (klass->oop_is_instance()) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1004 |
size = InstanceKlass::cast(klass())->local_interfaces()->length(); |
1 | 1005 |
} else { |
1006 |
assert(klass->oop_is_objArray() || klass->oop_is_typeArray(), "Illegal mirror klass"); |
|
1007 |
size = 2; |
|
1008 |
} |
|
1009 |
||
1010 |
// Allocate result array |
|
4571 | 1011 |
objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(), size, CHECK_NULL); |
1 | 1012 |
objArrayHandle result (THREAD, r); |
1013 |
// Fill in result |
|
1014 |
if (klass->oop_is_instance()) { |
|
1015 |
// Regular instance klass, fill in all local interfaces |
|
1016 |
for (int index = 0; index < size; index++) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1017 |
Klass* k = InstanceKlass::cast(klass())->local_interfaces()->at(index); |
14488 | 1018 |
result->obj_at_put(index, k->java_mirror()); |
1 | 1019 |
} |
1020 |
} else { |
|
1021 |
// All arrays implement java.lang.Cloneable and java.io.Serializable |
|
14488 | 1022 |
result->obj_at_put(0, SystemDictionary::Cloneable_klass()->java_mirror()); |
1023 |
result->obj_at_put(1, SystemDictionary::Serializable_klass()->java_mirror()); |
|
1 | 1024 |
} |
1025 |
return (jobjectArray) JNIHandles::make_local(env, result()); |
|
1026 |
JVM_END |
|
1027 |
||
1028 |
||
1029 |
JVM_QUICK_ENTRY(jboolean, JVM_IsInterface(JNIEnv *env, jclass cls)) |
|
1030 |
JVMWrapper("JVM_IsInterface"); |
|
1031 |
oop mirror = JNIHandles::resolve_non_null(cls); |
|
1032 |
if (java_lang_Class::is_primitive(mirror)) { |
|
1033 |
return JNI_FALSE; |
|
1034 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1035 |
Klass* k = java_lang_Class::as_Klass(mirror); |
14488 | 1036 |
jboolean result = k->is_interface(); |
1037 |
assert(!result || k->oop_is_instance(), |
|
1 | 1038 |
"all interfaces are instance types"); |
1039 |
// The compiler intrinsic for isInterface tests the |
|
1040 |
// Klass::_access_flags bits in the same way. |
|
1041 |
return result; |
|
1042 |
JVM_END |
|
1043 |
||
1044 |
||
1045 |
JVM_ENTRY(jobjectArray, JVM_GetClassSigners(JNIEnv *env, jclass cls)) |
|
1046 |
JVMWrapper("JVM_GetClassSigners"); |
|
1047 |
JvmtiVMObjectAllocEventCollector oam; |
|
1048 |
if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) { |
|
1049 |
// There are no signers for primitive types |
|
1050 |
return NULL; |
|
1051 |
} |
|
1052 |
||
17826
9ad5cd464a75
8003421: NPG: Move oops out of InstanceKlass into mirror
coleenp
parents:
17370
diff
changeset
|
1053 |
objArrayOop signers = java_lang_Class::signers(JNIHandles::resolve_non_null(cls)); |
1 | 1054 |
|
1055 |
// If there are no signers set in the class, or if the class |
|
1056 |
// is an array, return NULL. |
|
1057 |
if (signers == NULL) return NULL; |
|
1058 |
||
1059 |
// copy of the signers array |
|
13952
e3cf184080bc
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
13728
diff
changeset
|
1060 |
Klass* element = ObjArrayKlass::cast(signers->klass())->element_klass(); |
1 | 1061 |
objArrayOop signers_copy = oopFactory::new_objArray(element, signers->length(), CHECK_NULL); |
1062 |
for (int index = 0; index < signers->length(); index++) { |
|
1063 |
signers_copy->obj_at_put(index, signers->obj_at(index)); |
|
1064 |
} |
|
1065 |
||
1066 |
// return the copy |
|
1067 |
return (jobjectArray) JNIHandles::make_local(env, signers_copy); |
|
1068 |
JVM_END |
|
1069 |
||
1070 |
||
1071 |
JVM_ENTRY(void, JVM_SetClassSigners(JNIEnv *env, jclass cls, jobjectArray signers)) |
|
1072 |
JVMWrapper("JVM_SetClassSigners"); |
|
1073 |
if (!java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) { |
|
1074 |
// This call is ignored for primitive types and arrays. |
|
1075 |
// Signers are only set once, ClassLoader.java, and thus shouldn't |
|
1076 |
// be called with an array. Only the bootstrap loader creates arrays. |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1077 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
14488 | 1078 |
if (k->oop_is_instance()) { |
17826
9ad5cd464a75
8003421: NPG: Move oops out of InstanceKlass into mirror
coleenp
parents:
17370
diff
changeset
|
1079 |
java_lang_Class::set_signers(k->java_mirror(), objArrayOop(JNIHandles::resolve(signers))); |
1 | 1080 |
} |
1081 |
} |
|
1082 |
JVM_END |
|
1083 |
||
1084 |
||
1085 |
JVM_ENTRY(jobject, JVM_GetProtectionDomain(JNIEnv *env, jclass cls)) |
|
1086 |
JVMWrapper("JVM_GetProtectionDomain"); |
|
1087 |
if (JNIHandles::resolve(cls) == NULL) { |
|
1088 |
THROW_(vmSymbols::java_lang_NullPointerException(), NULL); |
|
1089 |
} |
|
1090 |
||
1091 |
if (java_lang_Class::is_primitive(JNIHandles::resolve(cls))) { |
|
1092 |
// Primitive types does not have a protection domain. |
|
1093 |
return NULL; |
|
1094 |
} |
|
1095 |
||
17826
9ad5cd464a75
8003421: NPG: Move oops out of InstanceKlass into mirror
coleenp
parents:
17370
diff
changeset
|
1096 |
oop pd = java_lang_Class::protection_domain(JNIHandles::resolve(cls)); |
9ad5cd464a75
8003421: NPG: Move oops out of InstanceKlass into mirror
coleenp
parents:
17370
diff
changeset
|
1097 |
return (jobject) JNIHandles::make_local(env, pd); |
1 | 1098 |
JVM_END |
1099 |
||
1100 |
||
18056 | 1101 |
static bool is_authorized(Handle context, instanceKlassHandle klass, TRAPS) { |
1102 |
// If there is a security manager and protection domain, check the access |
|
1103 |
// in the protection domain, otherwise it is authorized. |
|
1104 |
if (java_lang_System::has_security_manager()) { |
|
1105 |
||
1106 |
// For bootstrapping, if pd implies method isn't in the JDK, allow |
|
1107 |
// this context to revert to older behavior. |
|
1108 |
// In this case the isAuthorized field in AccessControlContext is also not |
|
1109 |
// present. |
|
1110 |
if (Universe::protection_domain_implies_method() == NULL) { |
|
1111 |
return true; |
|
1112 |
} |
|
1113 |
||
1114 |
// Whitelist certain access control contexts |
|
1115 |
if (java_security_AccessControlContext::is_authorized(context)) { |
|
1116 |
return true; |
|
1117 |
} |
|
1118 |
||
1119 |
oop prot = klass->protection_domain(); |
|
1120 |
if (prot != NULL) { |
|
1121 |
// Call pd.implies(new SecurityPermission("createAccessControlContext")) |
|
1122 |
// in the new wrapper. |
|
1123 |
methodHandle m(THREAD, Universe::protection_domain_implies_method()); |
|
1124 |
Handle h_prot(THREAD, prot); |
|
1125 |
JavaValue result(T_BOOLEAN); |
|
1126 |
JavaCallArguments args(h_prot); |
|
1127 |
JavaCalls::call(&result, m, &args, CHECK_false); |
|
1128 |
return (result.get_jboolean() != 0); |
|
1129 |
} |
|
1130 |
} |
|
1131 |
return true; |
|
1132 |
} |
|
1133 |
||
1134 |
// Create an AccessControlContext with a protection domain with null codesource |
|
1135 |
// and null permissions - which gives no permissions. |
|
1136 |
oop create_dummy_access_control_context(TRAPS) { |
|
1137 |
InstanceKlass* pd_klass = InstanceKlass::cast(SystemDictionary::ProtectionDomain_klass()); |
|
23448
0bd799a983a8
8036630: Null ProtectionDomain in JVM can cause NPE because principals field is not initialized to an empty array
coleenp
parents:
23178
diff
changeset
|
1138 |
Handle obj = pd_klass->allocate_instance_handle(CHECK_NULL); |
0bd799a983a8
8036630: Null ProtectionDomain in JVM can cause NPE because principals field is not initialized to an empty array
coleenp
parents:
23178
diff
changeset
|
1139 |
// Call constructor ProtectionDomain(null, null); |
0bd799a983a8
8036630: Null ProtectionDomain in JVM can cause NPE because principals field is not initialized to an empty array
coleenp
parents:
23178
diff
changeset
|
1140 |
JavaValue result(T_VOID); |
0bd799a983a8
8036630: Null ProtectionDomain in JVM can cause NPE because principals field is not initialized to an empty array
coleenp
parents:
23178
diff
changeset
|
1141 |
JavaCalls::call_special(&result, obj, KlassHandle(THREAD, pd_klass), |
0bd799a983a8
8036630: Null ProtectionDomain in JVM can cause NPE because principals field is not initialized to an empty array
coleenp
parents:
23178
diff
changeset
|
1142 |
vmSymbols::object_initializer_name(), |
0bd799a983a8
8036630: Null ProtectionDomain in JVM can cause NPE because principals field is not initialized to an empty array
coleenp
parents:
23178
diff
changeset
|
1143 |
vmSymbols::codesource_permissioncollection_signature(), |
0bd799a983a8
8036630: Null ProtectionDomain in JVM can cause NPE because principals field is not initialized to an empty array
coleenp
parents:
23178
diff
changeset
|
1144 |
Handle(), Handle(), CHECK_NULL); |
18056 | 1145 |
|
1146 |
// new ProtectionDomain[] {pd}; |
|
1147 |
objArrayOop context = oopFactory::new_objArray(pd_klass, 1, CHECK_NULL); |
|
23448
0bd799a983a8
8036630: Null ProtectionDomain in JVM can cause NPE because principals field is not initialized to an empty array
coleenp
parents:
23178
diff
changeset
|
1148 |
context->obj_at_put(0, obj()); |
18056 | 1149 |
|
1150 |
// new AccessControlContext(new ProtectionDomain[] {pd}) |
|
1151 |
objArrayHandle h_context(THREAD, context); |
|
23448
0bd799a983a8
8036630: Null ProtectionDomain in JVM can cause NPE because principals field is not initialized to an empty array
coleenp
parents:
23178
diff
changeset
|
1152 |
oop acc = java_security_AccessControlContext::create(h_context, false, Handle(), CHECK_NULL); |
0bd799a983a8
8036630: Null ProtectionDomain in JVM can cause NPE because principals field is not initialized to an empty array
coleenp
parents:
23178
diff
changeset
|
1153 |
return acc; |
18056 | 1154 |
} |
1 | 1155 |
|
1156 |
JVM_ENTRY(jobject, JVM_DoPrivileged(JNIEnv *env, jclass cls, jobject action, jobject context, jboolean wrapException)) |
|
1157 |
JVMWrapper("JVM_DoPrivileged"); |
|
1158 |
||
1159 |
if (action == NULL) { |
|
1160 |
THROW_MSG_0(vmSymbols::java_lang_NullPointerException(), "Null action"); |
|
1161 |
} |
|
1162 |
||
18056 | 1163 |
// Compute the frame initiating the do privileged operation and setup the privileged stack |
1164 |
vframeStream vfst(thread); |
|
1165 |
vfst.security_get_caller_frame(1); |
|
1166 |
||
1167 |
if (vfst.at_end()) { |
|
1168 |
THROW_MSG_0(vmSymbols::java_lang_InternalError(), "no caller?"); |
|
1169 |
} |
|
1170 |
||
1171 |
Method* method = vfst.method(); |
|
1172 |
instanceKlassHandle klass (THREAD, method->method_holder()); |
|
1173 |
||
1174 |
// Check that action object understands "Object run()" |
|
1175 |
Handle h_context; |
|
1176 |
if (context != NULL) { |
|
1177 |
h_context = Handle(THREAD, JNIHandles::resolve(context)); |
|
1178 |
bool authorized = is_authorized(h_context, klass, CHECK_NULL); |
|
1179 |
if (!authorized) { |
|
1180 |
// Create an unprivileged access control object and call it's run function |
|
1181 |
// instead. |
|
1182 |
oop noprivs = create_dummy_access_control_context(CHECK_NULL); |
|
1183 |
h_context = Handle(THREAD, noprivs); |
|
1184 |
} |
|
1185 |
} |
|
1 | 1186 |
|
1187 |
// Check that action object understands "Object run()" |
|
1188 |
Handle object (THREAD, JNIHandles::resolve(action)); |
|
1189 |
||
1190 |
// get run() method |
|
14488 | 1191 |
Method* m_oop = object->klass()->uncached_lookup_method( |
1 | 1192 |
vmSymbols::run_method_name(), |
23999
22eb7be3d99d
8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents:
23448
diff
changeset
|
1193 |
vmSymbols::void_object_signature(), |
22eb7be3d99d
8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents:
23448
diff
changeset
|
1194 |
Klass::normal); |
1 | 1195 |
methodHandle m (THREAD, m_oop); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1196 |
if (m.is_null() || !m->is_method() || !m()->is_public() || m()->is_static()) { |
1 | 1197 |
THROW_MSG_0(vmSymbols::java_lang_InternalError(), "No run method"); |
1198 |
} |
|
1199 |
||
18056 | 1200 |
// Stack allocated list of privileged stack elements |
1201 |
PrivilegedElement pi; |
|
1 | 1202 |
if (!vfst.at_end()) { |
18056 | 1203 |
pi.initialize(&vfst, h_context(), thread->privileged_stack_top(), CHECK_NULL); |
1 | 1204 |
thread->set_privileged_stack_top(&pi); |
1205 |
} |
|
1206 |
||
1207 |
||
1208 |
// invoke the Object run() in the action object. We cannot use call_interface here, since the static type |
|
1209 |
// is not really known - it is either java.security.PrivilegedAction or java.security.PrivilegedExceptionAction |
|
1210 |
Handle pending_exception; |
|
1211 |
JavaValue result(T_OBJECT); |
|
1212 |
JavaCallArguments args(object); |
|
1213 |
JavaCalls::call(&result, m, &args, THREAD); |
|
1214 |
||
1215 |
// done with action, remove ourselves from the list |
|
1216 |
if (!vfst.at_end()) { |
|
1217 |
assert(thread->privileged_stack_top() != NULL && thread->privileged_stack_top() == &pi, "wrong top element"); |
|
1218 |
thread->set_privileged_stack_top(thread->privileged_stack_top()->next()); |
|
1219 |
} |
|
1220 |
||
1221 |
if (HAS_PENDING_EXCEPTION) { |
|
1222 |
pending_exception = Handle(THREAD, PENDING_EXCEPTION); |
|
1223 |
CLEAR_PENDING_EXCEPTION; |
|
22897
77e1024a4a14
4505697: nsk/jdi/ExceptionEvent/_itself_/exevent006 and exevent008 tests fail with InvocationTargetException
jbachorik
parents:
22881
diff
changeset
|
1224 |
// JVMTI has already reported the pending exception |
77e1024a4a14
4505697: nsk/jdi/ExceptionEvent/_itself_/exevent006 and exevent008 tests fail with InvocationTargetException
jbachorik
parents:
22881
diff
changeset
|
1225 |
// JVMTI internal flag reset is needed in order to report PrivilegedActionException |
77e1024a4a14
4505697: nsk/jdi/ExceptionEvent/_itself_/exevent006 and exevent008 tests fail with InvocationTargetException
jbachorik
parents:
22881
diff
changeset
|
1226 |
if (THREAD->is_Java_thread()) { |
77e1024a4a14
4505697: nsk/jdi/ExceptionEvent/_itself_/exevent006 and exevent008 tests fail with InvocationTargetException
jbachorik
parents:
22881
diff
changeset
|
1227 |
JvmtiExport::clear_detected_exception((JavaThread*) THREAD); |
77e1024a4a14
4505697: nsk/jdi/ExceptionEvent/_itself_/exevent006 and exevent008 tests fail with InvocationTargetException
jbachorik
parents:
22881
diff
changeset
|
1228 |
} |
4571 | 1229 |
if ( pending_exception->is_a(SystemDictionary::Exception_klass()) && |
1230 |
!pending_exception->is_a(SystemDictionary::RuntimeException_klass())) { |
|
1 | 1231 |
// Throw a java.security.PrivilegedActionException(Exception e) exception |
1232 |
JavaCallArguments args(pending_exception); |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
1233 |
THROW_ARG_0(vmSymbols::java_security_PrivilegedActionException(), |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
1234 |
vmSymbols::exception_void_signature(), |
1 | 1235 |
&args); |
1236 |
} |
|
1237 |
} |
|
1238 |
||
1239 |
if (pending_exception.not_null()) THROW_OOP_0(pending_exception()); |
|
1240 |
return JNIHandles::make_local(env, (oop) result.get_jobject()); |
|
1241 |
JVM_END |
|
1242 |
||
1243 |
||
1244 |
// Returns the inherited_access_control_context field of the running thread. |
|
1245 |
JVM_ENTRY(jobject, JVM_GetInheritedAccessControlContext(JNIEnv *env, jclass cls)) |
|
1246 |
JVMWrapper("JVM_GetInheritedAccessControlContext"); |
|
1247 |
oop result = java_lang_Thread::inherited_access_control_context(thread->threadObj()); |
|
1248 |
return JNIHandles::make_local(env, result); |
|
1249 |
JVM_END |
|
1250 |
||
1251 |
class RegisterArrayForGC { |
|
1252 |
private: |
|
1253 |
JavaThread *_thread; |
|
1254 |
public: |
|
1255 |
RegisterArrayForGC(JavaThread *thread, GrowableArray<oop>* array) { |
|
1256 |
_thread = thread; |
|
1257 |
_thread->register_array_for_gc(array); |
|
1258 |
} |
|
1259 |
||
1260 |
~RegisterArrayForGC() { |
|
1261 |
_thread->register_array_for_gc(NULL); |
|
1262 |
} |
|
1263 |
}; |
|
1264 |
||
1265 |
||
1266 |
JVM_ENTRY(jobject, JVM_GetStackAccessControlContext(JNIEnv *env, jclass cls)) |
|
1267 |
JVMWrapper("JVM_GetStackAccessControlContext"); |
|
1268 |
if (!UsePrivilegedStack) return NULL; |
|
1269 |
||
1270 |
ResourceMark rm(THREAD); |
|
1271 |
GrowableArray<oop>* local_array = new GrowableArray<oop>(12); |
|
1272 |
JvmtiVMObjectAllocEventCollector oam; |
|
1273 |
||
1274 |
// count the protection domains on the execution stack. We collapse |
|
1275 |
// duplicate consecutive protection domains into a single one, as |
|
1276 |
// well as stopping when we hit a privileged frame. |
|
1277 |
||
1278 |
// Use vframeStream to iterate through Java frames |
|
1279 |
vframeStream vfst(thread); |
|
1280 |
||
1281 |
oop previous_protection_domain = NULL; |
|
1282 |
Handle privileged_context(thread, NULL); |
|
1283 |
bool is_privileged = false; |
|
1284 |
oop protection_domain = NULL; |
|
1285 |
||
1286 |
for(; !vfst.at_end(); vfst.next()) { |
|
1287 |
// get method of frame |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1288 |
Method* method = vfst.method(); |
1 | 1289 |
intptr_t* frame_id = vfst.frame_id(); |
1290 |
||
1291 |
// check the privileged frames to see if we have a match |
|
1292 |
if (thread->privileged_stack_top() && thread->privileged_stack_top()->frame_id() == frame_id) { |
|
1293 |
// this frame is privileged |
|
1294 |
is_privileged = true; |
|
1295 |
privileged_context = Handle(thread, thread->privileged_stack_top()->privileged_context()); |
|
1296 |
protection_domain = thread->privileged_stack_top()->protection_domain(); |
|
1297 |
} else { |
|
14391
df0a1573d5bd
8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents:
13952
diff
changeset
|
1298 |
protection_domain = method->method_holder()->protection_domain(); |
1 | 1299 |
} |
1300 |
||
1301 |
if ((previous_protection_domain != protection_domain) && (protection_domain != NULL)) { |
|
1302 |
local_array->push(protection_domain); |
|
1303 |
previous_protection_domain = protection_domain; |
|
1304 |
} |
|
1305 |
||
1306 |
if (is_privileged) break; |
|
1307 |
} |
|
1308 |
||
1309 |
||
1310 |
// either all the domains on the stack were system domains, or |
|
1311 |
// we had a privileged system domain |
|
1312 |
if (local_array->is_empty()) { |
|
1313 |
if (is_privileged && privileged_context.is_null()) return NULL; |
|
1314 |
||
1315 |
oop result = java_security_AccessControlContext::create(objArrayHandle(), is_privileged, privileged_context, CHECK_NULL); |
|
1316 |
return JNIHandles::make_local(env, result); |
|
1317 |
} |
|
1318 |
||
1319 |
// the resource area must be registered in case of a gc |
|
1320 |
RegisterArrayForGC ragc(thread, local_array); |
|
4571 | 1321 |
objArrayOop context = oopFactory::new_objArray(SystemDictionary::ProtectionDomain_klass(), |
1 | 1322 |
local_array->length(), CHECK_NULL); |
1323 |
objArrayHandle h_context(thread, context); |
|
1324 |
for (int index = 0; index < local_array->length(); index++) { |
|
1325 |
h_context->obj_at_put(index, local_array->at(index)); |
|
1326 |
} |
|
1327 |
||
1328 |
oop result = java_security_AccessControlContext::create(h_context, is_privileged, privileged_context, CHECK_NULL); |
|
1329 |
||
1330 |
return JNIHandles::make_local(env, result); |
|
1331 |
JVM_END |
|
1332 |
||
1333 |
||
1334 |
JVM_QUICK_ENTRY(jboolean, JVM_IsArrayClass(JNIEnv *env, jclass cls)) |
|
1335 |
JVMWrapper("JVM_IsArrayClass"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1336 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
14488 | 1337 |
return (k != NULL) && k->oop_is_array() ? true : false; |
1 | 1338 |
JVM_END |
1339 |
||
1340 |
||
1341 |
JVM_QUICK_ENTRY(jboolean, JVM_IsPrimitiveClass(JNIEnv *env, jclass cls)) |
|
1342 |
JVMWrapper("JVM_IsPrimitiveClass"); |
|
1343 |
oop mirror = JNIHandles::resolve_non_null(cls); |
|
1344 |
return (jboolean) java_lang_Class::is_primitive(mirror); |
|
1345 |
JVM_END |
|
1346 |
||
1347 |
||
1348 |
JVM_ENTRY(jint, JVM_GetClassModifiers(JNIEnv *env, jclass cls)) |
|
1349 |
JVMWrapper("JVM_GetClassModifiers"); |
|
1350 |
if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) { |
|
1351 |
// Primitive type |
|
1352 |
return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC; |
|
1353 |
} |
|
1354 |
||
14488 | 1355 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
1 | 1356 |
debug_only(int computed_modifiers = k->compute_modifier_flags(CHECK_0)); |
1357 |
assert(k->modifier_flags() == computed_modifiers, "modifiers cache is OK"); |
|
1358 |
return k->modifier_flags(); |
|
1359 |
JVM_END |
|
1360 |
||
1361 |
||
1362 |
// Inner class reflection /////////////////////////////////////////////////////////////////////////////// |
|
1363 |
||
1364 |
JVM_ENTRY(jobjectArray, JVM_GetDeclaredClasses(JNIEnv *env, jclass ofClass)) |
|
1365 |
JvmtiVMObjectAllocEventCollector oam; |
|
1366 |
// ofClass is a reference to a java_lang_Class object. The mirror object |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1367 |
// of an InstanceKlass |
1 | 1368 |
|
1369 |
if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) || |
|
14488 | 1370 |
! java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->oop_is_instance()) { |
4571 | 1371 |
oop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_NULL); |
1 | 1372 |
return (jobjectArray)JNIHandles::make_local(env, result); |
1373 |
} |
|
1374 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1375 |
instanceKlassHandle k(thread, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))); |
12231
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11636
diff
changeset
|
1376 |
InnerClassesIterator iter(k); |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11636
diff
changeset
|
1377 |
|
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11636
diff
changeset
|
1378 |
if (iter.length() == 0) { |
1 | 1379 |
// Neither an inner nor outer class |
4571 | 1380 |
oop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_NULL); |
1 | 1381 |
return (jobjectArray)JNIHandles::make_local(env, result); |
1382 |
} |
|
1383 |
||
1384 |
// find inner class info |
|
1385 |
constantPoolHandle cp(thread, k->constants()); |
|
12231
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11636
diff
changeset
|
1386 |
int length = iter.length(); |
1 | 1387 |
|
1388 |
// Allocate temp. result array |
|
4571 | 1389 |
objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(), length/4, CHECK_NULL); |
1 | 1390 |
objArrayHandle result (THREAD, r); |
1391 |
int members = 0; |
|
1392 |
||
12231
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11636
diff
changeset
|
1393 |
for (; !iter.done(); iter.next()) { |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11636
diff
changeset
|
1394 |
int ioff = iter.inner_class_info_index(); |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11636
diff
changeset
|
1395 |
int ooff = iter.outer_class_info_index(); |
1 | 1396 |
|
1397 |
if (ioff != 0 && ooff != 0) { |
|
1398 |
// Check to see if the name matches the class we're looking for |
|
1399 |
// before attempting to find the class. |
|
1400 |
if (cp->klass_name_at_matches(k, ooff)) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1401 |
Klass* outer_klass = cp->klass_at(ooff, CHECK_NULL); |
1 | 1402 |
if (outer_klass == k()) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1403 |
Klass* ik = cp->klass_at(ioff, CHECK_NULL); |
1 | 1404 |
instanceKlassHandle inner_klass (THREAD, ik); |
1405 |
||
1406 |
// Throws an exception if outer klass has not declared k as |
|
1407 |
// an inner klass |
|
2332
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2105
diff
changeset
|
1408 |
Reflection::check_for_inner_class(k, inner_klass, true, CHECK_NULL); |
1 | 1409 |
|
1410 |
result->obj_at_put(members, inner_klass->java_mirror()); |
|
1411 |
members++; |
|
1412 |
} |
|
1413 |
} |
|
1414 |
} |
|
1415 |
} |
|
1416 |
||
1417 |
if (members != length) { |
|
1418 |
// Return array of right length |
|
4571 | 1419 |
objArrayOop res = oopFactory::new_objArray(SystemDictionary::Class_klass(), members, CHECK_NULL); |
1 | 1420 |
for(int i = 0; i < members; i++) { |
1421 |
res->obj_at_put(i, result->obj_at(i)); |
|
1422 |
} |
|
1423 |
return (jobjectArray)JNIHandles::make_local(env, res); |
|
1424 |
} |
|
1425 |
||
1426 |
return (jobjectArray)JNIHandles::make_local(env, result()); |
|
1427 |
JVM_END |
|
1428 |
||
1429 |
||
1430 |
JVM_ENTRY(jclass, JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass)) |
|
2332
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2105
diff
changeset
|
1431 |
{ |
1 | 1432 |
// ofClass is a reference to a java_lang_Class object. |
1433 |
if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) || |
|
14488 | 1434 |
! java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->oop_is_instance()) { |
1 | 1435 |
return NULL; |
1436 |
} |
|
1437 |
||
4496
c5a0b15a8e7d
6895168: JCK api/signaturetest/sigtest.basic.html#basic test fails for jdk 5.0 with HS 16 in nightly build
xlu
parents:
4429
diff
changeset
|
1438 |
bool inner_is_member = false; |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1439 |
Klass* outer_klass |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1440 |
= InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass)) |
4496
c5a0b15a8e7d
6895168: JCK api/signaturetest/sigtest.basic.html#basic test fails for jdk 5.0 with HS 16 in nightly build
xlu
parents:
4429
diff
changeset
|
1441 |
)->compute_enclosing_class(&inner_is_member, CHECK_NULL); |
2332
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2105
diff
changeset
|
1442 |
if (outer_klass == NULL) return NULL; // already a top-level class |
4496
c5a0b15a8e7d
6895168: JCK api/signaturetest/sigtest.basic.html#basic test fails for jdk 5.0 with HS 16 in nightly build
xlu
parents:
4429
diff
changeset
|
1443 |
if (!inner_is_member) return NULL; // an anonymous class (inside a method) |
14488 | 1444 |
return (jclass) JNIHandles::make_local(env, outer_klass->java_mirror()); |
2332
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2105
diff
changeset
|
1445 |
} |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2105
diff
changeset
|
1446 |
JVM_END |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2105
diff
changeset
|
1447 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1448 |
// should be in InstanceKlass.cpp, but is here for historical reasons |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1449 |
Klass* InstanceKlass::compute_enclosing_class_impl(instanceKlassHandle k, |
4496
c5a0b15a8e7d
6895168: JCK api/signaturetest/sigtest.basic.html#basic test fails for jdk 5.0 with HS 16 in nightly build
xlu
parents:
4429
diff
changeset
|
1450 |
bool* inner_is_member, |
c5a0b15a8e7d
6895168: JCK api/signaturetest/sigtest.basic.html#basic test fails for jdk 5.0 with HS 16 in nightly build
xlu
parents:
4429
diff
changeset
|
1451 |
TRAPS) { |
2332
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2105
diff
changeset
|
1452 |
Thread* thread = THREAD; |
12231
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11636
diff
changeset
|
1453 |
InnerClassesIterator iter(k); |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11636
diff
changeset
|
1454 |
if (iter.length() == 0) { |
1 | 1455 |
// No inner class info => no declaring class |
1456 |
return NULL; |
|
1457 |
} |
|
1458 |
||
1459 |
constantPoolHandle i_cp(thread, k->constants()); |
|
1460 |
||
1461 |
bool found = false; |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1462 |
Klass* ok; |
1 | 1463 |
instanceKlassHandle outer_klass; |
4496
c5a0b15a8e7d
6895168: JCK api/signaturetest/sigtest.basic.html#basic test fails for jdk 5.0 with HS 16 in nightly build
xlu
parents:
4429
diff
changeset
|
1464 |
*inner_is_member = false; |
1 | 1465 |
|
1466 |
// Find inner_klass attribute |
|
12231
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11636
diff
changeset
|
1467 |
for (; !iter.done() && !found; iter.next()) { |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11636
diff
changeset
|
1468 |
int ioff = iter.inner_class_info_index(); |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11636
diff
changeset
|
1469 |
int ooff = iter.outer_class_info_index(); |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11636
diff
changeset
|
1470 |
int noff = iter.inner_name_index(); |
2332
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2105
diff
changeset
|
1471 |
if (ioff != 0) { |
1 | 1472 |
// Check to see if the name matches the class we're looking for |
1473 |
// before attempting to find the class. |
|
1474 |
if (i_cp->klass_name_at_matches(k, ioff)) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1475 |
Klass* inner_klass = i_cp->klass_at(ioff, CHECK_NULL); |
2332
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2105
diff
changeset
|
1476 |
found = (k() == inner_klass); |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2105
diff
changeset
|
1477 |
if (found && ooff != 0) { |
1 | 1478 |
ok = i_cp->klass_at(ooff, CHECK_NULL); |
1479 |
outer_klass = instanceKlassHandle(thread, ok); |
|
4496
c5a0b15a8e7d
6895168: JCK api/signaturetest/sigtest.basic.html#basic test fails for jdk 5.0 with HS 16 in nightly build
xlu
parents:
4429
diff
changeset
|
1480 |
*inner_is_member = true; |
1 | 1481 |
} |
1482 |
} |
|
1483 |
} |
|
1484 |
} |
|
1485 |
||
2332
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2105
diff
changeset
|
1486 |
if (found && outer_klass.is_null()) { |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2105
diff
changeset
|
1487 |
// It may be anonymous; try for that. |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2105
diff
changeset
|
1488 |
int encl_method_class_idx = k->enclosing_method_class_index(); |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2105
diff
changeset
|
1489 |
if (encl_method_class_idx != 0) { |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2105
diff
changeset
|
1490 |
ok = i_cp->klass_at(encl_method_class_idx, CHECK_NULL); |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2105
diff
changeset
|
1491 |
outer_klass = instanceKlassHandle(thread, ok); |
4496
c5a0b15a8e7d
6895168: JCK api/signaturetest/sigtest.basic.html#basic test fails for jdk 5.0 with HS 16 in nightly build
xlu
parents:
4429
diff
changeset
|
1492 |
*inner_is_member = false; |
2332
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2105
diff
changeset
|
1493 |
} |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2105
diff
changeset
|
1494 |
} |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2105
diff
changeset
|
1495 |
|
1 | 1496 |
// If no inner class attribute found for this class. |
2332
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2105
diff
changeset
|
1497 |
if (outer_klass.is_null()) return NULL; |
1 | 1498 |
|
1499 |
// Throws an exception if outer klass has not declared k as an inner klass |
|
2332
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2105
diff
changeset
|
1500 |
// We need evidence that each klass knows about the other, or else |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2105
diff
changeset
|
1501 |
// the system could allow a spoof of an inner class to gain access rights. |
4496
c5a0b15a8e7d
6895168: JCK api/signaturetest/sigtest.basic.html#basic test fails for jdk 5.0 with HS 16 in nightly build
xlu
parents:
4429
diff
changeset
|
1502 |
Reflection::check_for_inner_class(outer_klass, k, *inner_is_member, CHECK_NULL); |
2332
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2105
diff
changeset
|
1503 |
return outer_klass(); |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2105
diff
changeset
|
1504 |
} |
1 | 1505 |
|
1506 |
JVM_ENTRY(jstring, JVM_GetClassSignature(JNIEnv *env, jclass cls)) |
|
1507 |
assert (cls != NULL, "illegal class"); |
|
1508 |
JVMWrapper("JVM_GetClassSignature"); |
|
1509 |
JvmtiVMObjectAllocEventCollector oam; |
|
1510 |
ResourceMark rm(THREAD); |
|
1511 |
// Return null for arrays and primatives |
|
1512 |
if (!java_lang_Class::is_primitive(JNIHandles::resolve(cls))) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1513 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls)); |
14488 | 1514 |
if (k->oop_is_instance()) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1515 |
Symbol* sym = InstanceKlass::cast(k)->generic_signature(); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
1516 |
if (sym == NULL) return NULL; |
1 | 1517 |
Handle str = java_lang_String::create_from_symbol(sym, CHECK_NULL); |
1518 |
return (jstring) JNIHandles::make_local(env, str()); |
|
1519 |
} |
|
1520 |
} |
|
1521 |
return NULL; |
|
1522 |
JVM_END |
|
1523 |
||
1524 |
||
1525 |
JVM_ENTRY(jbyteArray, JVM_GetClassAnnotations(JNIEnv *env, jclass cls)) |
|
1526 |
assert (cls != NULL, "illegal class"); |
|
1527 |
JVMWrapper("JVM_GetClassAnnotations"); |
|
16444
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1528 |
|
1 | 1529 |
// Return null for arrays and primitives |
1530 |
if (!java_lang_Class::is_primitive(JNIHandles::resolve(cls))) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1531 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls)); |
14488 | 1532 |
if (k->oop_is_instance()) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1533 |
typeArrayOop a = Annotations::make_java_array(InstanceKlass::cast(k)->class_annotations(), CHECK_NULL); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1534 |
return (jbyteArray) JNIHandles::make_local(env, a); |
1 | 1535 |
} |
1536 |
} |
|
1537 |
return NULL; |
|
1538 |
JVM_END |
|
1539 |
||
1540 |
||
16444
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1541 |
static bool jvm_get_field_common(jobject field, fieldDescriptor& fd, TRAPS) { |
1 | 1542 |
// some of this code was adapted from from jni_FromReflectedField |
1543 |
||
1544 |
oop reflected = JNIHandles::resolve_non_null(field); |
|
1545 |
oop mirror = java_lang_reflect_Field::clazz(reflected); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1546 |
Klass* k = java_lang_Class::as_Klass(mirror); |
1 | 1547 |
int slot = java_lang_reflect_Field::slot(reflected); |
1548 |
int modifiers = java_lang_reflect_Field::modifiers(reflected); |
|
1549 |
||
1550 |
KlassHandle kh(THREAD, k); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1551 |
intptr_t offset = InstanceKlass::cast(kh())->field_offset(slot); |
1 | 1552 |
|
1553 |
if (modifiers & JVM_ACC_STATIC) { |
|
1554 |
// for static fields we only look in the current class |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1555 |
if (!InstanceKlass::cast(kh())->find_local_field_from_offset(offset, true, &fd)) { |
1 | 1556 |
assert(false, "cannot find static field"); |
16444
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1557 |
return false; |
1 | 1558 |
} |
1559 |
} else { |
|
1560 |
// for instance fields we start with the current class and work |
|
1561 |
// our way up through the superclass chain |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1562 |
if (!InstanceKlass::cast(kh())->find_field_from_offset(offset, false, &fd)) { |
1 | 1563 |
assert(false, "cannot find instance field"); |
16444
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1564 |
return false; |
1 | 1565 |
} |
1566 |
} |
|
16444
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1567 |
return true; |
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1568 |
} |
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1569 |
|
15102
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
1570 |
static Method* jvm_get_method_common(jobject method) { |
1 | 1571 |
// some of this code was adapted from from jni_FromReflectedMethod |
1572 |
||
1573 |
oop reflected = JNIHandles::resolve_non_null(method); |
|
1574 |
oop mirror = NULL; |
|
1575 |
int slot = 0; |
|
1576 |
||
4571 | 1577 |
if (reflected->klass() == SystemDictionary::reflect_Constructor_klass()) { |
1 | 1578 |
mirror = java_lang_reflect_Constructor::clazz(reflected); |
1579 |
slot = java_lang_reflect_Constructor::slot(reflected); |
|
1580 |
} else { |
|
4571 | 1581 |
assert(reflected->klass() == SystemDictionary::reflect_Method_klass(), |
1 | 1582 |
"wrong type"); |
1583 |
mirror = java_lang_reflect_Method::clazz(reflected); |
|
1584 |
slot = java_lang_reflect_Method::slot(reflected); |
|
1585 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1586 |
Klass* k = java_lang_Class::as_Klass(mirror); |
1 | 1587 |
|
15102
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
1588 |
Method* m = InstanceKlass::cast(k)->method_with_idnum(slot); |
16444
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1589 |
assert(m != NULL, "cannot find method"); |
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1590 |
return m; // caller has to deal with NULL in product mode |
1 | 1591 |
} |
1592 |
||
15097
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14488
diff
changeset
|
1593 |
/* Type use annotations support (JDK 1.8) */ |
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14488
diff
changeset
|
1594 |
|
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14488
diff
changeset
|
1595 |
JVM_ENTRY(jbyteArray, JVM_GetClassTypeAnnotations(JNIEnv *env, jclass cls)) |
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14488
diff
changeset
|
1596 |
assert (cls != NULL, "illegal class"); |
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14488
diff
changeset
|
1597 |
JVMWrapper("JVM_GetClassTypeAnnotations"); |
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14488
diff
changeset
|
1598 |
ResourceMark rm(THREAD); |
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14488
diff
changeset
|
1599 |
// Return null for arrays and primitives |
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14488
diff
changeset
|
1600 |
if (!java_lang_Class::is_primitive(JNIHandles::resolve(cls))) { |
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14488
diff
changeset
|
1601 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls)); |
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14488
diff
changeset
|
1602 |
if (k->oop_is_instance()) { |
15601 | 1603 |
AnnotationArray* type_annotations = InstanceKlass::cast(k)->class_type_annotations(); |
15217
af9400e71d87
8005994: Method annotations are allocated unnecessarily during class file parsing
stefank
parents:
15102
diff
changeset
|
1604 |
if (type_annotations != NULL) { |
15601 | 1605 |
typeArrayOop a = Annotations::make_java_array(type_annotations, CHECK_NULL); |
15217
af9400e71d87
8005994: Method annotations are allocated unnecessarily during class file parsing
stefank
parents:
15102
diff
changeset
|
1606 |
return (jbyteArray) JNIHandles::make_local(env, a); |
af9400e71d87
8005994: Method annotations are allocated unnecessarily during class file parsing
stefank
parents:
15102
diff
changeset
|
1607 |
} |
15097
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14488
diff
changeset
|
1608 |
} |
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14488
diff
changeset
|
1609 |
} |
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14488
diff
changeset
|
1610 |
return NULL; |
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14488
diff
changeset
|
1611 |
JVM_END |
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14488
diff
changeset
|
1612 |
|
16444
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1613 |
JVM_ENTRY(jbyteArray, JVM_GetMethodTypeAnnotations(JNIEnv *env, jobject method)) |
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1614 |
assert (method != NULL, "illegal method"); |
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1615 |
JVMWrapper("JVM_GetMethodTypeAnnotations"); |
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1616 |
|
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1617 |
// method is a handle to a java.lang.reflect.Method object |
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1618 |
Method* m = jvm_get_method_common(method); |
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1619 |
if (m == NULL) { |
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1620 |
return NULL; |
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1621 |
} |
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1622 |
|
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1623 |
AnnotationArray* type_annotations = m->type_annotations(); |
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1624 |
if (type_annotations != NULL) { |
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1625 |
typeArrayOop a = Annotations::make_java_array(type_annotations, CHECK_NULL); |
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1626 |
return (jbyteArray) JNIHandles::make_local(env, a); |
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1627 |
} |
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1628 |
|
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1629 |
return NULL; |
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1630 |
JVM_END |
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1631 |
|
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1632 |
JVM_ENTRY(jbyteArray, JVM_GetFieldTypeAnnotations(JNIEnv *env, jobject field)) |
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1633 |
assert (field != NULL, "illegal field"); |
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1634 |
JVMWrapper("JVM_GetFieldTypeAnnotations"); |
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1635 |
|
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1636 |
fieldDescriptor fd; |
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1637 |
bool gotFd = jvm_get_field_common(field, fd, CHECK_NULL); |
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1638 |
if (!gotFd) { |
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1639 |
return NULL; |
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1640 |
} |
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1641 |
|
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1642 |
return (jbyteArray) JNIHandles::make_local(env, Annotations::make_java_array(fd.type_annotations(), THREAD)); |
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1643 |
JVM_END |
e9cfab742724
8009382: Add JVM_Get{Field|Method}TypeAnnotations
rbackman
parents:
16431
diff
changeset
|
1644 |
|
15194
a35093d73168
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
15102
diff
changeset
|
1645 |
static void bounds_check(constantPoolHandle cp, jint index, TRAPS) { |
a35093d73168
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
15102
diff
changeset
|
1646 |
if (!cp->is_within_bounds(index)) { |
a35093d73168
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
15102
diff
changeset
|
1647 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Constant pool index out of bounds"); |
a35093d73168
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
15102
diff
changeset
|
1648 |
} |
a35093d73168
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
15102
diff
changeset
|
1649 |
} |
a35093d73168
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
15102
diff
changeset
|
1650 |
|
15102
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
1651 |
JVM_ENTRY(jobjectArray, JVM_GetMethodParameters(JNIEnv *env, jobject method)) |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
1652 |
{ |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
1653 |
JVMWrapper("JVM_GetMethodParameters"); |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
1654 |
// method is a handle to a java.lang.reflect.Method object |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
1655 |
Method* method_ptr = jvm_get_method_common(method); |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
1656 |
methodHandle mh (THREAD, method_ptr); |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
1657 |
Handle reflected_method (THREAD, JNIHandles::resolve_non_null(method)); |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
1658 |
const int num_params = mh->method_parameters_length(); |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
1659 |
|
27612
7201412afbd0
8058313: Mismatch of method descriptor and MethodParameters.parameters_count should cause MalformedParameterException
emc
parents:
27471
diff
changeset
|
1660 |
if (num_params < 0) { |
7201412afbd0
8058313: Mismatch of method descriptor and MethodParameters.parameters_count should cause MalformedParameterException
emc
parents:
27471
diff
changeset
|
1661 |
// A -1 return value from method_parameters_length means there is no |
7201412afbd0
8058313: Mismatch of method descriptor and MethodParameters.parameters_count should cause MalformedParameterException
emc
parents:
27471
diff
changeset
|
1662 |
// parameter data. Return null to indicate this to the reflection |
7201412afbd0
8058313: Mismatch of method descriptor and MethodParameters.parameters_count should cause MalformedParameterException
emc
parents:
27471
diff
changeset
|
1663 |
// API. |
7201412afbd0
8058313: Mismatch of method descriptor and MethodParameters.parameters_count should cause MalformedParameterException
emc
parents:
27471
diff
changeset
|
1664 |
assert(num_params == -1, "num_params should be -1 if it is less than zero"); |
7201412afbd0
8058313: Mismatch of method descriptor and MethodParameters.parameters_count should cause MalformedParameterException
emc
parents:
27471
diff
changeset
|
1665 |
return (jobjectArray)NULL; |
7201412afbd0
8058313: Mismatch of method descriptor and MethodParameters.parameters_count should cause MalformedParameterException
emc
parents:
27471
diff
changeset
|
1666 |
} else { |
7201412afbd0
8058313: Mismatch of method descriptor and MethodParameters.parameters_count should cause MalformedParameterException
emc
parents:
27471
diff
changeset
|
1667 |
// Otherwise, we return something up to reflection, even if it is |
7201412afbd0
8058313: Mismatch of method descriptor and MethodParameters.parameters_count should cause MalformedParameterException
emc
parents:
27471
diff
changeset
|
1668 |
// a zero-length array. Why? Because in some cases this can |
7201412afbd0
8058313: Mismatch of method descriptor and MethodParameters.parameters_count should cause MalformedParameterException
emc
parents:
27471
diff
changeset
|
1669 |
// trigger a MalformedParametersException. |
7201412afbd0
8058313: Mismatch of method descriptor and MethodParameters.parameters_count should cause MalformedParameterException
emc
parents:
27471
diff
changeset
|
1670 |
|
15194
a35093d73168
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
15102
diff
changeset
|
1671 |
// make sure all the symbols are properly formatted |
a35093d73168
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
15102
diff
changeset
|
1672 |
for (int i = 0; i < num_params; i++) { |
a35093d73168
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
15102
diff
changeset
|
1673 |
MethodParametersElement* params = mh->method_parameters_start(); |
a35093d73168
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
15102
diff
changeset
|
1674 |
int index = params[i].name_cp_index; |
a35093d73168
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
15102
diff
changeset
|
1675 |
bounds_check(mh->constants(), index, CHECK_NULL); |
a35093d73168
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
15102
diff
changeset
|
1676 |
|
a35093d73168
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
15102
diff
changeset
|
1677 |
if (0 != index && !mh->constants()->tag_at(index).is_utf8()) { |
a35093d73168
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
15102
diff
changeset
|
1678 |
THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), |
a35093d73168
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
15102
diff
changeset
|
1679 |
"Wrong type at constant pool index"); |
a35093d73168
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
15102
diff
changeset
|
1680 |
} |
a35093d73168
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
15102
diff
changeset
|
1681 |
|
a35093d73168
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
15102
diff
changeset
|
1682 |
} |
a35093d73168
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
15102
diff
changeset
|
1683 |
|
15102
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
1684 |
objArrayOop result_oop = oopFactory::new_objArray(SystemDictionary::reflect_Parameter_klass(), num_params, CHECK_NULL); |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
1685 |
objArrayHandle result (THREAD, result_oop); |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
1686 |
|
15194
a35093d73168
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
15102
diff
changeset
|
1687 |
for (int i = 0; i < num_params; i++) { |
15102
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
1688 |
MethodParametersElement* params = mh->method_parameters_start(); |
15194
a35093d73168
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
15102
diff
changeset
|
1689 |
// For a 0 index, give a NULL symbol |
17370
59a0620561fa
8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents:
16621
diff
changeset
|
1690 |
Symbol* sym = 0 != params[i].name_cp_index ? |
15194
a35093d73168
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
15102
diff
changeset
|
1691 |
mh->constants()->symbol_at(params[i].name_cp_index) : NULL; |
15464
1f2cca0aa501
8006949: Update hotspot for MethodParameters format change
emc
parents:
15439
diff
changeset
|
1692 |
int flags = params[i].flags; |
15102
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
1693 |
oop param = Reflection::new_parameter(reflected_method, i, sym, |
15194
a35093d73168
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
15102
diff
changeset
|
1694 |
flags, CHECK_NULL); |
15102
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
1695 |
result->obj_at_put(i, param); |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
1696 |
} |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
1697 |
return (jobjectArray)JNIHandles::make_local(env, result()); |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
1698 |
} |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
1699 |
} |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
1700 |
JVM_END |
1 | 1701 |
|
1702 |
// New (JDK 1.4) reflection implementation ///////////////////////////////////// |
|
1703 |
||
1704 |
JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean publicOnly)) |
|
1705 |
{ |
|
1706 |
JVMWrapper("JVM_GetClassDeclaredFields"); |
|
1707 |
JvmtiVMObjectAllocEventCollector oam; |
|
1708 |
||
1709 |
// Exclude primitive types and array types |
|
1710 |
if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) || |
|
14488 | 1711 |
java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->oop_is_array()) { |
1 | 1712 |
// Return empty array |
4571 | 1713 |
oop res = oopFactory::new_objArray(SystemDictionary::reflect_Field_klass(), 0, CHECK_NULL); |
1 | 1714 |
return (jobjectArray) JNIHandles::make_local(env, res); |
1715 |
} |
|
1716 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1717 |
instanceKlassHandle k(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))); |
1 | 1718 |
constantPoolHandle cp(THREAD, k->constants()); |
1719 |
||
1720 |
// Ensure class is linked |
|
1721 |
k->link_class(CHECK_NULL); |
|
1722 |
||
1723 |
// 4496456 We need to filter out java.lang.Throwable.backtrace |
|
1724 |
bool skip_backtrace = false; |
|
1725 |
||
1726 |
// Allocate result |
|
1727 |
int num_fields; |
|
1728 |
||
1729 |
if (publicOnly) { |
|
1730 |
num_fields = 0; |
|
10546 | 1731 |
for (JavaFieldStream fs(k()); !fs.done(); fs.next()) { |
1732 |
if (fs.access_flags().is_public()) ++num_fields; |
|
1 | 1733 |
} |
1734 |
} else { |
|
10546 | 1735 |
num_fields = k->java_fields_count(); |
1 | 1736 |
|
4571 | 1737 |
if (k() == SystemDictionary::Throwable_klass()) { |
1 | 1738 |
num_fields--; |
1739 |
skip_backtrace = true; |
|
1740 |
} |
|
1741 |
} |
|
1742 |
||
4571 | 1743 |
objArrayOop r = oopFactory::new_objArray(SystemDictionary::reflect_Field_klass(), num_fields, CHECK_NULL); |
1 | 1744 |
objArrayHandle result (THREAD, r); |
1745 |
||
1746 |
int out_idx = 0; |
|
1747 |
fieldDescriptor fd; |
|
10546 | 1748 |
for (JavaFieldStream fs(k); !fs.done(); fs.next()) { |
1 | 1749 |
if (skip_backtrace) { |
1750 |
// 4496456 skip java.lang.Throwable.backtrace |
|
10546 | 1751 |
int offset = fs.offset(); |
1 | 1752 |
if (offset == java_lang_Throwable::get_backtrace_offset()) continue; |
1753 |
} |
|
1754 |
||
10546 | 1755 |
if (!publicOnly || fs.access_flags().is_public()) { |
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
18690
diff
changeset
|
1756 |
fd.reinitialize(k(), fs.index()); |
24456
8c7933fa5a1f
8025580: Temporary flags: UseNewReflection and ReflectionWrapResolutionErrors
coleenp
parents:
24429
diff
changeset
|
1757 |
oop field = Reflection::new_field(&fd, CHECK_NULL); |
1 | 1758 |
result->obj_at_put(out_idx, field); |
1759 |
++out_idx; |
|
1760 |
} |
|
1761 |
} |
|
1762 |
assert(out_idx == num_fields, "just checking"); |
|
1763 |
return (jobjectArray) JNIHandles::make_local(env, result()); |
|
1764 |
} |
|
1765 |
JVM_END |
|
1766 |
||
20059
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1767 |
static bool select_method(methodHandle method, bool want_constructor) { |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1768 |
if (want_constructor) { |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1769 |
return (method->is_initializer() && !method->is_static()); |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1770 |
} else { |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1771 |
return (!method->is_initializer() && !method->is_overpass()); |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1772 |
} |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1773 |
} |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1774 |
|
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1775 |
static jobjectArray get_class_declared_methods_helper( |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1776 |
JNIEnv *env, |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1777 |
jclass ofClass, jboolean publicOnly, |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1778 |
bool want_constructor, |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1779 |
Klass* klass, TRAPS) { |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1780 |
|
1 | 1781 |
JvmtiVMObjectAllocEventCollector oam; |
1782 |
||
1783 |
// Exclude primitive types and array types |
|
1784 |
if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) |
|
14488 | 1785 |
|| java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->oop_is_array()) { |
1 | 1786 |
// Return empty array |
20059
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1787 |
oop res = oopFactory::new_objArray(klass, 0, CHECK_NULL); |
1 | 1788 |
return (jobjectArray) JNIHandles::make_local(env, res); |
1789 |
} |
|
1790 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1791 |
instanceKlassHandle k(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))); |
1 | 1792 |
|
1793 |
// Ensure class is linked |
|
1794 |
k->link_class(CHECK_NULL); |
|
1795 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1796 |
Array<Method*>* methods = k->methods(); |
1 | 1797 |
int methods_length = methods->length(); |
20059
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1798 |
|
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1799 |
// Save original method_idnum in case of redefinition, which can change |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1800 |
// the idnum of obsolete methods. The new method will have the same idnum |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1801 |
// but if we refresh the methods array, the counts will be wrong. |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1802 |
ResourceMark rm(THREAD); |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1803 |
GrowableArray<int>* idnums = new GrowableArray<int>(methods_length); |
1 | 1804 |
int num_methods = 0; |
1805 |
||
20059
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1806 |
for (int i = 0; i < methods_length; i++) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1807 |
methodHandle method(THREAD, methods->at(i)); |
20059
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1808 |
if (select_method(method, want_constructor)) { |
1 | 1809 |
if (!publicOnly || method->is_public()) { |
20059
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1810 |
idnums->push(method->method_idnum()); |
1 | 1811 |
++num_methods; |
1812 |
} |
|
1813 |
} |
|
1814 |
} |
|
1815 |
||
1816 |
// Allocate result |
|
20059
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1817 |
objArrayOop r = oopFactory::new_objArray(klass, num_methods, CHECK_NULL); |
1 | 1818 |
objArrayHandle result (THREAD, r); |
1819 |
||
20059
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1820 |
// Now just put the methods that we selected above, but go by their idnum |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1821 |
// in case of redefinition. The methods can be redefined at any safepoint, |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1822 |
// so above when allocating the oop array and below when creating reflect |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1823 |
// objects. |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1824 |
for (int i = 0; i < num_methods; i++) { |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1825 |
methodHandle method(THREAD, k->method_with_idnum(idnums->at(i))); |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1826 |
if (method.is_null()) { |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1827 |
// Method may have been deleted and seems this API can handle null |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1828 |
// Otherwise should probably put a method that throws NSME |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1829 |
result->obj_at_put(i, NULL); |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1830 |
} else { |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1831 |
oop m; |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1832 |
if (want_constructor) { |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1833 |
m = Reflection::new_constructor(method, CHECK_NULL); |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1834 |
} else { |
24456
8c7933fa5a1f
8025580: Temporary flags: UseNewReflection and ReflectionWrapResolutionErrors
coleenp
parents:
24429
diff
changeset
|
1835 |
m = Reflection::new_method(method, false, CHECK_NULL); |
1 | 1836 |
} |
20059
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1837 |
result->obj_at_put(i, m); |
1 | 1838 |
} |
1839 |
} |
|
20059
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1840 |
|
1 | 1841 |
return (jobjectArray) JNIHandles::make_local(env, result()); |
1842 |
} |
|
20059
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1843 |
|
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1844 |
JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly)) |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1845 |
{ |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1846 |
JVMWrapper("JVM_GetClassDeclaredMethods"); |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1847 |
return get_class_declared_methods_helper(env, ofClass, publicOnly, |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1848 |
/*want_constructor*/ false, |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1849 |
SystemDictionary::reflect_Method_klass(), THREAD); |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1850 |
} |
1 | 1851 |
JVM_END |
1852 |
||
1853 |
JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly)) |
|
1854 |
{ |
|
1855 |
JVMWrapper("JVM_GetClassDeclaredConstructors"); |
|
20059
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1856 |
return get_class_declared_methods_helper(env, ofClass, publicOnly, |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1857 |
/*want_constructor*/ true, |
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
18690
diff
changeset
|
1858 |
SystemDictionary::reflect_Constructor_klass(), THREAD); |
1 | 1859 |
} |
1860 |
JVM_END |
|
1861 |
||
1862 |
JVM_ENTRY(jint, JVM_GetClassAccessFlags(JNIEnv *env, jclass cls)) |
|
1863 |
{ |
|
1864 |
JVMWrapper("JVM_GetClassAccessFlags"); |
|
1865 |
if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) { |
|
1866 |
// Primitive type |
|
1867 |
return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC; |
|
1868 |
} |
|
1869 |
||
14488 | 1870 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
1 | 1871 |
return k->access_flags().as_int() & JVM_ACC_WRITTEN_FLAGS; |
1872 |
} |
|
1873 |
JVM_END |
|
1874 |
||
1875 |
||
1876 |
// Constant pool access ////////////////////////////////////////////////////////// |
|
1877 |
||
1878 |
JVM_ENTRY(jobject, JVM_GetClassConstantPool(JNIEnv *env, jclass cls)) |
|
1879 |
{ |
|
1880 |
JVMWrapper("JVM_GetClassConstantPool"); |
|
1881 |
JvmtiVMObjectAllocEventCollector oam; |
|
1882 |
||
1883 |
// Return null for primitives and arrays |
|
1884 |
if (!java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1885 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
14488 | 1886 |
if (k->oop_is_instance()) { |
1 | 1887 |
instanceKlassHandle k_h(THREAD, k); |
1888 |
Handle jcp = sun_reflect_ConstantPool::create(CHECK_NULL); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1889 |
sun_reflect_ConstantPool::set_cp(jcp(), k_h->constants()); |
1 | 1890 |
return JNIHandles::make_local(jcp()); |
1891 |
} |
|
1892 |
} |
|
1893 |
return NULL; |
|
1894 |
} |
|
1895 |
JVM_END |
|
1896 |
||
1897 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1898 |
JVM_ENTRY(jint, JVM_ConstantPoolGetSize(JNIEnv *env, jobject obj, jobject unused)) |
1 | 1899 |
{ |
1900 |
JVMWrapper("JVM_ConstantPoolGetSize"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1901 |
constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); |
1 | 1902 |
return cp->length(); |
1903 |
} |
|
1904 |
JVM_END |
|
1905 |
||
1906 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1907 |
JVM_ENTRY(jclass, JVM_ConstantPoolGetClassAt(JNIEnv *env, jobject obj, jobject unused, jint index)) |
1 | 1908 |
{ |
1909 |
JVMWrapper("JVM_ConstantPoolGetClassAt"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1910 |
constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); |
1 | 1911 |
bounds_check(cp, index, CHECK_NULL); |
1912 |
constantTag tag = cp->tag_at(index); |
|
1913 |
if (!tag.is_klass() && !tag.is_unresolved_klass()) { |
|
1914 |
THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); |
|
1915 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1916 |
Klass* k = cp->klass_at(index, CHECK_NULL); |
8725
8c1e3dd5fe1b
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
8106
diff
changeset
|
1917 |
return (jclass) JNIHandles::make_local(k->java_mirror()); |
1 | 1918 |
} |
1919 |
JVM_END |
|
1920 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1921 |
JVM_ENTRY(jclass, JVM_ConstantPoolGetClassAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index)) |
1 | 1922 |
{ |
1923 |
JVMWrapper("JVM_ConstantPoolGetClassAtIfLoaded"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1924 |
constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); |
1 | 1925 |
bounds_check(cp, index, CHECK_NULL); |
1926 |
constantTag tag = cp->tag_at(index); |
|
1927 |
if (!tag.is_klass() && !tag.is_unresolved_klass()) { |
|
1928 |
THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); |
|
1929 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1930 |
Klass* k = ConstantPool::klass_at_if_loaded(cp, index); |
1 | 1931 |
if (k == NULL) return NULL; |
8725
8c1e3dd5fe1b
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
8106
diff
changeset
|
1932 |
return (jclass) JNIHandles::make_local(k->java_mirror()); |
1 | 1933 |
} |
1934 |
JVM_END |
|
1935 |
||
1936 |
static jobject get_method_at_helper(constantPoolHandle cp, jint index, bool force_resolution, TRAPS) { |
|
1937 |
constantTag tag = cp->tag_at(index); |
|
1938 |
if (!tag.is_method() && !tag.is_interface_method()) { |
|
1939 |
THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); |
|
1940 |
} |
|
1941 |
int klass_ref = cp->uncached_klass_ref_index_at(index); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1942 |
Klass* k_o; |
1 | 1943 |
if (force_resolution) { |
1944 |
k_o = cp->klass_at(klass_ref, CHECK_NULL); |
|
1945 |
} else { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1946 |
k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref); |
1 | 1947 |
if (k_o == NULL) return NULL; |
1948 |
} |
|
1949 |
instanceKlassHandle k(THREAD, k_o); |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
1950 |
Symbol* name = cp->uncached_name_ref_at(index); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
1951 |
Symbol* sig = cp->uncached_signature_ref_at(index); |
1 | 1952 |
methodHandle m (THREAD, k->find_method(name, sig)); |
1953 |
if (m.is_null()) { |
|
1954 |
THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "Unable to look up method in target class"); |
|
1955 |
} |
|
1956 |
oop method; |
|
1957 |
if (!m->is_initializer() || m->is_static()) { |
|
24456
8c7933fa5a1f
8025580: Temporary flags: UseNewReflection and ReflectionWrapResolutionErrors
coleenp
parents:
24429
diff
changeset
|
1958 |
method = Reflection::new_method(m, true, CHECK_NULL); |
1 | 1959 |
} else { |
1960 |
method = Reflection::new_constructor(m, CHECK_NULL); |
|
1961 |
} |
|
1962 |
return JNIHandles::make_local(method); |
|
1963 |
} |
|
1964 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1965 |
JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject obj, jobject unused, jint index)) |
1 | 1966 |
{ |
1967 |
JVMWrapper("JVM_ConstantPoolGetMethodAt"); |
|
1968 |
JvmtiVMObjectAllocEventCollector oam; |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1969 |
constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); |
1 | 1970 |
bounds_check(cp, index, CHECK_NULL); |
1971 |
jobject res = get_method_at_helper(cp, index, true, CHECK_NULL); |
|
1972 |
return res; |
|
1973 |
} |
|
1974 |
JVM_END |
|
1975 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1976 |
JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index)) |
1 | 1977 |
{ |
1978 |
JVMWrapper("JVM_ConstantPoolGetMethodAtIfLoaded"); |
|
1979 |
JvmtiVMObjectAllocEventCollector oam; |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1980 |
constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); |
1 | 1981 |
bounds_check(cp, index, CHECK_NULL); |
1982 |
jobject res = get_method_at_helper(cp, index, false, CHECK_NULL); |
|
1983 |
return res; |
|
1984 |
} |
|
1985 |
JVM_END |
|
1986 |
||
1987 |
static jobject get_field_at_helper(constantPoolHandle cp, jint index, bool force_resolution, TRAPS) { |
|
1988 |
constantTag tag = cp->tag_at(index); |
|
1989 |
if (!tag.is_field()) { |
|
1990 |
THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); |
|
1991 |
} |
|
1992 |
int klass_ref = cp->uncached_klass_ref_index_at(index); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1993 |
Klass* k_o; |
1 | 1994 |
if (force_resolution) { |
1995 |
k_o = cp->klass_at(klass_ref, CHECK_NULL); |
|
1996 |
} else { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1997 |
k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref); |
1 | 1998 |
if (k_o == NULL) return NULL; |
1999 |
} |
|
2000 |
instanceKlassHandle k(THREAD, k_o); |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
2001 |
Symbol* name = cp->uncached_name_ref_at(index); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
2002 |
Symbol* sig = cp->uncached_signature_ref_at(index); |
1 | 2003 |
fieldDescriptor fd; |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2004 |
Klass* target_klass = k->find_field(name, sig, &fd); |
1 | 2005 |
if (target_klass == NULL) { |
2006 |
THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "Unable to look up field in target class"); |
|
2007 |
} |
|
24456
8c7933fa5a1f
8025580: Temporary flags: UseNewReflection and ReflectionWrapResolutionErrors
coleenp
parents:
24429
diff
changeset
|
2008 |
oop field = Reflection::new_field(&fd, CHECK_NULL); |
1 | 2009 |
return JNIHandles::make_local(field); |
2010 |
} |
|
2011 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2012 |
JVM_ENTRY(jobject, JVM_ConstantPoolGetFieldAt(JNIEnv *env, jobject obj, jobject unusedl, jint index)) |
1 | 2013 |
{ |
2014 |
JVMWrapper("JVM_ConstantPoolGetFieldAt"); |
|
2015 |
JvmtiVMObjectAllocEventCollector oam; |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2016 |
constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); |
1 | 2017 |
bounds_check(cp, index, CHECK_NULL); |
2018 |
jobject res = get_field_at_helper(cp, index, true, CHECK_NULL); |
|
2019 |
return res; |
|
2020 |
} |
|
2021 |
JVM_END |
|
2022 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2023 |
JVM_ENTRY(jobject, JVM_ConstantPoolGetFieldAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index)) |
1 | 2024 |
{ |
2025 |
JVMWrapper("JVM_ConstantPoolGetFieldAtIfLoaded"); |
|
2026 |
JvmtiVMObjectAllocEventCollector oam; |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2027 |
constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); |
1 | 2028 |
bounds_check(cp, index, CHECK_NULL); |
2029 |
jobject res = get_field_at_helper(cp, index, false, CHECK_NULL); |
|
2030 |
return res; |
|
2031 |
} |
|
2032 |
JVM_END |
|
2033 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2034 |
JVM_ENTRY(jobjectArray, JVM_ConstantPoolGetMemberRefInfoAt(JNIEnv *env, jobject obj, jobject unused, jint index)) |
1 | 2035 |
{ |
2036 |
JVMWrapper("JVM_ConstantPoolGetMemberRefInfoAt"); |
|
2037 |
JvmtiVMObjectAllocEventCollector oam; |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2038 |
constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); |
1 | 2039 |
bounds_check(cp, index, CHECK_NULL); |
2040 |
constantTag tag = cp->tag_at(index); |
|
2041 |
if (!tag.is_field_or_method()) { |
|
2042 |
THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); |
|
2043 |
} |
|
2044 |
int klass_ref = cp->uncached_klass_ref_index_at(index); |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
2045 |
Symbol* klass_name = cp->klass_name_at(klass_ref); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
2046 |
Symbol* member_name = cp->uncached_name_ref_at(index); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
2047 |
Symbol* member_sig = cp->uncached_signature_ref_at(index); |
4571 | 2048 |
objArrayOop dest_o = oopFactory::new_objArray(SystemDictionary::String_klass(), 3, CHECK_NULL); |
1 | 2049 |
objArrayHandle dest(THREAD, dest_o); |
2050 |
Handle str = java_lang_String::create_from_symbol(klass_name, CHECK_NULL); |
|
2051 |
dest->obj_at_put(0, str()); |
|
2052 |
str = java_lang_String::create_from_symbol(member_name, CHECK_NULL); |
|
2053 |
dest->obj_at_put(1, str()); |
|
2054 |
str = java_lang_String::create_from_symbol(member_sig, CHECK_NULL); |
|
2055 |
dest->obj_at_put(2, str()); |
|
2056 |
return (jobjectArray) JNIHandles::make_local(dest()); |
|
2057 |
} |
|
2058 |
JVM_END |
|
2059 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2060 |
JVM_ENTRY(jint, JVM_ConstantPoolGetIntAt(JNIEnv *env, jobject obj, jobject unused, jint index)) |
1 | 2061 |
{ |
2062 |
JVMWrapper("JVM_ConstantPoolGetIntAt"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2063 |
constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); |
1 | 2064 |
bounds_check(cp, index, CHECK_0); |
2065 |
constantTag tag = cp->tag_at(index); |
|
2066 |
if (!tag.is_int()) { |
|
2067 |
THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); |
|
2068 |
} |
|
2069 |
return cp->int_at(index); |
|
2070 |
} |
|
2071 |
JVM_END |
|
2072 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2073 |
JVM_ENTRY(jlong, JVM_ConstantPoolGetLongAt(JNIEnv *env, jobject obj, jobject unused, jint index)) |
1 | 2074 |
{ |
2075 |
JVMWrapper("JVM_ConstantPoolGetLongAt"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2076 |
constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); |
1 | 2077 |
bounds_check(cp, index, CHECK_(0L)); |
2078 |
constantTag tag = cp->tag_at(index); |
|
2079 |
if (!tag.is_long()) { |
|
2080 |
THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); |
|
2081 |
} |
|
2082 |
return cp->long_at(index); |
|
2083 |
} |
|
2084 |
JVM_END |
|
2085 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2086 |
JVM_ENTRY(jfloat, JVM_ConstantPoolGetFloatAt(JNIEnv *env, jobject obj, jobject unused, jint index)) |
1 | 2087 |
{ |
2088 |
JVMWrapper("JVM_ConstantPoolGetFloatAt"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2089 |
constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); |
1 | 2090 |
bounds_check(cp, index, CHECK_(0.0f)); |
2091 |
constantTag tag = cp->tag_at(index); |
|
2092 |
if (!tag.is_float()) { |
|
2093 |
THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); |
|
2094 |
} |
|
2095 |
return cp->float_at(index); |
|
2096 |
} |
|
2097 |
JVM_END |
|
2098 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2099 |
JVM_ENTRY(jdouble, JVM_ConstantPoolGetDoubleAt(JNIEnv *env, jobject obj, jobject unused, jint index)) |
1 | 2100 |
{ |
2101 |
JVMWrapper("JVM_ConstantPoolGetDoubleAt"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2102 |
constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); |
1 | 2103 |
bounds_check(cp, index, CHECK_(0.0)); |
2104 |
constantTag tag = cp->tag_at(index); |
|
2105 |
if (!tag.is_double()) { |
|
2106 |
THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); |
|
2107 |
} |
|
2108 |
return cp->double_at(index); |
|
2109 |
} |
|
2110 |
JVM_END |
|
2111 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2112 |
JVM_ENTRY(jstring, JVM_ConstantPoolGetStringAt(JNIEnv *env, jobject obj, jobject unused, jint index)) |
1 | 2113 |
{ |
2114 |
JVMWrapper("JVM_ConstantPoolGetStringAt"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2115 |
constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); |
1 | 2116 |
bounds_check(cp, index, CHECK_NULL); |
2117 |
constantTag tag = cp->tag_at(index); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2118 |
if (!tag.is_string()) { |
1 | 2119 |
THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); |
2120 |
} |
|
2121 |
oop str = cp->string_at(index, CHECK_NULL); |
|
2122 |
return (jstring) JNIHandles::make_local(str); |
|
2123 |
} |
|
2124 |
JVM_END |
|
2125 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2126 |
JVM_ENTRY(jstring, JVM_ConstantPoolGetUTF8At(JNIEnv *env, jobject obj, jobject unused, jint index)) |
1 | 2127 |
{ |
2128 |
JVMWrapper("JVM_ConstantPoolGetUTF8At"); |
|
2129 |
JvmtiVMObjectAllocEventCollector oam; |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2130 |
constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); |
1 | 2131 |
bounds_check(cp, index, CHECK_NULL); |
2132 |
constantTag tag = cp->tag_at(index); |
|
2133 |
if (!tag.is_symbol()) { |
|
2134 |
THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); |
|
2135 |
} |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
2136 |
Symbol* sym = cp->symbol_at(index); |
1 | 2137 |
Handle str = java_lang_String::create_from_symbol(sym, CHECK_NULL); |
2138 |
return (jstring) JNIHandles::make_local(str()); |
|
2139 |
} |
|
2140 |
JVM_END |
|
2141 |
||
2142 |
||
2143 |
// Assertion support. ////////////////////////////////////////////////////////// |
|
2144 |
||
2145 |
JVM_ENTRY(jboolean, JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls)) |
|
2146 |
JVMWrapper("JVM_DesiredAssertionStatus"); |
|
2147 |
assert(cls != NULL, "bad class"); |
|
2148 |
||
2149 |
oop r = JNIHandles::resolve(cls); |
|
2150 |
assert(! java_lang_Class::is_primitive(r), "primitive classes not allowed"); |
|
2151 |
if (java_lang_Class::is_primitive(r)) return false; |
|
2152 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2153 |
Klass* k = java_lang_Class::as_Klass(r); |
14488 | 2154 |
assert(k->oop_is_instance(), "must be an instance klass"); |
2155 |
if (! k->oop_is_instance()) return false; |
|
1 | 2156 |
|
2157 |
ResourceMark rm(THREAD); |
|
14488 | 2158 |
const char* name = k->name()->as_C_string(); |
2159 |
bool system_class = k->class_loader() == NULL; |
|
1 | 2160 |
return JavaAssertions::enabled(name, system_class); |
2161 |
||
2162 |
JVM_END |
|
2163 |
||
2164 |
||
2165 |
// Return a new AssertionStatusDirectives object with the fields filled in with |
|
2166 |
// command-line assertion arguments (i.e., -ea, -da). |
|
2167 |
JVM_ENTRY(jobject, JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused)) |
|
2168 |
JVMWrapper("JVM_AssertionStatusDirectives"); |
|
2169 |
JvmtiVMObjectAllocEventCollector oam; |
|
2170 |
oop asd = JavaAssertions::createAssertionStatusDirectives(CHECK_NULL); |
|
2171 |
return JNIHandles::make_local(env, asd); |
|
2172 |
JVM_END |
|
2173 |
||
2174 |
// Verification //////////////////////////////////////////////////////////////////////////////// |
|
2175 |
||
2176 |
// Reflection for the verifier ///////////////////////////////////////////////////////////////// |
|
2177 |
||
2178 |
// RedefineClasses support: bug 6214132 caused verification to fail. |
|
2179 |
// All functions from this section should call the jvmtiThreadSate function: |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2180 |
// Klass* class_to_verify_considering_redefinition(Klass* klass). |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2181 |
// The function returns a Klass* of the _scratch_class if the verifier |
1 | 2182 |
// was invoked in the middle of the class redefinition. |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2183 |
// Otherwise it returns its argument value which is the _the_class Klass*. |
1 | 2184 |
// Please, refer to the description in the jvmtiThreadSate.hpp. |
2185 |
||
2186 |
JVM_ENTRY(const char*, JVM_GetClassNameUTF(JNIEnv *env, jclass cls)) |
|
2187 |
JVMWrapper("JVM_GetClassNameUTF"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2188 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
1 | 2189 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
14488 | 2190 |
return k->name()->as_utf8(); |
1 | 2191 |
JVM_END |
2192 |
||
2193 |
||
2194 |
JVM_QUICK_ENTRY(void, JVM_GetClassCPTypes(JNIEnv *env, jclass cls, unsigned char *types)) |
|
2195 |
JVMWrapper("JVM_GetClassCPTypes"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2196 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
1 | 2197 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2198 |
// types will have length zero if this is not an InstanceKlass |
1 | 2199 |
// (length is determined by call to JVM_GetClassCPEntriesCount) |
14488 | 2200 |
if (k->oop_is_instance()) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2201 |
ConstantPool* cp = InstanceKlass::cast(k)->constants(); |
1 | 2202 |
for (int index = cp->length() - 1; index >= 0; index--) { |
2203 |
constantTag tag = cp->tag_at(index); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2204 |
types[index] = (tag.is_unresolved_klass()) ? JVM_CONSTANT_Class : tag.value(); |
1 | 2205 |
} |
2206 |
} |
|
2207 |
JVM_END |
|
2208 |
||
2209 |
||
2210 |
JVM_QUICK_ENTRY(jint, JVM_GetClassCPEntriesCount(JNIEnv *env, jclass cls)) |
|
2211 |
JVMWrapper("JVM_GetClassCPEntriesCount"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2212 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
1 | 2213 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
14488 | 2214 |
if (!k->oop_is_instance()) |
1 | 2215 |
return 0; |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2216 |
return InstanceKlass::cast(k)->constants()->length(); |
1 | 2217 |
JVM_END |
2218 |
||
2219 |
||
2220 |
JVM_QUICK_ENTRY(jint, JVM_GetClassFieldsCount(JNIEnv *env, jclass cls)) |
|
2221 |
JVMWrapper("JVM_GetClassFieldsCount"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2222 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
1 | 2223 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
14488 | 2224 |
if (!k->oop_is_instance()) |
1 | 2225 |
return 0; |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2226 |
return InstanceKlass::cast(k)->java_fields_count(); |
1 | 2227 |
JVM_END |
2228 |
||
2229 |
||
2230 |
JVM_QUICK_ENTRY(jint, JVM_GetClassMethodsCount(JNIEnv *env, jclass cls)) |
|
2231 |
JVMWrapper("JVM_GetClassMethodsCount"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2232 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
1 | 2233 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
14488 | 2234 |
if (!k->oop_is_instance()) |
1 | 2235 |
return 0; |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2236 |
return InstanceKlass::cast(k)->methods()->length(); |
1 | 2237 |
JVM_END |
2238 |
||
2239 |
||
2240 |
// The following methods, used for the verifier, are never called with |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2241 |
// array klasses, so a direct cast to InstanceKlass is safe. |
1 | 2242 |
// Typically, these methods are called in a loop with bounds determined |
2243 |
// by the results of JVM_GetClass{Fields,Methods}Count, which return |
|
2244 |
// zero for arrays. |
|
2245 |
JVM_QUICK_ENTRY(void, JVM_GetMethodIxExceptionIndexes(JNIEnv *env, jclass cls, jint method_index, unsigned short *exceptions)) |
|
2246 |
JVMWrapper("JVM_GetMethodIxExceptionIndexes"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2247 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
1 | 2248 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2249 |
Method* method = InstanceKlass::cast(k)->methods()->at(method_index); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2250 |
int length = method->checked_exceptions_length(); |
1 | 2251 |
if (length > 0) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2252 |
CheckedExceptionElement* table= method->checked_exceptions_start(); |
1 | 2253 |
for (int i = 0; i < length; i++) { |
2254 |
exceptions[i] = table[i].class_cp_index; |
|
2255 |
} |
|
2256 |
} |
|
2257 |
JVM_END |
|
2258 |
||
2259 |
||
2260 |
JVM_QUICK_ENTRY(jint, JVM_GetMethodIxExceptionsCount(JNIEnv *env, jclass cls, jint method_index)) |
|
2261 |
JVMWrapper("JVM_GetMethodIxExceptionsCount"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2262 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
1 | 2263 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2264 |
Method* method = InstanceKlass::cast(k)->methods()->at(method_index); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2265 |
return method->checked_exceptions_length(); |
1 | 2266 |
JVM_END |
2267 |
||
2268 |
||
2269 |
JVM_QUICK_ENTRY(void, JVM_GetMethodIxByteCode(JNIEnv *env, jclass cls, jint method_index, unsigned char *code)) |
|
2270 |
JVMWrapper("JVM_GetMethodIxByteCode"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2271 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
1 | 2272 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2273 |
Method* method = InstanceKlass::cast(k)->methods()->at(method_index); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2274 |
memcpy(code, method->code_base(), method->code_size()); |
1 | 2275 |
JVM_END |
2276 |
||
2277 |
||
2278 |
JVM_QUICK_ENTRY(jint, JVM_GetMethodIxByteCodeLength(JNIEnv *env, jclass cls, jint method_index)) |
|
2279 |
JVMWrapper("JVM_GetMethodIxByteCodeLength"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2280 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
1 | 2281 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2282 |
Method* method = InstanceKlass::cast(k)->methods()->at(method_index); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2283 |
return method->code_size(); |
1 | 2284 |
JVM_END |
2285 |
||
2286 |
||
2287 |
JVM_QUICK_ENTRY(void, JVM_GetMethodIxExceptionTableEntry(JNIEnv *env, jclass cls, jint method_index, jint entry_index, JVM_ExceptionTableEntryType *entry)) |
|
2288 |
JVMWrapper("JVM_GetMethodIxExceptionTableEntry"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2289 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
1 | 2290 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2291 |
Method* method = InstanceKlass::cast(k)->methods()->at(method_index); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2292 |
ExceptionTable extable(method); |
13282
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12231
diff
changeset
|
2293 |
entry->start_pc = extable.start_pc(entry_index); |
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12231
diff
changeset
|
2294 |
entry->end_pc = extable.end_pc(entry_index); |
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12231
diff
changeset
|
2295 |
entry->handler_pc = extable.handler_pc(entry_index); |
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12231
diff
changeset
|
2296 |
entry->catchType = extable.catch_type_index(entry_index); |
1 | 2297 |
JVM_END |
2298 |
||
2299 |
||
2300 |
JVM_QUICK_ENTRY(jint, JVM_GetMethodIxExceptionTableLength(JNIEnv *env, jclass cls, int method_index)) |
|
2301 |
JVMWrapper("JVM_GetMethodIxExceptionTableLength"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2302 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
1 | 2303 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2304 |
Method* method = InstanceKlass::cast(k)->methods()->at(method_index); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2305 |
return method->exception_table_length(); |
1 | 2306 |
JVM_END |
2307 |
||
2308 |
||
2309 |
JVM_QUICK_ENTRY(jint, JVM_GetMethodIxModifiers(JNIEnv *env, jclass cls, int method_index)) |
|
2310 |
JVMWrapper("JVM_GetMethodIxModifiers"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2311 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
1 | 2312 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2313 |
Method* method = InstanceKlass::cast(k)->methods()->at(method_index); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2314 |
return method->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS; |
1 | 2315 |
JVM_END |
2316 |
||
2317 |
||
2318 |
JVM_QUICK_ENTRY(jint, JVM_GetFieldIxModifiers(JNIEnv *env, jclass cls, int field_index)) |
|
2319 |
JVMWrapper("JVM_GetFieldIxModifiers"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2320 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
1 | 2321 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2322 |
return InstanceKlass::cast(k)->field_access_flags(field_index) & JVM_RECOGNIZED_FIELD_MODIFIERS; |
1 | 2323 |
JVM_END |
2324 |
||
2325 |
||
2326 |
JVM_QUICK_ENTRY(jint, JVM_GetMethodIxLocalsCount(JNIEnv *env, jclass cls, int method_index)) |
|
2327 |
JVMWrapper("JVM_GetMethodIxLocalsCount"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2328 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
1 | 2329 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2330 |
Method* method = InstanceKlass::cast(k)->methods()->at(method_index); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2331 |
return method->max_locals(); |
1 | 2332 |
JVM_END |
2333 |
||
2334 |
||
2335 |
JVM_QUICK_ENTRY(jint, JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cls, int method_index)) |
|
2336 |
JVMWrapper("JVM_GetMethodIxArgsSize"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2337 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
1 | 2338 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2339 |
Method* method = InstanceKlass::cast(k)->methods()->at(method_index); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2340 |
return method->size_of_parameters(); |
1 | 2341 |
JVM_END |
2342 |
||
2343 |
||
2344 |
JVM_QUICK_ENTRY(jint, JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index)) |
|
2345 |
JVMWrapper("JVM_GetMethodIxMaxStack"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2346 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
1 | 2347 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2348 |
Method* method = InstanceKlass::cast(k)->methods()->at(method_index); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2349 |
return method->verifier_max_stack(); |
1 | 2350 |
JVM_END |
2351 |
||
2352 |
||
2353 |
JVM_QUICK_ENTRY(jboolean, JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index)) |
|
2354 |
JVMWrapper("JVM_IsConstructorIx"); |
|
2355 |
ResourceMark rm(THREAD); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2356 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
1 | 2357 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2358 |
Method* method = InstanceKlass::cast(k)->methods()->at(method_index); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2359 |
return method->name() == vmSymbols::object_initializer_name(); |
1 | 2360 |
JVM_END |
2361 |
||
2362 |
||
15439
a72c53517fe7
8004967: Default method cause VerifyError: Illegal use of nonvirtual
acorn
parents:
15432
diff
changeset
|
2363 |
JVM_QUICK_ENTRY(jboolean, JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cls, int method_index)) |
a72c53517fe7
8004967: Default method cause VerifyError: Illegal use of nonvirtual
acorn
parents:
15432
diff
changeset
|
2364 |
JVMWrapper("JVM_IsVMGeneratedMethodIx"); |
a72c53517fe7
8004967: Default method cause VerifyError: Illegal use of nonvirtual
acorn
parents:
15432
diff
changeset
|
2365 |
ResourceMark rm(THREAD); |
a72c53517fe7
8004967: Default method cause VerifyError: Illegal use of nonvirtual
acorn
parents:
15432
diff
changeset
|
2366 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
a72c53517fe7
8004967: Default method cause VerifyError: Illegal use of nonvirtual
acorn
parents:
15432
diff
changeset
|
2367 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
a72c53517fe7
8004967: Default method cause VerifyError: Illegal use of nonvirtual
acorn
parents:
15432
diff
changeset
|
2368 |
Method* method = InstanceKlass::cast(k)->methods()->at(method_index); |
a72c53517fe7
8004967: Default method cause VerifyError: Illegal use of nonvirtual
acorn
parents:
15432
diff
changeset
|
2369 |
return method->is_overpass(); |
a72c53517fe7
8004967: Default method cause VerifyError: Illegal use of nonvirtual
acorn
parents:
15432
diff
changeset
|
2370 |
JVM_END |
a72c53517fe7
8004967: Default method cause VerifyError: Illegal use of nonvirtual
acorn
parents:
15432
diff
changeset
|
2371 |
|
1 | 2372 |
JVM_ENTRY(const char*, JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index)) |
2373 |
JVMWrapper("JVM_GetMethodIxIxUTF"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2374 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
1 | 2375 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2376 |
Method* method = InstanceKlass::cast(k)->methods()->at(method_index); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2377 |
return method->name()->as_utf8(); |
1 | 2378 |
JVM_END |
2379 |
||
2380 |
||
2381 |
JVM_ENTRY(const char*, JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index)) |
|
2382 |
JVMWrapper("JVM_GetMethodIxSignatureUTF"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2383 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
1 | 2384 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2385 |
Method* method = InstanceKlass::cast(k)->methods()->at(method_index); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2386 |
return method->signature()->as_utf8(); |
1 | 2387 |
JVM_END |
2388 |
||
2389 |
/** |
|
2390 |
* All of these JVM_GetCP-xxx methods are used by the old verifier to |
|
2391 |
* read entries in the constant pool. Since the old verifier always |
|
2392 |
* works on a copy of the code, it will not see any rewriting that |
|
2393 |
* may possibly occur in the middle of verification. So it is important |
|
2394 |
* that nothing it calls tries to use the cpCache instead of the raw |
|
2395 |
* constant pool, so we must use cp->uncached_x methods when appropriate. |
|
2396 |
*/ |
|
2397 |
JVM_ENTRY(const char*, JVM_GetCPFieldNameUTF(JNIEnv *env, jclass cls, jint cp_index)) |
|
2398 |
JVMWrapper("JVM_GetCPFieldNameUTF"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2399 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
1 | 2400 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2401 |
ConstantPool* cp = InstanceKlass::cast(k)->constants(); |
1 | 2402 |
switch (cp->tag_at(cp_index).value()) { |
2403 |
case JVM_CONSTANT_Fieldref: |
|
2404 |
return cp->uncached_name_ref_at(cp_index)->as_utf8(); |
|
2405 |
default: |
|
2406 |
fatal("JVM_GetCPFieldNameUTF: illegal constant"); |
|
2407 |
} |
|
2408 |
ShouldNotReachHere(); |
|
2409 |
return NULL; |
|
2410 |
JVM_END |
|
2411 |
||
2412 |
||
2413 |
JVM_ENTRY(const char*, JVM_GetCPMethodNameUTF(JNIEnv *env, jclass cls, jint cp_index)) |
|
2414 |
JVMWrapper("JVM_GetCPMethodNameUTF"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2415 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
1 | 2416 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2417 |
ConstantPool* cp = InstanceKlass::cast(k)->constants(); |
1 | 2418 |
switch (cp->tag_at(cp_index).value()) { |
2419 |
case JVM_CONSTANT_InterfaceMethodref: |
|
2420 |
case JVM_CONSTANT_Methodref: |
|
4429
d7eb4e2099aa
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
3820
diff
changeset
|
2421 |
case JVM_CONSTANT_NameAndType: // for invokedynamic |
1 | 2422 |
return cp->uncached_name_ref_at(cp_index)->as_utf8(); |
2423 |
default: |
|
2424 |
fatal("JVM_GetCPMethodNameUTF: illegal constant"); |
|
2425 |
} |
|
2426 |
ShouldNotReachHere(); |
|
2427 |
return NULL; |
|
2428 |
JVM_END |
|
2429 |
||
2430 |
||
2431 |
JVM_ENTRY(const char*, JVM_GetCPMethodSignatureUTF(JNIEnv *env, jclass cls, jint cp_index)) |
|
2432 |
JVMWrapper("JVM_GetCPMethodSignatureUTF"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2433 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
1 | 2434 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2435 |
ConstantPool* cp = InstanceKlass::cast(k)->constants(); |
1 | 2436 |
switch (cp->tag_at(cp_index).value()) { |
2437 |
case JVM_CONSTANT_InterfaceMethodref: |
|
2438 |
case JVM_CONSTANT_Methodref: |
|
4429
d7eb4e2099aa
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
3820
diff
changeset
|
2439 |
case JVM_CONSTANT_NameAndType: // for invokedynamic |
1 | 2440 |
return cp->uncached_signature_ref_at(cp_index)->as_utf8(); |
2441 |
default: |
|
2442 |
fatal("JVM_GetCPMethodSignatureUTF: illegal constant"); |
|
2443 |
} |
|
2444 |
ShouldNotReachHere(); |
|
2445 |
return NULL; |
|
2446 |
JVM_END |
|
2447 |
||
2448 |
||
2449 |
JVM_ENTRY(const char*, JVM_GetCPFieldSignatureUTF(JNIEnv *env, jclass cls, jint cp_index)) |
|
2450 |
JVMWrapper("JVM_GetCPFieldSignatureUTF"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2451 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
1 | 2452 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2453 |
ConstantPool* cp = InstanceKlass::cast(k)->constants(); |
1 | 2454 |
switch (cp->tag_at(cp_index).value()) { |
2455 |
case JVM_CONSTANT_Fieldref: |
|
2456 |
return cp->uncached_signature_ref_at(cp_index)->as_utf8(); |
|
2457 |
default: |
|
2458 |
fatal("JVM_GetCPFieldSignatureUTF: illegal constant"); |
|
2459 |
} |
|
2460 |
ShouldNotReachHere(); |
|
2461 |
return NULL; |
|
2462 |
JVM_END |
|
2463 |
||
2464 |
||
2465 |
JVM_ENTRY(const char*, JVM_GetCPClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)) |
|
2466 |
JVMWrapper("JVM_GetCPClassNameUTF"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2467 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
1 | 2468 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2469 |
ConstantPool* cp = InstanceKlass::cast(k)->constants(); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
2470 |
Symbol* classname = cp->klass_name_at(cp_index); |
1 | 2471 |
return classname->as_utf8(); |
2472 |
JVM_END |
|
2473 |
||
2474 |
||
2475 |
JVM_ENTRY(const char*, JVM_GetCPFieldClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)) |
|
2476 |
JVMWrapper("JVM_GetCPFieldClassNameUTF"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2477 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
1 | 2478 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2479 |
ConstantPool* cp = InstanceKlass::cast(k)->constants(); |
1 | 2480 |
switch (cp->tag_at(cp_index).value()) { |
2481 |
case JVM_CONSTANT_Fieldref: { |
|
2482 |
int class_index = cp->uncached_klass_ref_index_at(cp_index); |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
2483 |
Symbol* classname = cp->klass_name_at(class_index); |
1 | 2484 |
return classname->as_utf8(); |
2485 |
} |
|
2486 |
default: |
|
2487 |
fatal("JVM_GetCPFieldClassNameUTF: illegal constant"); |
|
2488 |
} |
|
2489 |
ShouldNotReachHere(); |
|
2490 |
return NULL; |
|
2491 |
JVM_END |
|
2492 |
||
2493 |
||
2494 |
JVM_ENTRY(const char*, JVM_GetCPMethodClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)) |
|
2495 |
JVMWrapper("JVM_GetCPMethodClassNameUTF"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2496 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
1 | 2497 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2498 |
ConstantPool* cp = InstanceKlass::cast(k)->constants(); |
1 | 2499 |
switch (cp->tag_at(cp_index).value()) { |
2500 |
case JVM_CONSTANT_Methodref: |
|
2501 |
case JVM_CONSTANT_InterfaceMethodref: { |
|
2502 |
int class_index = cp->uncached_klass_ref_index_at(cp_index); |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
2503 |
Symbol* classname = cp->klass_name_at(class_index); |
1 | 2504 |
return classname->as_utf8(); |
2505 |
} |
|
2506 |
default: |
|
2507 |
fatal("JVM_GetCPMethodClassNameUTF: illegal constant"); |
|
2508 |
} |
|
2509 |
ShouldNotReachHere(); |
|
2510 |
return NULL; |
|
2511 |
JVM_END |
|
2512 |
||
2513 |
||
10546 | 2514 |
JVM_ENTRY(jint, JVM_GetCPFieldModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls)) |
1 | 2515 |
JVMWrapper("JVM_GetCPFieldModifiers"); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2516 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2517 |
Klass* k_called = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(called_cls)); |
1 | 2518 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
2519 |
k_called = JvmtiThreadState::class_to_verify_considering_redefinition(k_called, thread); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2520 |
ConstantPool* cp = InstanceKlass::cast(k)->constants(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2521 |
ConstantPool* cp_called = InstanceKlass::cast(k_called)->constants(); |
1 | 2522 |
switch (cp->tag_at(cp_index).value()) { |
2523 |
case JVM_CONSTANT_Fieldref: { |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
2524 |
Symbol* name = cp->uncached_name_ref_at(cp_index); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
2525 |
Symbol* signature = cp->uncached_signature_ref_at(cp_index); |
10546 | 2526 |
for (JavaFieldStream fs(k_called); !fs.done(); fs.next()) { |
2527 |
if (fs.name() == name && fs.signature() == signature) { |
|
2528 |
return fs.access_flags().as_short() & JVM_RECOGNIZED_FIELD_MODIFIERS; |
|
1 | 2529 |
} |
2530 |
} |
|
2531 |
return -1; |
|
2532 |
} |
|
2533 |
default: |
|
2534 |
fatal("JVM_GetCPFieldModifiers: illegal constant"); |
|
2535 |
} |
|
2536 |
ShouldNotReachHere(); |
|
2537 |
return 0; |
|
2538 |
JVM_END |
|
2539 |
||
2540 |
||
2541 |
JVM_QUICK_ENTRY(jint, JVM_GetCPMethodModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls)) |
|
2542 |
JVMWrapper("JVM_GetCPMethodModifiers"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2543 |
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2544 |
Klass* k_called = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(called_cls)); |
1 | 2545 |
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); |
2546 |
k_called = JvmtiThreadState::class_to_verify_considering_redefinition(k_called, thread); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2547 |
ConstantPool* cp = InstanceKlass::cast(k)->constants(); |
1 | 2548 |
switch (cp->tag_at(cp_index).value()) { |
2549 |
case JVM_CONSTANT_Methodref: |
|
2550 |
case JVM_CONSTANT_InterfaceMethodref: { |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
2551 |
Symbol* name = cp->uncached_name_ref_at(cp_index); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
2552 |
Symbol* signature = cp->uncached_signature_ref_at(cp_index); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2553 |
Array<Method*>* methods = InstanceKlass::cast(k_called)->methods(); |
1 | 2554 |
int methods_count = methods->length(); |
2555 |
for (int i = 0; i < methods_count; i++) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2556 |
Method* method = methods->at(i); |
1 | 2557 |
if (method->name() == name && method->signature() == signature) { |
2558 |
return method->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS; |
|
2559 |
} |
|
2560 |
} |
|
2561 |
return -1; |
|
2562 |
} |
|
2563 |
default: |
|
2564 |
fatal("JVM_GetCPMethodModifiers: illegal constant"); |
|
2565 |
} |
|
2566 |
ShouldNotReachHere(); |
|
2567 |
return 0; |
|
2568 |
JVM_END |
|
2569 |
||
2570 |
||
2571 |
// Misc ////////////////////////////////////////////////////////////////////////////////////////////// |
|
2572 |
||
2573 |
JVM_LEAF(void, JVM_ReleaseUTF(const char *utf)) |
|
2574 |
// So long as UTF8::convert_to_utf8 returns resource strings, we don't have to do anything |
|
2575 |
JVM_END |
|
2576 |
||
2577 |
||
2578 |
JVM_ENTRY(jboolean, JVM_IsSameClassPackage(JNIEnv *env, jclass class1, jclass class2)) |
|
2579 |
JVMWrapper("JVM_IsSameClassPackage"); |
|
2580 |
oop class1_mirror = JNIHandles::resolve_non_null(class1); |
|
2581 |
oop class2_mirror = JNIHandles::resolve_non_null(class2); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2582 |
Klass* klass1 = java_lang_Class::as_Klass(class1_mirror); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
2583 |
Klass* klass2 = java_lang_Class::as_Klass(class2_mirror); |
1 | 2584 |
return (jboolean) Reflection::is_same_class_package(klass1, klass2); |
2585 |
JVM_END |
|
2586 |
||
2587 |
// Printing support ////////////////////////////////////////////////// |
|
2588 |
extern "C" { |
|
2589 |
||
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
24351
diff
changeset
|
2590 |
ATTRIBUTE_PRINTF(3, 0) |
1 | 2591 |
int jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args) { |
2592 |
// see bug 4399518, 4417214 |
|
2593 |
if ((intptr_t)count <= 0) return -1; |
|
27471 | 2594 |
|
2595 |
int result = vsnprintf(str, count, fmt, args); |
|
27667
3c814b51da6c
8064779: Add additional comments for "8062370: Various minor code improvements"
coleenp
parents:
27612
diff
changeset
|
2596 |
// Note: on truncation vsnprintf(3) on Unix returns numbers of |
3c814b51da6c
8064779: Add additional comments for "8062370: Various minor code improvements"
coleenp
parents:
27612
diff
changeset
|
2597 |
// characters which would have been written had the buffer been large |
3c814b51da6c
8064779: Add additional comments for "8062370: Various minor code improvements"
coleenp
parents:
27612
diff
changeset
|
2598 |
// enough; on Windows, it returns -1. We handle both cases here and |
3c814b51da6c
8064779: Add additional comments for "8062370: Various minor code improvements"
coleenp
parents:
27612
diff
changeset
|
2599 |
// always return -1, and perform null termination. |
27471 | 2600 |
if ((result > 0 && (size_t)result >= count) || result == -1) { |
2601 |
str[count - 1] = '\0'; |
|
2602 |
result = -1; |
|
2603 |
} |
|
2604 |
||
2605 |
return result; |
|
1 | 2606 |
} |
2607 |
||
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
24351
diff
changeset
|
2608 |
ATTRIBUTE_PRINTF(3, 0) |
1 | 2609 |
int jio_snprintf(char *str, size_t count, const char *fmt, ...) { |
2610 |
va_list args; |
|
2611 |
int len; |
|
2612 |
va_start(args, fmt); |
|
2613 |
len = jio_vsnprintf(str, count, fmt, args); |
|
2614 |
va_end(args); |
|
2615 |
return len; |
|
2616 |
} |
|
2617 |
||
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
24351
diff
changeset
|
2618 |
ATTRIBUTE_PRINTF(2,3) |
1 | 2619 |
int jio_fprintf(FILE* f, const char *fmt, ...) { |
2620 |
int len; |
|
2621 |
va_list args; |
|
2622 |
va_start(args, fmt); |
|
2623 |
len = jio_vfprintf(f, fmt, args); |
|
2624 |
va_end(args); |
|
2625 |
return len; |
|
2626 |
} |
|
2627 |
||
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
24351
diff
changeset
|
2628 |
ATTRIBUTE_PRINTF(2, 0) |
1 | 2629 |
int jio_vfprintf(FILE* f, const char *fmt, va_list args) { |
2630 |
if (Arguments::vfprintf_hook() != NULL) { |
|
2631 |
return Arguments::vfprintf_hook()(f, fmt, args); |
|
2632 |
} else { |
|
2633 |
return vfprintf(f, fmt, args); |
|
2634 |
} |
|
2635 |
} |
|
2636 |
||
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
24351
diff
changeset
|
2637 |
ATTRIBUTE_PRINTF(1, 2) |
8106 | 2638 |
JNIEXPORT int jio_printf(const char *fmt, ...) { |
1 | 2639 |
int len; |
2640 |
va_list args; |
|
2641 |
va_start(args, fmt); |
|
2642 |
len = jio_vfprintf(defaultStream::output_stream(), fmt, args); |
|
2643 |
va_end(args); |
|
2644 |
return len; |
|
2645 |
} |
|
2646 |
||
2647 |
||
2648 |
// HotSpot specific jio method |
|
2649 |
void jio_print(const char* s) { |
|
2650 |
// Try to make this function as atomic as possible. |
|
2651 |
if (Arguments::vfprintf_hook() != NULL) { |
|
2652 |
jio_fprintf(defaultStream::output_stream(), "%s", s); |
|
2653 |
} else { |
|
1889
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1550
diff
changeset
|
2654 |
// Make an unused local variable to avoid warning from gcc 4.x compiler. |
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1550
diff
changeset
|
2655 |
size_t count = ::write(defaultStream::output_fd(), s, (int)strlen(s)); |
1 | 2656 |
} |
2657 |
} |
|
2658 |
||
2659 |
} // Extern C |
|
2660 |
||
2661 |
// java.lang.Thread ////////////////////////////////////////////////////////////////////////////// |
|
2662 |
||
2663 |
// In most of the JVM Thread support functions we need to be sure to lock the Threads_lock |
|
2664 |
// to prevent the target thread from exiting after we have a pointer to the C++ Thread or |
|
2665 |
// OSThread objects. The exception to this rule is when the target object is the thread |
|
2666 |
// doing the operation, in which case we know that the thread won't exit until the |
|
2667 |
// operation is done (all exits being voluntary). There are a few cases where it is |
|
2668 |
// rather silly to do operations on yourself, like resuming yourself or asking whether |
|
2669 |
// you are alive. While these can still happen, they are not subject to deadlocks if |
|
2670 |
// the lock is held while the operation occurs (this is not the case for suspend, for |
|
2671 |
// instance), and are very unlikely. Because IsAlive needs to be fast and its |
|
2672 |
// implementation is local to this file, we always lock Threads_lock for that one. |
|
2673 |
||
2674 |
static void thread_entry(JavaThread* thread, TRAPS) { |
|
2675 |
HandleMark hm(THREAD); |
|
2676 |
Handle obj(THREAD, thread->threadObj()); |
|
2677 |
JavaValue result(T_VOID); |
|
2678 |
JavaCalls::call_virtual(&result, |
|
2679 |
obj, |
|
4571 | 2680 |
KlassHandle(THREAD, SystemDictionary::Thread_klass()), |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
2681 |
vmSymbols::run_method_name(), |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
2682 |
vmSymbols::void_method_signature(), |
1 | 2683 |
THREAD); |
2684 |
} |
|
2685 |
||
2686 |
||
2687 |
JVM_ENTRY(void, JVM_StartThread(JNIEnv* env, jobject jthread)) |
|
2688 |
JVMWrapper("JVM_StartThread"); |
|
2689 |
JavaThread *native_thread = NULL; |
|
2690 |
||
2691 |
// We cannot hold the Threads_lock when we throw an exception, |
|
2692 |
// due to rank ordering issues. Example: we might need to grab the |
|
2693 |
// Heap_lock while we construct the exception. |
|
2694 |
bool throw_illegal_thread_state = false; |
|
2695 |
||
2696 |
// We must release the Threads_lock before we can post a jvmti event |
|
2697 |
// in Thread::start. |
|
2698 |
{ |
|
2699 |
// Ensure that the C++ Thread and OSThread structures aren't freed before |
|
2700 |
// we operate. |
|
2701 |
MutexLocker mu(Threads_lock); |
|
2702 |
||
8061
07585870d15f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
7405
diff
changeset
|
2703 |
// Since JDK 5 the java.lang.Thread threadStatus is used to prevent |
07585870d15f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
7405
diff
changeset
|
2704 |
// re-starting an already started thread, so we should usually find |
07585870d15f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
7405
diff
changeset
|
2705 |
// that the JavaThread is null. However for a JNI attached thread |
07585870d15f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
7405
diff
changeset
|
2706 |
// there is a small window between the Thread object being created |
07585870d15f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
7405
diff
changeset
|
2707 |
// (with its JavaThread set) and the update to its threadStatus, so we |
07585870d15f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
7405
diff
changeset
|
2708 |
// have to check for this |
07585870d15f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
7405
diff
changeset
|
2709 |
if (java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread)) != NULL) { |
07585870d15f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
7405
diff
changeset
|
2710 |
throw_illegal_thread_state = true; |
1 | 2711 |
} else { |
8061
07585870d15f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
7405
diff
changeset
|
2712 |
// We could also check the stillborn flag to see if this thread was already stopped, but |
07585870d15f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
7405
diff
changeset
|
2713 |
// for historical reasons we let the thread detect that itself when it starts running |
07585870d15f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
7405
diff
changeset
|
2714 |
|
1 | 2715 |
jlong size = |
2716 |
java_lang_Thread::stackSize(JNIHandles::resolve_non_null(jthread)); |
|
2717 |
// Allocate the C++ Thread structure and create the native thread. The |
|
2718 |
// stack size retrieved from java is signed, but the constructor takes |
|
2719 |
// size_t (an unsigned type), so avoid passing negative values which would |
|
2720 |
// result in really large stacks. |
|
2721 |
size_t sz = size > 0 ? (size_t) size : 0; |
|
2722 |
native_thread = new JavaThread(&thread_entry, sz); |
|
2723 |
||
2724 |
// At this point it may be possible that no osthread was created for the |
|
2725 |
// JavaThread due to lack of memory. Check for this situation and throw |
|
2726 |
// an exception if necessary. Eventually we may want to change this so |
|
2727 |
// that we only grab the lock if the thread was created successfully - |
|
2728 |
// then we can also do this check and throw the exception in the |
|
2729 |
// JavaThread constructor. |
|
2730 |
if (native_thread->osthread() != NULL) { |
|
2731 |
// Note: the current thread is not being used within "prepare". |
|
2732 |
native_thread->prepare(jthread); |
|
2733 |
} |
|
2734 |
} |
|
2735 |
} |
|
2736 |
||
2737 |
if (throw_illegal_thread_state) { |
|
2738 |
THROW(vmSymbols::java_lang_IllegalThreadStateException()); |
|
2739 |
} |
|
2740 |
||
2741 |
assert(native_thread != NULL, "Starting null thread?"); |
|
2742 |
||
2743 |
if (native_thread->osthread() == NULL) { |
|
2744 |
// No one should hold a reference to the 'native_thread'. |
|
2745 |
delete native_thread; |
|
2746 |
if (JvmtiExport::should_post_resource_exhausted()) { |
|
2747 |
JvmtiExport::post_resource_exhausted( |
|
2748 |
JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR | JVMTI_RESOURCE_EXHAUSTED_THREADS, |
|
22758
c6b6abb73544
7182040: volano29 limited by os resource on Linux - need better diagnostic message
iklam
parents:
22189
diff
changeset
|
2749 |
os::native_thread_creation_failed_msg()); |
1 | 2750 |
} |
2751 |
THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(), |
|
22758
c6b6abb73544
7182040: volano29 limited by os resource on Linux - need better diagnostic message
iklam
parents:
22189
diff
changeset
|
2752 |
os::native_thread_creation_failed_msg()); |
1 | 2753 |
} |
2754 |
||
2755 |
Thread::start(native_thread); |
|
2756 |
||
2757 |
JVM_END |
|
2758 |
||
2759 |
// JVM_Stop is implemented using a VM_Operation, so threads are forced to safepoints |
|
2760 |
// before the quasi-asynchronous exception is delivered. This is a little obtrusive, |
|
2761 |
// but is thought to be reliable and simple. In the case, where the receiver is the |
|
8061
07585870d15f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
7405
diff
changeset
|
2762 |
// same thread as the sender, no safepoint is needed. |
1 | 2763 |
JVM_ENTRY(void, JVM_StopThread(JNIEnv* env, jobject jthread, jobject throwable)) |
2764 |
JVMWrapper("JVM_StopThread"); |
|
2765 |
||
2766 |
oop java_throwable = JNIHandles::resolve(throwable); |
|
2767 |
if (java_throwable == NULL) { |
|
2768 |
THROW(vmSymbols::java_lang_NullPointerException()); |
|
2769 |
} |
|
2770 |
oop java_thread = JNIHandles::resolve_non_null(jthread); |
|
2771 |
JavaThread* receiver = java_lang_Thread::thread(java_thread); |
|
11636
3c07b54482a5
7141200: log some interesting information in ring buffers for crashes
never
parents:
11256
diff
changeset
|
2772 |
Events::log_exception(JavaThread::current(), |
3c07b54482a5
7141200: log some interesting information in ring buffers for crashes
never
parents:
11256
diff
changeset
|
2773 |
"JVM_StopThread thread JavaThread " INTPTR_FORMAT " as oop " INTPTR_FORMAT " [exception " INTPTR_FORMAT "]", |
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
24351
diff
changeset
|
2774 |
p2i(receiver), p2i((address)java_thread), p2i(throwable)); |
8061
07585870d15f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
7405
diff
changeset
|
2775 |
// First check if thread is alive |
1 | 2776 |
if (receiver != NULL) { |
2777 |
// Check if exception is getting thrown at self (use oop equality, since the |
|
2778 |
// target object might exit) |
|
2779 |
if (java_thread == thread->threadObj()) { |
|
2780 |
THROW_OOP(java_throwable); |
|
2781 |
} else { |
|
2782 |
// Enques a VM_Operation to stop all threads and then deliver the exception... |
|
2783 |
Thread::send_async_exception(java_thread, JNIHandles::resolve(throwable)); |
|
2784 |
} |
|
2785 |
} |
|
8061
07585870d15f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
7405
diff
changeset
|
2786 |
else { |
07585870d15f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
7405
diff
changeset
|
2787 |
// Either: |
07585870d15f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
7405
diff
changeset
|
2788 |
// - target thread has not been started before being stopped, or |
07585870d15f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
7405
diff
changeset
|
2789 |
// - target thread already terminated |
07585870d15f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
7405
diff
changeset
|
2790 |
// We could read the threadStatus to determine which case it is |
07585870d15f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
7405
diff
changeset
|
2791 |
// but that is overkill as it doesn't matter. We must set the |
07585870d15f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
7405
diff
changeset
|
2792 |
// stillborn flag for the first case, and if the thread has already |
07585870d15f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
7405
diff
changeset
|
2793 |
// exited setting this flag has no affect |
07585870d15f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
7405
diff
changeset
|
2794 |
java_lang_Thread::set_stillborn(java_thread); |
07585870d15f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
7405
diff
changeset
|
2795 |
} |
1 | 2796 |
JVM_END |
2797 |
||
2798 |
||
2799 |
JVM_ENTRY(jboolean, JVM_IsThreadAlive(JNIEnv* env, jobject jthread)) |
|
2800 |
JVMWrapper("JVM_IsThreadAlive"); |
|
2801 |
||
2802 |
oop thread_oop = JNIHandles::resolve_non_null(jthread); |
|
2803 |
return java_lang_Thread::is_alive(thread_oop); |
|
2804 |
JVM_END |
|
2805 |
||
2806 |
||
2807 |
JVM_ENTRY(void, JVM_SuspendThread(JNIEnv* env, jobject jthread)) |
|
2808 |
JVMWrapper("JVM_SuspendThread"); |
|
2809 |
oop java_thread = JNIHandles::resolve_non_null(jthread); |
|
2810 |
JavaThread* receiver = java_lang_Thread::thread(java_thread); |
|
2811 |
||
2812 |
if (receiver != NULL) { |
|
2813 |
// thread has run and has not exited (still on threads list) |
|
2814 |
||
2815 |
{ |
|
2816 |
MutexLockerEx ml(receiver->SR_lock(), Mutex::_no_safepoint_check_flag); |
|
2817 |
if (receiver->is_external_suspend()) { |
|
2818 |
// Don't allow nested external suspend requests. We can't return |
|
2819 |
// an error from this interface so just ignore the problem. |
|
2820 |
return; |
|
2821 |
} |
|
2822 |
if (receiver->is_exiting()) { // thread is in the process of exiting |
|
2823 |
return; |
|
2824 |
} |
|
2825 |
receiver->set_external_suspend(); |
|
2826 |
} |
|
2827 |
||
2828 |
// java_suspend() will catch threads in the process of exiting |
|
2829 |
// and will ignore them. |
|
2830 |
receiver->java_suspend(); |
|
2831 |
||
2832 |
// It would be nice to have the following assertion in all the |
|
2833 |
// time, but it is possible for a racing resume request to have |
|
2834 |
// resumed this thread right after we suspended it. Temporarily |
|
2835 |
// enable this assertion if you are chasing a different kind of |
|
2836 |
// bug. |
|
2837 |
// |
|
2838 |
// assert(java_lang_Thread::thread(receiver->threadObj()) == NULL || |
|
2839 |
// receiver->is_being_ext_suspended(), "thread is not suspended"); |
|
2840 |
} |
|
2841 |
JVM_END |
|
2842 |
||
2843 |
||
2844 |
JVM_ENTRY(void, JVM_ResumeThread(JNIEnv* env, jobject jthread)) |
|
2845 |
JVMWrapper("JVM_ResumeThread"); |
|
2846 |
// Ensure that the C++ Thread and OSThread structures aren't freed before we operate. |
|
2847 |
// We need to *always* get the threads lock here, since this operation cannot be allowed during |
|
2848 |
// a safepoint. The safepoint code relies on suspending a thread to examine its state. If other |
|
2849 |
// threads randomly resumes threads, then a thread might not be suspended when the safepoint code |
|
2850 |
// looks at it. |
|
2851 |
MutexLocker ml(Threads_lock); |
|
2852 |
JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread)); |
|
2853 |
if (thr != NULL) { |
|
2854 |
// the thread has run and is not in the process of exiting |
|
2855 |
thr->java_resume(); |
|
2856 |
} |
|
2857 |
JVM_END |
|
2858 |
||
2859 |
||
2860 |
JVM_ENTRY(void, JVM_SetThreadPriority(JNIEnv* env, jobject jthread, jint prio)) |
|
2861 |
JVMWrapper("JVM_SetThreadPriority"); |
|
2862 |
// Ensure that the C++ Thread and OSThread structures aren't freed before we operate |
|
2863 |
MutexLocker ml(Threads_lock); |
|
2864 |
oop java_thread = JNIHandles::resolve_non_null(jthread); |
|
2865 |
java_lang_Thread::set_priority(java_thread, (ThreadPriority)prio); |
|
2866 |
JavaThread* thr = java_lang_Thread::thread(java_thread); |
|
2867 |
if (thr != NULL) { // Thread not yet started; priority pushed down when it is |
|
2868 |
Thread::set_priority(thr, (ThreadPriority)prio); |
|
2869 |
} |
|
2870 |
JVM_END |
|
2871 |
||
2872 |
||
2873 |
JVM_ENTRY(void, JVM_Yield(JNIEnv *env, jclass threadClass)) |
|
2874 |
JVMWrapper("JVM_Yield"); |
|
2875 |
if (os::dont_yield()) return; |
|
10739 | 2876 |
HOTSPOT_THREAD_YIELD(); |
22796 | 2877 |
|
1 | 2878 |
// When ConvertYieldToSleep is off (default), this matches the classic VM use of yield. |
2879 |
// Critical for similar threading behaviour |
|
2880 |
if (ConvertYieldToSleep) { |
|
2881 |
os::sleep(thread, MinSleepInterval, false); |
|
2882 |
} else { |
|
25477
7dad9f95fd31
8047714: Fix for JDK-6546236 made Solaris os::yield() a no-op
fparain
parents:
25468
diff
changeset
|
2883 |
os::naked_yield(); |
1 | 2884 |
} |
2885 |
JVM_END |
|
2886 |
||
2887 |
||
2888 |
JVM_ENTRY(void, JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis)) |
|
2889 |
JVMWrapper("JVM_Sleep"); |
|
2890 |
||
2891 |
if (millis < 0) { |
|
2892 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative"); |
|
2893 |
} |
|
2894 |
||
2895 |
if (Thread::is_interrupted (THREAD, true) && !HAS_PENDING_EXCEPTION) { |
|
2896 |
THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted"); |
|
2897 |
} |
|
2898 |
||
2899 |
// Save current thread state and restore it at the end of this block. |
|
2900 |
// And set new thread state to SLEEPING. |
|
2901 |
JavaThreadSleepState jtss(thread); |
|
2902 |
||
22796 | 2903 |
HOTSPOT_THREAD_SLEEP_BEGIN(millis); |
5089
0cce506a0158
6935224: Adding new DTrace probes to work with Palantir
fparain
parents:
4573
diff
changeset
|
2904 |
|
18025 | 2905 |
EventThreadSleep event; |
2906 |
||
1 | 2907 |
if (millis == 0) { |
2908 |
// When ConvertSleepToYield is on, this matches the classic VM implementation of |
|
2909 |
// JVM_Sleep. Critical for similar threading behaviour (Win32) |
|
2910 |
// It appears that in certain GUI contexts, it may be beneficial to do a short sleep |
|
2911 |
// for SOLARIS |
|
2912 |
if (ConvertSleepToYield) { |
|
25477
7dad9f95fd31
8047714: Fix for JDK-6546236 made Solaris os::yield() a no-op
fparain
parents:
25468
diff
changeset
|
2913 |
os::naked_yield(); |
1 | 2914 |
} else { |
2915 |
ThreadState old_state = thread->osthread()->get_state(); |
|
2916 |
thread->osthread()->set_state(SLEEPING); |
|
2917 |
os::sleep(thread, MinSleepInterval, false); |
|
2918 |
thread->osthread()->set_state(old_state); |
|
2919 |
} |
|
2920 |
} else { |
|
2921 |
ThreadState old_state = thread->osthread()->get_state(); |
|
2922 |
thread->osthread()->set_state(SLEEPING); |
|
2923 |
if (os::sleep(thread, millis, true) == OS_INTRPT) { |
|
2924 |
// An asynchronous exception (e.g., ThreadDeathException) could have been thrown on |
|
2925 |
// us while we were sleeping. We do not overwrite those. |
|
2926 |
if (!HAS_PENDING_EXCEPTION) { |
|
18025 | 2927 |
if (event.should_commit()) { |
2928 |
event.set_time(millis); |
|
2929 |
event.commit(); |
|
2930 |
} |
|
22796 | 2931 |
HOTSPOT_THREAD_SLEEP_END(1); |
2932 |
||
1 | 2933 |
// TODO-FIXME: THROW_MSG returns which means we will not call set_state() |
2934 |
// to properly restore the thread state. That's likely wrong. |
|
2935 |
THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted"); |
|
2936 |
} |
|
2937 |
} |
|
2938 |
thread->osthread()->set_state(old_state); |
|
2939 |
} |
|
18025 | 2940 |
if (event.should_commit()) { |
2941 |
event.set_time(millis); |
|
2942 |
event.commit(); |
|
2943 |
} |
|
22796 | 2944 |
HOTSPOT_THREAD_SLEEP_END(0); |
1 | 2945 |
JVM_END |
2946 |
||
2947 |
JVM_ENTRY(jobject, JVM_CurrentThread(JNIEnv* env, jclass threadClass)) |
|
2948 |
JVMWrapper("JVM_CurrentThread"); |
|
2949 |
oop jthread = thread->threadObj(); |
|
2950 |
assert (thread != NULL, "no current thread!"); |
|
2951 |
return JNIHandles::make_local(env, jthread); |
|
2952 |
JVM_END |
|
2953 |
||
2954 |
||
2955 |
JVM_ENTRY(jint, JVM_CountStackFrames(JNIEnv* env, jobject jthread)) |
|
2956 |
JVMWrapper("JVM_CountStackFrames"); |
|
2957 |
||
2958 |
// Ensure that the C++ Thread and OSThread structures aren't freed before we operate |
|
2959 |
oop java_thread = JNIHandles::resolve_non_null(jthread); |
|
2960 |
bool throw_illegal_thread_state = false; |
|
2961 |
int count = 0; |
|
2962 |
||
2963 |
{ |
|
2964 |
MutexLockerEx ml(thread->threadObj() == java_thread ? NULL : Threads_lock); |
|
2965 |
// We need to re-resolve the java_thread, since a GC might have happened during the |
|
2966 |
// acquire of the lock |
|
2967 |
JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread)); |
|
2968 |
||
2969 |
if (thr == NULL) { |
|
2970 |
// do nothing |
|
2971 |
} else if(! thr->is_external_suspend() || ! thr->frame_anchor()->walkable()) { |
|
2972 |
// Check whether this java thread has been suspended already. If not, throws |
|
2973 |
// IllegalThreadStateException. We defer to throw that exception until |
|
2974 |
// Threads_lock is released since loading exception class has to leave VM. |
|
2975 |
// The correct way to test a thread is actually suspended is |
|
2976 |
// wait_for_ext_suspend_completion(), but we can't call that while holding |
|
2977 |
// the Threads_lock. The above tests are sufficient for our purposes |
|
2978 |
// provided the walkability of the stack is stable - which it isn't |
|
2979 |
// 100% but close enough for most practical purposes. |
|
2980 |
throw_illegal_thread_state = true; |
|
2981 |
} else { |
|
2982 |
// Count all java activation, i.e., number of vframes |
|
2983 |
for(vframeStream vfst(thr); !vfst.at_end(); vfst.next()) { |
|
2984 |
// Native frames are not counted |
|
2985 |
if (!vfst.method()->is_native()) count++; |
|
2986 |
} |
|
2987 |
} |
|
2988 |
} |
|
2989 |
||
2990 |
if (throw_illegal_thread_state) { |
|
2991 |
THROW_MSG_0(vmSymbols::java_lang_IllegalThreadStateException(), |
|
2992 |
"this thread is not suspended"); |
|
2993 |
} |
|
2994 |
return count; |
|
2995 |
JVM_END |
|
2996 |
||
2997 |
// Consider: A better way to implement JVM_Interrupt() is to acquire |
|
2998 |
// Threads_lock to resolve the jthread into a Thread pointer, fetch |
|
2999 |
// Thread->platformevent, Thread->native_thr, Thread->parker, etc., |
|
3000 |
// drop Threads_lock, and the perform the unpark() and thr_kill() operations |
|
3001 |
// outside the critical section. Threads_lock is hot so we want to minimize |
|
3002 |
// the hold-time. A cleaner interface would be to decompose interrupt into |
|
3003 |
// two steps. The 1st phase, performed under Threads_lock, would return |
|
3004 |
// a closure that'd be invoked after Threads_lock was dropped. |
|
3005 |
// This tactic is safe as PlatformEvent and Parkers are type-stable (TSM) and |
|
3006 |
// admit spurious wakeups. |
|
3007 |
||
3008 |
JVM_ENTRY(void, JVM_Interrupt(JNIEnv* env, jobject jthread)) |
|
3009 |
JVMWrapper("JVM_Interrupt"); |
|
3010 |
||
3011 |
// Ensure that the C++ Thread and OSThread structures aren't freed before we operate |
|
3012 |
oop java_thread = JNIHandles::resolve_non_null(jthread); |
|
3013 |
MutexLockerEx ml(thread->threadObj() == java_thread ? NULL : Threads_lock); |
|
3014 |
// We need to re-resolve the java_thread, since a GC might have happened during the |
|
3015 |
// acquire of the lock |
|
3016 |
JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread)); |
|
3017 |
if (thr != NULL) { |
|
3018 |
Thread::interrupt(thr); |
|
3019 |
} |
|
3020 |
JVM_END |
|
3021 |
||
3022 |
||
3023 |
JVM_QUICK_ENTRY(jboolean, JVM_IsInterrupted(JNIEnv* env, jobject jthread, jboolean clear_interrupted)) |
|
3024 |
JVMWrapper("JVM_IsInterrupted"); |
|
3025 |
||
3026 |
// Ensure that the C++ Thread and OSThread structures aren't freed before we operate |
|
3027 |
oop java_thread = JNIHandles::resolve_non_null(jthread); |
|
3028 |
MutexLockerEx ml(thread->threadObj() == java_thread ? NULL : Threads_lock); |
|
3029 |
// We need to re-resolve the java_thread, since a GC might have happened during the |
|
3030 |
// acquire of the lock |
|
3031 |
JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread)); |
|
3032 |
if (thr == NULL) { |
|
3033 |
return JNI_FALSE; |
|
3034 |
} else { |
|
3035 |
return (jboolean) Thread::is_interrupted(thr, clear_interrupted != 0); |
|
3036 |
} |
|
3037 |
JVM_END |
|
3038 |
||
3039 |
||
3040 |
// Return true iff the current thread has locked the object passed in |
|
3041 |
||
3042 |
JVM_ENTRY(jboolean, JVM_HoldsLock(JNIEnv* env, jclass threadClass, jobject obj)) |
|
3043 |
JVMWrapper("JVM_HoldsLock"); |
|
3044 |
assert(THREAD->is_Java_thread(), "sanity check"); |
|
3045 |
if (obj == NULL) { |
|
3046 |
THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE); |
|
3047 |
} |
|
3048 |
Handle h_obj(THREAD, JNIHandles::resolve(obj)); |
|
3049 |
return ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, h_obj); |
|
3050 |
JVM_END |
|
3051 |
||
3052 |
||
3053 |
JVM_ENTRY(void, JVM_DumpAllStacks(JNIEnv* env, jclass)) |
|
3054 |
JVMWrapper("JVM_DumpAllStacks"); |
|
3055 |
VM_PrintThreads op; |
|
3056 |
VMThread::execute(&op); |
|
3057 |
if (JvmtiExport::should_post_data_dump()) { |
|
3058 |
JvmtiExport::post_data_dump(); |
|
3059 |
} |
|
3060 |
JVM_END |
|
3061 |
||
10739 | 3062 |
JVM_ENTRY(void, JVM_SetNativeThreadName(JNIEnv* env, jobject jthread, jstring name)) |
3063 |
JVMWrapper("JVM_SetNativeThreadName"); |
|
3064 |
ResourceMark rm(THREAD); |
|
3065 |
oop java_thread = JNIHandles::resolve_non_null(jthread); |
|
3066 |
JavaThread* thr = java_lang_Thread::thread(java_thread); |
|
3067 |
// Thread naming only supported for the current thread, doesn't work for |
|
3068 |
// target threads. |
|
3069 |
if (Thread::current() == thr && !thr->has_attached_via_jni()) { |
|
3070 |
// we don't set the name of an attached thread to avoid stepping |
|
3071 |
// on other programs |
|
3072 |
const char *thread_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name)); |
|
3073 |
os::set_native_thread_name(thread_name); |
|
3074 |
} |
|
3075 |
JVM_END |
|
1 | 3076 |
|
3077 |
// java.lang.SecurityManager /////////////////////////////////////////////////////////////////////// |
|
3078 |
||
3079 |
static bool is_trusted_frame(JavaThread* jthread, vframeStream* vfst) { |
|
3080 |
assert(jthread->is_Java_thread(), "must be a Java thread"); |
|
3081 |
if (jthread->privileged_stack_top() == NULL) return false; |
|
3082 |
if (jthread->privileged_stack_top()->frame_id() == vfst->frame_id()) { |
|
3083 |
oop loader = jthread->privileged_stack_top()->class_loader(); |
|
3084 |
if (loader == NULL) return true; |
|
3085 |
bool trusted = java_lang_ClassLoader::is_trusted_loader(loader); |
|
3086 |
if (trusted) return true; |
|
3087 |
} |
|
3088 |
return false; |
|
3089 |
} |
|
3090 |
||
3091 |
JVM_ENTRY(jclass, JVM_CurrentLoadedClass(JNIEnv *env)) |
|
3092 |
JVMWrapper("JVM_CurrentLoadedClass"); |
|
3093 |
ResourceMark rm(THREAD); |
|
3094 |
||
3095 |
for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) { |
|
3096 |
// if a method in a class in a trusted loader is in a doPrivileged, return NULL |
|
3097 |
bool trusted = is_trusted_frame(thread, &vfst); |
|
3098 |
if (trusted) return NULL; |
|
3099 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
3100 |
Method* m = vfst.method(); |
1 | 3101 |
if (!m->is_native()) { |
14391
df0a1573d5bd
8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents:
13952
diff
changeset
|
3102 |
InstanceKlass* holder = m->method_holder(); |
df0a1573d5bd
8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents:
13952
diff
changeset
|
3103 |
oop loader = holder->class_loader(); |
1 | 3104 |
if (loader != NULL && !java_lang_ClassLoader::is_trusted_loader(loader)) { |
14391
df0a1573d5bd
8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents:
13952
diff
changeset
|
3105 |
return (jclass) JNIHandles::make_local(env, holder->java_mirror()); |
1 | 3106 |
} |
3107 |
} |
|
3108 |
} |
|
3109 |
return NULL; |
|
3110 |
JVM_END |
|
3111 |
||
3112 |
||
3113 |
JVM_ENTRY(jobject, JVM_CurrentClassLoader(JNIEnv *env)) |
|
3114 |
JVMWrapper("JVM_CurrentClassLoader"); |
|
3115 |
ResourceMark rm(THREAD); |
|
3116 |
||
3117 |
for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) { |
|
3118 |
||
3119 |
// if a method in a class in a trusted loader is in a doPrivileged, return NULL |
|
3120 |
bool trusted = is_trusted_frame(thread, &vfst); |
|
3121 |
if (trusted) return NULL; |
|
3122 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
3123 |
Method* m = vfst.method(); |
1 | 3124 |
if (!m->is_native()) { |
14391
df0a1573d5bd
8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents:
13952
diff
changeset
|
3125 |
InstanceKlass* holder = m->method_holder(); |
1 | 3126 |
assert(holder->is_klass(), "just checking"); |
14391
df0a1573d5bd
8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents:
13952
diff
changeset
|
3127 |
oop loader = holder->class_loader(); |
1 | 3128 |
if (loader != NULL && !java_lang_ClassLoader::is_trusted_loader(loader)) { |
3129 |
return JNIHandles::make_local(env, loader); |
|
3130 |
} |
|
3131 |
} |
|
3132 |
} |
|
3133 |
return NULL; |
|
3134 |
JVM_END |
|
3135 |
||
3136 |
||
3137 |
JVM_ENTRY(jobjectArray, JVM_GetClassContext(JNIEnv *env)) |
|
3138 |
JVMWrapper("JVM_GetClassContext"); |
|
3139 |
ResourceMark rm(THREAD); |
|
3140 |
JvmtiVMObjectAllocEventCollector oam; |
|
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
3141 |
vframeStream vfst(thread); |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
3142 |
|
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
3143 |
if (SystemDictionary::reflect_CallerSensitive_klass() != NULL) { |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
3144 |
// This must only be called from SecurityManager.getClassContext |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
3145 |
Method* m = vfst.method(); |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
3146 |
if (!(m->method_holder() == SystemDictionary::SecurityManager_klass() && |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
3147 |
m->name() == vmSymbols::getClassContext_name() && |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
3148 |
m->signature() == vmSymbols::void_class_array_signature())) { |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
3149 |
THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "JVM_GetClassContext must only be called from SecurityManager.getClassContext"); |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
3150 |
} |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
3151 |
} |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
3152 |
|
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
3153 |
// Collect method holders |
18101
fdcebbc730e1
8010124: JVM_GetClassContext: use GrowableArray instead of KlassLink
drchase
parents:
17826
diff
changeset
|
3154 |
GrowableArray<KlassHandle>* klass_array = new GrowableArray<KlassHandle>(); |
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
3155 |
for (; !vfst.at_end(); vfst.security_next()) { |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
3156 |
Method* m = vfst.method(); |
1 | 3157 |
// Native frames are not returned |
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
3158 |
if (!m->is_ignored_by_security_stack_walk() && !m->is_native()) { |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15601
diff
changeset
|
3159 |
Klass* holder = m->method_holder(); |
1 | 3160 |
assert(holder->is_klass(), "just checking"); |
18101
fdcebbc730e1
8010124: JVM_GetClassContext: use GrowableArray instead of KlassLink
drchase
parents:
17826
diff
changeset
|
3161 |
klass_array->append(holder); |
1 | 3162 |
} |
3163 |
} |
|
3164 |
||
3165 |
// Create result array of type [Ljava/lang/Class; |
|
18101
fdcebbc730e1
8010124: JVM_GetClassContext: use GrowableArray instead of KlassLink
drchase
parents:
17826
diff
changeset
|
3166 |
objArrayOop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), klass_array->length(), CHECK_NULL); |
1 | 3167 |
// Fill in mirrors corresponding to method holders |
18101
fdcebbc730e1
8010124: JVM_GetClassContext: use GrowableArray instead of KlassLink
drchase
parents:
17826
diff
changeset
|
3168 |
for (int i = 0; i < klass_array->length(); i++) { |
fdcebbc730e1
8010124: JVM_GetClassContext: use GrowableArray instead of KlassLink
drchase
parents:
17826
diff
changeset
|
3169 |
result->obj_at_put(i, klass_array->at(i)->java_mirror()); |
1 | 3170 |
} |
3171 |
||
3172 |
return (jobjectArray) JNIHandles::make_local(env, result); |
|
3173 |
JVM_END |
|
3174 |
||
3175 |
||
3176 |
JVM_ENTRY(jint, JVM_ClassDepth(JNIEnv *env, jstring name)) |
|
3177 |
JVMWrapper("JVM_ClassDepth"); |
|
3178 |
ResourceMark rm(THREAD); |
|
3179 |
Handle h_name (THREAD, JNIHandles::resolve_non_null(name)); |
|
3180 |
Handle class_name_str = java_lang_String::internalize_classname(h_name, CHECK_0); |
|
3181 |
||
3182 |
const char* str = java_lang_String::as_utf8_string(class_name_str()); |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
3183 |
TempNewSymbol class_name_sym = SymbolTable::probe(str, (int)strlen(str)); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
3184 |
if (class_name_sym == NULL) { |
1 | 3185 |
return -1; |
3186 |
} |
|
3187 |
||
3188 |
int depth = 0; |
|
3189 |
||
3190 |
for(vframeStream vfst(thread); !vfst.at_end(); vfst.next()) { |
|
3191 |
if (!vfst.method()->is_native()) { |
|
14391
df0a1573d5bd
8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents:
13952
diff
changeset
|
3192 |
InstanceKlass* holder = vfst.method()->method_holder(); |
1 | 3193 |
assert(holder->is_klass(), "just checking"); |
14391
df0a1573d5bd
8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents:
13952
diff
changeset
|
3194 |
if (holder->name() == class_name_sym) { |
1 | 3195 |
return depth; |
3196 |
} |
|
3197 |
depth++; |
|
3198 |
} |
|
3199 |
} |
|
3200 |
return -1; |
|
3201 |
JVM_END |
|
3202 |
||
3203 |
||
3204 |
JVM_ENTRY(jint, JVM_ClassLoaderDepth(JNIEnv *env)) |
|
3205 |
JVMWrapper("JVM_ClassLoaderDepth"); |
|
3206 |
ResourceMark rm(THREAD); |
|
3207 |
int depth = 0; |
|
3208 |
for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) { |
|
3209 |
// if a method in a class in a trusted loader is in a doPrivileged, return -1 |
|
3210 |
bool trusted = is_trusted_frame(thread, &vfst); |
|
3211 |
if (trusted) return -1; |
|
3212 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
3213 |
Method* m = vfst.method(); |
1 | 3214 |
if (!m->is_native()) { |
14391
df0a1573d5bd
8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents:
13952
diff
changeset
|
3215 |
InstanceKlass* holder = m->method_holder(); |
1 | 3216 |
assert(holder->is_klass(), "just checking"); |
14391
df0a1573d5bd
8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents:
13952
diff
changeset
|
3217 |
oop loader = holder->class_loader(); |
1 | 3218 |
if (loader != NULL && !java_lang_ClassLoader::is_trusted_loader(loader)) { |
3219 |
return depth; |
|
3220 |
} |
|
3221 |
depth++; |
|
3222 |
} |
|
3223 |
} |
|
3224 |
return -1; |
|
3225 |
JVM_END |
|
3226 |
||
3227 |
||
3228 |
// java.lang.Package //////////////////////////////////////////////////////////////// |
|
3229 |
||
3230 |
||
3231 |
JVM_ENTRY(jstring, JVM_GetSystemPackage(JNIEnv *env, jstring name)) |
|
3232 |
JVMWrapper("JVM_GetSystemPackage"); |
|
3233 |
ResourceMark rm(THREAD); |
|
3234 |
JvmtiVMObjectAllocEventCollector oam; |
|
3235 |
char* str = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name)); |
|
3236 |
oop result = ClassLoader::get_system_package(str, CHECK_NULL); |
|
3237 |
return (jstring) JNIHandles::make_local(result); |
|
3238 |
JVM_END |
|
3239 |
||
3240 |
||
3241 |
JVM_ENTRY(jobjectArray, JVM_GetSystemPackages(JNIEnv *env)) |
|
3242 |
JVMWrapper("JVM_GetSystemPackages"); |
|
3243 |
JvmtiVMObjectAllocEventCollector oam; |
|
3244 |
objArrayOop result = ClassLoader::get_system_packages(CHECK_NULL); |
|
3245 |
return (jobjectArray) JNIHandles::make_local(result); |
|
3246 |
JVM_END |
|
3247 |
||
3248 |
||
3249 |
// ObjectInputStream /////////////////////////////////////////////////////////////// |
|
3250 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
3251 |
bool force_verify_field_access(Klass* current_class, Klass* field_class, AccessFlags access, bool classloader_only) { |
1 | 3252 |
if (current_class == NULL) { |
3253 |
return true; |
|
3254 |
} |
|
3255 |
if ((current_class == field_class) || access.is_public()) { |
|
3256 |
return true; |
|
3257 |
} |
|
3258 |
||
3259 |
if (access.is_protected()) { |
|
3260 |
// See if current_class is a subclass of field_class |
|
14488 | 3261 |
if (current_class->is_subclass_of(field_class)) { |
1 | 3262 |
return true; |
3263 |
} |
|
3264 |
} |
|
3265 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
3266 |
return (!access.is_private() && InstanceKlass::cast(current_class)->is_same_class_package(field_class)); |
1 | 3267 |
} |
3268 |
||
3269 |
// Return the first non-null class loader up the execution stack, or null |
|
3270 |
// if only code from the null class loader is on the stack. |
|
3271 |
||
3272 |
JVM_ENTRY(jobject, JVM_LatestUserDefinedLoader(JNIEnv *env)) |
|
3273 |
for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) { |
|
3274 |
vfst.skip_reflection_related_frames(); // Only needed for 1.4 reflection |
|
14391
df0a1573d5bd
8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents:
13952
diff
changeset
|
3275 |
oop loader = vfst.method()->method_holder()->class_loader(); |
1 | 3276 |
if (loader != NULL) { |
3277 |
return JNIHandles::make_local(env, loader); |
|
3278 |
} |
|
3279 |
} |
|
3280 |
return NULL; |
|
3281 |
JVM_END |
|
3282 |
||
3283 |
||
3284 |
// Array /////////////////////////////////////////////////////////////////////////////////////////// |
|
3285 |
||
3286 |
||
3287 |
// resolve array handle and check arguments |
|
3288 |
static inline arrayOop check_array(JNIEnv *env, jobject arr, bool type_array_only, TRAPS) { |
|
3289 |
if (arr == NULL) { |
|
3290 |
THROW_0(vmSymbols::java_lang_NullPointerException()); |
|
3291 |
} |
|
3292 |
oop a = JNIHandles::resolve_non_null(arr); |
|
27405
ea143278766c
6191224: (reflect) Misleading detail string in IllegalArgumentException thrown by Array.get<Type>
cjplummer
parents:
27171
diff
changeset
|
3293 |
if (!a->is_array()) { |
1 | 3294 |
THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Argument is not an array"); |
27405
ea143278766c
6191224: (reflect) Misleading detail string in IllegalArgumentException thrown by Array.get<Type>
cjplummer
parents:
27171
diff
changeset
|
3295 |
} else if (type_array_only && !a->is_typeArray()) { |
ea143278766c
6191224: (reflect) Misleading detail string in IllegalArgumentException thrown by Array.get<Type>
cjplummer
parents:
27171
diff
changeset
|
3296 |
THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Argument is not an array of primitive type"); |
1 | 3297 |
} |
3298 |
return arrayOop(a); |
|
3299 |
} |
|
3300 |
||
3301 |
||
3302 |
JVM_ENTRY(jint, JVM_GetArrayLength(JNIEnv *env, jobject arr)) |
|
3303 |
JVMWrapper("JVM_GetArrayLength"); |
|
3304 |
arrayOop a = check_array(env, arr, false, CHECK_0); |
|
3305 |
return a->length(); |
|
3306 |
JVM_END |
|
3307 |
||
3308 |
||
3309 |
JVM_ENTRY(jobject, JVM_GetArrayElement(JNIEnv *env, jobject arr, jint index)) |
|
3310 |
JVMWrapper("JVM_Array_Get"); |
|
3311 |
JvmtiVMObjectAllocEventCollector oam; |
|
3312 |
arrayOop a = check_array(env, arr, false, CHECK_NULL); |
|
3313 |
jvalue value; |
|
3314 |
BasicType type = Reflection::array_get(&value, a, index, CHECK_NULL); |
|
3315 |
oop box = Reflection::box(&value, type, CHECK_NULL); |
|
3316 |
return JNIHandles::make_local(env, box); |
|
3317 |
JVM_END |
|
3318 |
||
3319 |
||
3320 |
JVM_ENTRY(jvalue, JVM_GetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jint wCode)) |
|
3321 |
JVMWrapper("JVM_GetPrimitiveArrayElement"); |
|
3322 |
jvalue value; |
|
3323 |
value.i = 0; // to initialize value before getting used in CHECK |
|
3324 |
arrayOop a = check_array(env, arr, true, CHECK_(value)); |
|
3325 |
assert(a->is_typeArray(), "just checking"); |
|
3326 |
BasicType type = Reflection::array_get(&value, a, index, CHECK_(value)); |
|
3327 |
BasicType wide_type = (BasicType) wCode; |
|
3328 |
if (type != wide_type) { |
|
3329 |
Reflection::widen(&value, type, wide_type, CHECK_(value)); |
|
3330 |
} |
|
3331 |
return value; |
|
3332 |
JVM_END |
|
3333 |
||
3334 |
||
3335 |
JVM_ENTRY(void, JVM_SetArrayElement(JNIEnv *env, jobject arr, jint index, jobject val)) |
|
3336 |
JVMWrapper("JVM_SetArrayElement"); |
|
3337 |
arrayOop a = check_array(env, arr, false, CHECK); |
|
3338 |
oop box = JNIHandles::resolve(val); |
|
3339 |
jvalue value; |
|
3340 |
value.i = 0; // to initialize value before getting used in CHECK |
|
3341 |
BasicType value_type; |
|
3342 |
if (a->is_objArray()) { |
|
3343 |
// Make sure we do no unbox e.g. java/lang/Integer instances when storing into an object array |
|
3344 |
value_type = Reflection::unbox_for_regular_object(box, &value); |
|
3345 |
} else { |
|
3346 |
value_type = Reflection::unbox_for_primitive(box, &value, CHECK); |
|
3347 |
} |
|
3348 |
Reflection::array_set(&value, a, index, value_type, CHECK); |
|
3349 |
JVM_END |
|
3350 |
||
3351 |
||
3352 |
JVM_ENTRY(void, JVM_SetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jvalue v, unsigned char vCode)) |
|
3353 |
JVMWrapper("JVM_SetPrimitiveArrayElement"); |
|
3354 |
arrayOop a = check_array(env, arr, true, CHECK); |
|
3355 |
assert(a->is_typeArray(), "just checking"); |
|
3356 |
BasicType value_type = (BasicType) vCode; |
|
3357 |
Reflection::array_set(&v, a, index, value_type, CHECK); |
|
3358 |
JVM_END |
|
3359 |
||
3360 |
||
3361 |
JVM_ENTRY(jobject, JVM_NewArray(JNIEnv *env, jclass eltClass, jint length)) |
|
3362 |
JVMWrapper("JVM_NewArray"); |
|
3363 |
JvmtiVMObjectAllocEventCollector oam; |
|
3364 |
oop element_mirror = JNIHandles::resolve(eltClass); |
|
3365 |
oop result = Reflection::reflect_new_array(element_mirror, length, CHECK_NULL); |
|
3366 |
return JNIHandles::make_local(env, result); |
|
3367 |
JVM_END |
|
3368 |
||
3369 |
||
3370 |
JVM_ENTRY(jobject, JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim)) |
|
3371 |
JVMWrapper("JVM_NewMultiArray"); |
|
3372 |
JvmtiVMObjectAllocEventCollector oam; |
|
3373 |
arrayOop dim_array = check_array(env, dim, true, CHECK_NULL); |
|
3374 |
oop element_mirror = JNIHandles::resolve(eltClass); |
|
3375 |
assert(dim_array->is_typeArray(), "just checking"); |
|
3376 |
oop result = Reflection::reflect_new_multi_array(element_mirror, typeArrayOop(dim_array), CHECK_NULL); |
|
3377 |
return JNIHandles::make_local(env, result); |
|
3378 |
JVM_END |
|
3379 |
||
3380 |
||
3381 |
// Library support /////////////////////////////////////////////////////////////////////////// |
|
3382 |
||
3383 |
JVM_ENTRY_NO_ENV(void*, JVM_LoadLibrary(const char* name)) |
|
3384 |
//%note jvm_ct |
|
3385 |
JVMWrapper2("JVM_LoadLibrary (%s)", name); |
|
3386 |
char ebuf[1024]; |
|
3387 |
void *load_result; |
|
3388 |
{ |
|
3389 |
ThreadToNativeFromVM ttnfvm(thread); |
|
7405
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
3390 |
load_result = os::dll_load(name, ebuf, sizeof ebuf); |
1 | 3391 |
} |
3392 |
if (load_result == NULL) { |
|
3393 |
char msg[1024]; |
|
3394 |
jio_snprintf(msg, sizeof msg, "%s: %s", name, ebuf); |
|
3395 |
// Since 'ebuf' may contain a string encoded using |
|
3396 |
// platform encoding scheme, we need to pass |
|
3397 |
// Exceptions::unsafe_to_utf8 to the new_exception method |
|
3398 |
// as the last argument. See bug 6367357. |
|
3399 |
Handle h_exception = |
|
3400 |
Exceptions::new_exception(thread, |
|
3401 |
vmSymbols::java_lang_UnsatisfiedLinkError(), |
|
3402 |
msg, Exceptions::unsafe_to_utf8); |
|
3403 |
||
3404 |
THROW_HANDLE_0(h_exception); |
|
3405 |
} |
|
3406 |
return load_result; |
|
3407 |
JVM_END |
|
3408 |
||
3409 |
||
3410 |
JVM_LEAF(void, JVM_UnloadLibrary(void* handle)) |
|
3411 |
JVMWrapper("JVM_UnloadLibrary"); |
|
7405
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
3412 |
os::dll_unload(handle); |
1 | 3413 |
JVM_END |
3414 |
||
3415 |
||
3416 |
JVM_LEAF(void*, JVM_FindLibraryEntry(void* handle, const char* name)) |
|
3417 |
JVMWrapper2("JVM_FindLibraryEntry (%s)", name); |
|
7405
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
3418 |
return os::dll_lookup(handle, name); |
1 | 3419 |
JVM_END |
3420 |
||
11256
025cd1741566
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
10739
diff
changeset
|
3421 |
|
1 | 3422 |
// JNI version /////////////////////////////////////////////////////////////////////////////// |
3423 |
||
3424 |
JVM_LEAF(jboolean, JVM_IsSupportedJNIVersion(jint version)) |
|
3425 |
JVMWrapper2("JVM_IsSupportedJNIVersion (%d)", version); |
|
3426 |
return Threads::is_supported_jni_version_including_1_1(version); |
|
3427 |
JVM_END |
|
3428 |
||
3429 |
||
3430 |
// String support /////////////////////////////////////////////////////////////////////////// |
|
3431 |
||
3432 |
JVM_ENTRY(jstring, JVM_InternString(JNIEnv *env, jstring str)) |
|
3433 |
JVMWrapper("JVM_InternString"); |
|
3434 |
JvmtiVMObjectAllocEventCollector oam; |
|
3435 |
if (str == NULL) return NULL; |
|
3436 |
oop string = JNIHandles::resolve_non_null(str); |
|
3437 |
oop result = StringTable::intern(string, CHECK_NULL); |
|
3438 |
return (jstring) JNIHandles::make_local(env, result); |
|
3439 |
JVM_END |
|
3440 |
||
3441 |
||
3442 |
// Raw monitor support ////////////////////////////////////////////////////////////////////// |
|
3443 |
||
3444 |
// The lock routine below calls lock_without_safepoint_check in order to get a raw lock |
|
3445 |
// without interfering with the safepoint mechanism. The routines are not JVM_LEAF because |
|
3446 |
// they might be called by non-java threads. The JVM_LEAF installs a NoHandleMark check |
|
3447 |
// that only works with java threads. |
|
3448 |
||
3449 |
||
3450 |
JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void) { |
|
3451 |
VM_Exit::block_if_vm_exited(); |
|
3452 |
JVMWrapper("JVM_RawMonitorCreate"); |
|
3453 |
return new Mutex(Mutex::native, "JVM_RawMonitorCreate"); |
|
3454 |
} |
|
3455 |
||
3456 |
||
3457 |
JNIEXPORT void JNICALL JVM_RawMonitorDestroy(void *mon) { |
|
3458 |
VM_Exit::block_if_vm_exited(); |
|
3459 |
JVMWrapper("JVM_RawMonitorDestroy"); |
|
3460 |
delete ((Mutex*) mon); |
|
3461 |
} |
|
3462 |
||
3463 |
||
3464 |
JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void *mon) { |
|
3465 |
VM_Exit::block_if_vm_exited(); |
|
3466 |
JVMWrapper("JVM_RawMonitorEnter"); |
|
3467 |
((Mutex*) mon)->jvm_raw_lock(); |
|
3468 |
return 0; |
|
3469 |
} |
|
3470 |
||
3471 |
||
3472 |
JNIEXPORT void JNICALL JVM_RawMonitorExit(void *mon) { |
|
3473 |
VM_Exit::block_if_vm_exited(); |
|
3474 |
JVMWrapper("JVM_RawMonitorExit"); |
|
3475 |
((Mutex*) mon)->jvm_raw_unlock(); |
|
3476 |
} |
|
3477 |
||
3478 |
||
3479 |
// Shared JNI/JVM entry points ////////////////////////////////////////////////////////////// |
|
3480 |
||
27021 | 3481 |
jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init, |
3482 |
Handle loader, Handle protection_domain, |
|
3483 |
jboolean throwError, TRAPS) { |
|
1 | 3484 |
// Security Note: |
3485 |
// The Java level wrapper will perform the necessary security check allowing |
|
27021 | 3486 |
// us to pass the NULL as the initiating class loader. The VM is responsible for |
3487 |
// the checkPackageAccess relative to the initiating class loader via the |
|
3488 |
// protection_domain. The protection_domain is passed as NULL by the java code |
|
3489 |
// if there is no security manager in 3-arg Class.forName(). |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
3490 |
Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL); |
3578
411436f0a4a2
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
mchung
parents:
3575
diff
changeset
|
3491 |
|
1 | 3492 |
KlassHandle klass_handle(THREAD, klass); |
3493 |
// Check if we should initialize the class |
|
3494 |
if (init && klass_handle->oop_is_instance()) { |
|
3495 |
klass_handle->initialize(CHECK_NULL); |
|
3496 |
} |
|
3497 |
return (jclass) JNIHandles::make_local(env, klass_handle->java_mirror()); |
|
3498 |
} |
|
3499 |
||
3500 |
||
3501 |
// Method /////////////////////////////////////////////////////////////////////////////////////////// |
|
3502 |
||
3503 |
JVM_ENTRY(jobject, JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0)) |
|
3504 |
JVMWrapper("JVM_InvokeMethod"); |
|
3505 |
Handle method_handle; |
|
3506 |
if (thread->stack_available((address) &method_handle) >= JVMInvokeMethodSlack) { |
|
3507 |
method_handle = Handle(THREAD, JNIHandles::resolve(method)); |
|
3508 |
Handle receiver(THREAD, JNIHandles::resolve(obj)); |
|
3509 |
objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0))); |
|
3510 |
oop result = Reflection::invoke_method(method_handle(), receiver, args, CHECK_NULL); |
|
3511 |
jobject res = JNIHandles::make_local(env, result); |
|
3512 |
if (JvmtiExport::should_post_vm_object_alloc()) { |
|
3513 |
oop ret_type = java_lang_reflect_Method::return_type(method_handle()); |
|
3514 |
assert(ret_type != NULL, "sanity check: ret_type oop must not be NULL!"); |
|
3515 |
if (java_lang_Class::is_primitive(ret_type)) { |
|
3516 |
// Only for primitive type vm allocates memory for java object. |
|
3517 |
// See box() method. |
|
3518 |
JvmtiExport::post_vm_object_alloc(JavaThread::current(), result); |
|
3519 |
} |
|
3520 |
} |
|
3521 |
return res; |
|
3522 |
} else { |
|
3523 |
THROW_0(vmSymbols::java_lang_StackOverflowError()); |
|
3524 |
} |
|
3525 |
JVM_END |
|
3526 |
||
3527 |
||
3528 |
JVM_ENTRY(jobject, JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0)) |
|
3529 |
JVMWrapper("JVM_NewInstanceFromConstructor"); |
|
3530 |
oop constructor_mirror = JNIHandles::resolve(c); |
|
3531 |
objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0))); |
|
3532 |
oop result = Reflection::invoke_constructor(constructor_mirror, args, CHECK_NULL); |
|
3533 |
jobject res = JNIHandles::make_local(env, result); |
|
3534 |
if (JvmtiExport::should_post_vm_object_alloc()) { |
|
3535 |
JvmtiExport::post_vm_object_alloc(JavaThread::current(), result); |
|
3536 |
} |
|
3537 |
return res; |
|
3538 |
JVM_END |
|
3539 |
||
3540 |
// Atomic /////////////////////////////////////////////////////////////////////////////////////////// |
|
3541 |
||
3542 |
JVM_LEAF(jboolean, JVM_SupportsCX8()) |
|
3543 |
JVMWrapper("JVM_SupportsCX8"); |
|
3544 |
return VM_Version::supports_cx8(); |
|
3545 |
JVM_END |
|
3546 |
||
363
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3547 |
// DTrace /////////////////////////////////////////////////////////////////// |
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3548 |
|
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3549 |
JVM_ENTRY(jint, JVM_DTraceGetVersion(JNIEnv* env)) |
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3550 |
JVMWrapper("JVM_DTraceGetVersion"); |
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3551 |
return (jint)JVM_TRACING_DTRACE_VERSION; |
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3552 |
JVM_END |
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3553 |
|
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3554 |
JVM_ENTRY(jlong,JVM_DTraceActivate( |
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3555 |
JNIEnv* env, jint version, jstring module_name, jint providers_count, |
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3556 |
JVM_DTraceProvider* providers)) |
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3557 |
JVMWrapper("JVM_DTraceActivate"); |
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3558 |
return DTraceJSDT::activate( |
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3559 |
version, module_name, providers_count, providers, CHECK_0); |
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3560 |
JVM_END |
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3561 |
|
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3562 |
JVM_ENTRY(jboolean,JVM_DTraceIsProbeEnabled(JNIEnv* env, jmethodID method)) |
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3563 |
JVMWrapper("JVM_DTraceIsProbeEnabled"); |
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3564 |
return DTraceJSDT::is_probe_enabled(method); |
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3565 |
JVM_END |
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3566 |
|
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3567 |
JVM_ENTRY(void,JVM_DTraceDispose(JNIEnv* env, jlong handle)) |
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3568 |
JVMWrapper("JVM_DTraceDispose"); |
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3569 |
DTraceJSDT::dispose(handle); |
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3570 |
JVM_END |
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3571 |
|
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3572 |
JVM_ENTRY(jboolean,JVM_DTraceIsSupported(JNIEnv* env)) |
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3573 |
JVMWrapper("JVM_DTraceIsSupported"); |
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3574 |
return DTraceJSDT::is_supported(); |
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3575 |
JVM_END |
99d43e8a76ad
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents:
1
diff
changeset
|
3576 |
|
1 | 3577 |
// Returns an array of all live Thread objects (VM internal JavaThreads, |
3578 |
// jvmti agent threads, and JNI attaching threads are skipped) |
|
3579 |
// See CR 6404306 regarding JNI attaching threads |
|
3580 |
JVM_ENTRY(jobjectArray, JVM_GetAllThreads(JNIEnv *env, jclass dummy)) |
|
3581 |
ResourceMark rm(THREAD); |
|
3582 |
ThreadsListEnumerator tle(THREAD, false, false); |
|
3583 |
JvmtiVMObjectAllocEventCollector oam; |
|
3584 |
||
3585 |
int num_threads = tle.num_threads(); |
|
4571 | 3586 |
objArrayOop r = oopFactory::new_objArray(SystemDictionary::Thread_klass(), num_threads, CHECK_NULL); |
1 | 3587 |
objArrayHandle threads_ah(THREAD, r); |
3588 |
||
3589 |
for (int i = 0; i < num_threads; i++) { |
|
3590 |
Handle h = tle.get_threadObj(i); |
|
3591 |
threads_ah->obj_at_put(i, h()); |
|
3592 |
} |
|
3593 |
||
3594 |
return (jobjectArray) JNIHandles::make_local(env, threads_ah()); |
|
3595 |
JVM_END |
|
3596 |
||
3597 |
||
3598 |
// Support for java.lang.Thread.getStackTrace() and getAllStackTraces() methods |
|
3599 |
// Return StackTraceElement[][], each element is the stack trace of a thread in |
|
3600 |
// the corresponding entry in the given threads array |
|
3601 |
JVM_ENTRY(jobjectArray, JVM_DumpThreads(JNIEnv *env, jclass threadClass, jobjectArray threads)) |
|
3602 |
JVMWrapper("JVM_DumpThreads"); |
|
3603 |
JvmtiVMObjectAllocEventCollector oam; |
|
3604 |
||
3605 |
// Check if threads is null |
|
3606 |
if (threads == NULL) { |
|
3607 |
THROW_(vmSymbols::java_lang_NullPointerException(), 0); |
|
3608 |
} |
|
3609 |
||
3610 |
objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(threads)); |
|
3611 |
objArrayHandle ah(THREAD, a); |
|
3612 |
int num_threads = ah->length(); |
|
3613 |
// check if threads is non-empty array |
|
3614 |
if (num_threads == 0) { |
|
3615 |
THROW_(vmSymbols::java_lang_IllegalArgumentException(), 0); |
|
3616 |
} |
|
3617 |
||
3618 |
// check if threads is not an array of objects of Thread class |
|
13952
e3cf184080bc
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
13728
diff
changeset
|
3619 |
Klass* k = ObjArrayKlass::cast(ah->klass())->element_klass(); |
4571 | 3620 |
if (k != SystemDictionary::Thread_klass()) { |
1 | 3621 |
THROW_(vmSymbols::java_lang_IllegalArgumentException(), 0); |
3622 |
} |
|
3623 |
||
3624 |
ResourceMark rm(THREAD); |
|
3625 |
||
3626 |
GrowableArray<instanceHandle>* thread_handle_array = new GrowableArray<instanceHandle>(num_threads); |
|
3627 |
for (int i = 0; i < num_threads; i++) { |
|
3628 |
oop thread_obj = ah->obj_at(i); |
|
3629 |
instanceHandle h(THREAD, (instanceOop) thread_obj); |
|
3630 |
thread_handle_array->append(h); |
|
3631 |
} |
|
3632 |
||
3633 |
Handle stacktraces = ThreadService::dump_stack_traces(thread_handle_array, num_threads, CHECK_NULL); |
|
3634 |
return (jobjectArray)JNIHandles::make_local(env, stacktraces()); |
|
3635 |
||
3636 |
JVM_END |
|
3637 |
||
3638 |
// JVM monitoring and management support |
|
3639 |
JVM_ENTRY_NO_ENV(void*, JVM_GetManagement(jint version)) |
|
3640 |
return Management::get_jmm_interface(version); |
|
3641 |
JVM_END |
|
3642 |
||
3643 |
// com.sun.tools.attach.VirtualMachine agent properties support |
|
3644 |
// |
|
3645 |
// Initialize the agent properties with the properties maintained in the VM |
|
3646 |
JVM_ENTRY(jobject, JVM_InitAgentProperties(JNIEnv *env, jobject properties)) |
|
3647 |
JVMWrapper("JVM_InitAgentProperties"); |
|
3648 |
ResourceMark rm; |
|
3649 |
||
3650 |
Handle props(THREAD, JNIHandles::resolve_non_null(properties)); |
|
3651 |
||
3652 |
PUTPROP(props, "sun.java.command", Arguments::java_command()); |
|
3653 |
PUTPROP(props, "sun.jvm.flags", Arguments::jvm_flags()); |
|
3654 |
PUTPROP(props, "sun.jvm.args", Arguments::jvm_args()); |
|
3655 |
return properties; |
|
3656 |
JVM_END |
|
3657 |
||
3658 |
JVM_ENTRY(jobjectArray, JVM_GetEnclosingMethodInfo(JNIEnv *env, jclass ofClass)) |
|
3659 |
{ |
|
3660 |
JVMWrapper("JVM_GetEnclosingMethodInfo"); |
|
3661 |
JvmtiVMObjectAllocEventCollector oam; |
|
3662 |
||
3663 |
if (ofClass == NULL) { |
|
3664 |
return NULL; |
|
3665 |
} |
|
3666 |
Handle mirror(THREAD, JNIHandles::resolve_non_null(ofClass)); |
|
3667 |
// Special handling for primitive objects |
|
3668 |
if (java_lang_Class::is_primitive(mirror())) { |
|
3669 |
return NULL; |
|
3670 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
3671 |
Klass* k = java_lang_Class::as_Klass(mirror()); |
14488 | 3672 |
if (!k->oop_is_instance()) { |
1 | 3673 |
return NULL; |
3674 |
} |
|
3675 |
instanceKlassHandle ik_h(THREAD, k); |
|
3676 |
int encl_method_class_idx = ik_h->enclosing_method_class_index(); |
|
3677 |
if (encl_method_class_idx == 0) { |
|
3678 |
return NULL; |
|
3679 |
} |
|
4571 | 3680 |
objArrayOop dest_o = oopFactory::new_objArray(SystemDictionary::Object_klass(), 3, CHECK_NULL); |
1 | 3681 |
objArrayHandle dest(THREAD, dest_o); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
3682 |
Klass* enc_k = ik_h->constants()->klass_at(encl_method_class_idx, CHECK_NULL); |
14488 | 3683 |
dest->obj_at_put(0, enc_k->java_mirror()); |
1 | 3684 |
int encl_method_method_idx = ik_h->enclosing_method_method_index(); |
3685 |
if (encl_method_method_idx != 0) { |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
3686 |
Symbol* sym = ik_h->constants()->symbol_at( |
1 | 3687 |
extract_low_short_from_int( |
3688 |
ik_h->constants()->name_and_type_at(encl_method_method_idx))); |
|
3689 |
Handle str = java_lang_String::create_from_symbol(sym, CHECK_NULL); |
|
3690 |
dest->obj_at_put(1, str()); |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
8061
diff
changeset
|
3691 |
sym = ik_h->constants()->symbol_at( |
1 | 3692 |
extract_high_short_from_int( |
3693 |
ik_h->constants()->name_and_type_at(encl_method_method_idx))); |
|
3694 |
str = java_lang_String::create_from_symbol(sym, CHECK_NULL); |
|
3695 |
dest->obj_at_put(2, str()); |
|
3696 |
} |
|
3697 |
return (jobjectArray) JNIHandles::make_local(dest()); |
|
3698 |
} |
|
3699 |
JVM_END |
|
3700 |
||
3701 |
JVM_ENTRY(void, JVM_GetVersionInfo(JNIEnv* env, jvm_version_info* info, size_t info_size)) |
|
3702 |
{ |
|
23178
e7bdf3ea2a34
8035893: JVM_GetVersionInfo fails to zero structure
igerasim
parents:
22897
diff
changeset
|
3703 |
memset(info, 0, info_size); |
1 | 3704 |
|
3705 |
info->jvm_version = Abstract_VM_Version::jvm_version(); |
|
3706 |
info->update_version = 0; /* 0 in HotSpot Express VM */ |
|
3707 |
info->special_update_version = 0; /* 0 in HotSpot Express VM */ |
|
3708 |
||
3709 |
// when we add a new capability in the jvm_version_info struct, we should also |
|
3710 |
// consider to expose this new capability in the sun.rt.jvmCapabilities jvmstat |
|
3711 |
// counter defined in runtimeService.cpp. |
|
3712 |
info->is_attachable = AttachListener::is_attach_supported(); |
|
3713 |
} |
|
3714 |
JVM_END |