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