6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "gc/shared/collectedHeap.hpp"
27 #include "gc/shared/oopStorage.inline.hpp"
28 #include "gc/shared/oopStorageSet.hpp"
29 #include "logging/log.hpp"
30 #include "memory/iterator.hpp"
31 #include "memory/universe.hpp"
32 #include "oops/access.inline.hpp"
33 #include "oops/oop.inline.hpp"
34 #include "runtime/handles.inline.hpp"
35 #include "runtime/javaThread.inline.hpp"
36 #include "runtime/jniHandles.inline.hpp"
37 #include "runtime/mutexLocker.hpp"
38 #include "utilities/align.hpp"
39 #include "utilities/debug.hpp"
40
41 OopStorage* JNIHandles::global_handles() {
42 return _global_handles;
43 }
44
45 OopStorage* JNIHandles::weak_global_handles() {
46 return _weak_global_handles;
47 }
48
49 // Serviceability agent support.
50 OopStorage* JNIHandles::_global_handles = NULL;
51 OopStorage* JNIHandles::_weak_global_handles = NULL;
52
53 void jni_handles_init() {
54 JNIHandles::_global_handles = OopStorageSet::create_strong("JNI Global", mtInternal);
271 guarantee(oopDesc::is_oop_or_null(RawAccess<>::oop_load(root)), "Invalid oop");
272 }
273 virtual void do_oop(narrowOop* root) { ShouldNotReachHere(); }
274 };
275
276 void JNIHandles::verify() {
277 VerifyJNIHandles verify_handle;
278
279 oops_do(&verify_handle);
280 weak_oops_do(&verify_handle);
281 }
282
283 // This method is implemented here to avoid circular includes between
284 // jniHandles.hpp and thread.hpp.
285 bool JNIHandles::current_thread_in_native() {
286 Thread* thread = Thread::current();
287 return (thread->is_Java_thread() &&
288 JavaThread::cast(thread)->thread_state() == _thread_in_native);
289 }
290
291 int JNIHandleBlock::_blocks_allocated = 0;
292
293 static inline bool is_tagged_free_list(uintptr_t value) {
294 return (value & 1u) != 0;
295 }
296
297 static inline uintptr_t tag_free_list(uintptr_t value) {
298 return value | 1u;
299 }
300
301 static inline uintptr_t untag_free_list(uintptr_t value) {
302 return value & ~(uintptr_t)1u;
303 }
304
305 // There is a freelist of handles running through the JNIHandleBlock
306 // with a tagged next pointer, distinguishing these next pointers from
307 // oops. The freelist handling currently relies on the size of oops
308 // being the same as a native pointer. If this ever changes, then
309 // this freelist handling must change too.
310 STATIC_ASSERT(sizeof(oop) == sizeof(uintptr_t));
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/vmSymbols.hpp"
27 #include "gc/shared/collectedHeap.hpp"
28 #include "gc/shared/oopStorage.inline.hpp"
29 #include "gc/shared/oopStorageSet.hpp"
30 #include "logging/log.hpp"
31 #include "memory/iterator.hpp"
32 #include "memory/universe.hpp"
33 #include "oops/access.inline.hpp"
34 #include "oops/oop.inline.hpp"
35 #include "runtime/handles.inline.hpp"
36 #include "runtime/javaCalls.hpp"
37 #include "runtime/javaThread.inline.hpp"
38 #include "runtime/jniHandles.inline.hpp"
39 #include "runtime/mutexLocker.hpp"
40 #include "utilities/align.hpp"
41 #include "utilities/debug.hpp"
42
43 OopStorage* JNIHandles::global_handles() {
44 return _global_handles;
45 }
46
47 OopStorage* JNIHandles::weak_global_handles() {
48 return _weak_global_handles;
49 }
50
51 // Serviceability agent support.
52 OopStorage* JNIHandles::_global_handles = NULL;
53 OopStorage* JNIHandles::_weak_global_handles = NULL;
54
55 void jni_handles_init() {
56 JNIHandles::_global_handles = OopStorageSet::create_strong("JNI Global", mtInternal);
273 guarantee(oopDesc::is_oop_or_null(RawAccess<>::oop_load(root)), "Invalid oop");
274 }
275 virtual void do_oop(narrowOop* root) { ShouldNotReachHere(); }
276 };
277
278 void JNIHandles::verify() {
279 VerifyJNIHandles verify_handle;
280
281 oops_do(&verify_handle);
282 weak_oops_do(&verify_handle);
283 }
284
285 // This method is implemented here to avoid circular includes between
286 // jniHandles.hpp and thread.hpp.
287 bool JNIHandles::current_thread_in_native() {
288 Thread* thread = Thread::current();
289 return (thread->is_Java_thread() &&
290 JavaThread::cast(thread)->thread_state() == _thread_in_native);
291 }
292
293 bool JNIHandles::is_same_object(jobject handle1, jobject handle2) {
294 oop obj1 = resolve_no_keepalive(handle1);
295 oop obj2 = resolve_no_keepalive(handle2);
296
297 bool ret = obj1 == obj2;
298
299 if (EnableValhalla) {
300 if (!ret && obj1 != NULL && obj2 != NULL && obj1->klass() == obj2->klass() && obj1->klass()->is_inline_klass()) {
301 // The two references are different, they are not null and they are both inline types,
302 // a full substitutability test is required, calling ValueObjectMethods.isSubstitutable()
303 // (similarly to InterpreterRuntime::is_substitutable)
304 JavaThread* THREAD = JavaThread::current();
305 Handle ha(THREAD, obj1);
306 Handle hb(THREAD, obj2);
307 JavaValue result(T_BOOLEAN);
308 JavaCallArguments args;
309 args.push_oop(ha);
310 args.push_oop(hb);
311 methodHandle method(THREAD, Universe::is_substitutable_method());
312 JavaCalls::call(&result, method, &args, THREAD);
313 if (HAS_PENDING_EXCEPTION) {
314 // Something really bad happened because isSubstitutable() should not throw exceptions
315 // If it is an error, just let it propagate
316 // If it is an exception, wrap it into an InternalError
317 if (!PENDING_EXCEPTION->is_a(vmClasses::Error_klass())) {
318 Handle e(THREAD, PENDING_EXCEPTION);
319 CLEAR_PENDING_EXCEPTION;
320 THROW_MSG_CAUSE_(vmSymbols::java_lang_InternalError(), "Internal error in substitutability test", e, false);
321 }
322 }
323 ret = result.get_jboolean();
324 }
325 }
326
327 return ret;
328 }
329
330
331 int JNIHandleBlock::_blocks_allocated = 0;
332
333 static inline bool is_tagged_free_list(uintptr_t value) {
334 return (value & 1u) != 0;
335 }
336
337 static inline uintptr_t tag_free_list(uintptr_t value) {
338 return value | 1u;
339 }
340
341 static inline uintptr_t untag_free_list(uintptr_t value) {
342 return value & ~(uintptr_t)1u;
343 }
344
345 // There is a freelist of handles running through the JNIHandleBlock
346 // with a tagged next pointer, distinguishing these next pointers from
347 // oops. The freelist handling currently relies on the size of oops
348 // being the same as a native pointer. If this ever changes, then
349 // this freelist handling must change too.
350 STATIC_ASSERT(sizeof(oop) == sizeof(uintptr_t));
|