21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/classFileStream.hpp"
27 #include "classfile/vmSymbols.hpp"
28 #include "memory/allocation.inline.hpp"
29 #include "memory/resourceArea.hpp"
30 #include "oops/fieldStreams.hpp"
31 #include "oops/objArrayOop.inline.hpp"
32 #include "oops/oop.inline.hpp"
33 #include "prims/jni.h"
34 #include "prims/jvm.h"
35 #include "prims/unsafe.hpp"
36 #include "runtime/atomic.hpp"
37 #include "runtime/globals.hpp"
38 #include "runtime/interfaceSupport.hpp"
39 #include "runtime/orderAccess.inline.hpp"
40 #include "runtime/reflection.hpp"
41 #include "runtime/vm_version.hpp"
42 #include "services/threadService.hpp"
43 #include "trace/tracing.hpp"
44 #include "utilities/align.hpp"
45 #include "utilities/copy.hpp"
46 #include "utilities/dtrace.hpp"
47 #include "utilities/macros.hpp"
48 #if INCLUDE_ALL_GCS
49 #include "gc/g1/g1SATBCardTableModRefBS.hpp"
50 #endif // INCLUDE_ALL_GCS
51
52 /**
53 * Implementation of the jdk.internal.misc.Unsafe class
54 */
55
56
57 #define MAX_OBJECT_SIZE \
58 ( arrayOopDesc::header_size(T_DOUBLE) * HeapWordSize \
59 + ((julong)max_jint * sizeof(double)) )
60
1087 HOTSPOT_THREAD_PARK_BEGIN((uintptr_t) thread->parker(), (int) isAbsolute, time);
1088
1089 JavaThreadParkedState jtps(thread, time != 0);
1090 thread->parker()->park(isAbsolute != 0, time);
1091
1092 HOTSPOT_THREAD_PARK_END((uintptr_t) thread->parker());
1093
1094 if (event.should_commit()) {
1095 oop obj = thread->current_park_blocker();
1096 event.set_parkedClass((obj != NULL) ? obj->klass() : NULL);
1097 event.set_timeout(time);
1098 event.set_address((obj != NULL) ? (TYPE_ADDRESS) cast_from_oop<uintptr_t>(obj) : 0);
1099 event.commit();
1100 }
1101 } UNSAFE_END
1102
1103 UNSAFE_ENTRY(void, Unsafe_Unpark(JNIEnv *env, jobject unsafe, jobject jthread)) {
1104 Parker* p = NULL;
1105
1106 if (jthread != NULL) {
1107 oop java_thread = JNIHandles::resolve_non_null(jthread);
1108 if (java_thread != NULL) {
1109 jlong lp = java_lang_Thread::park_event(java_thread);
1110 if (lp != 0) {
1111 // This cast is OK even though the jlong might have been read
1112 // non-atomically on 32bit systems, since there, one word will
1113 // always be zero anyway and the value set is always the same
1114 p = (Parker*)addr_from_java(lp);
1115 } else {
1116 // Grab lock if apparently null or using older version of library
1117 MutexLocker mu(Threads_lock);
1118 java_thread = JNIHandles::resolve_non_null(jthread);
1119
1120 if (java_thread != NULL) {
1121 JavaThread* thr = java_lang_Thread::thread(java_thread);
1122 if (thr != NULL) {
1123 p = thr->parker();
1124 if (p != NULL) { // Bind to Java thread for next time.
1125 java_lang_Thread::set_park_event(java_thread, addr_to_java(p));
1126 }
1127 }
1128 }
1129 }
1130 }
1131 }
1132
1133 if (p != NULL) {
1134 HOTSPOT_THREAD_UNPARK((uintptr_t) p);
1135 p->unpark();
1136 }
1137 } UNSAFE_END
1138
1139 UNSAFE_ENTRY(jint, Unsafe_GetLoadAverage0(JNIEnv *env, jobject unsafe, jdoubleArray loadavg, jint nelem)) {
1140 const int max_nelem = 3;
1141 double la[max_nelem];
1142 jint ret;
1143
1144 typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(loadavg));
1145 assert(a->is_typeArray(), "must be type array");
1146
1147 ret = os::loadavg(la, nelem);
1148 if (ret == -1) {
1149 return -1;
1150 }
1151
|
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/classFileStream.hpp"
27 #include "classfile/vmSymbols.hpp"
28 #include "memory/allocation.inline.hpp"
29 #include "memory/resourceArea.hpp"
30 #include "oops/fieldStreams.hpp"
31 #include "oops/objArrayOop.inline.hpp"
32 #include "oops/oop.inline.hpp"
33 #include "prims/jni.h"
34 #include "prims/jvm.h"
35 #include "prims/unsafe.hpp"
36 #include "runtime/atomic.hpp"
37 #include "runtime/globals.hpp"
38 #include "runtime/interfaceSupport.hpp"
39 #include "runtime/orderAccess.inline.hpp"
40 #include "runtime/reflection.hpp"
41 #include "runtime/thread.hpp"
42 #include "runtime/threadSMR.hpp"
43 #include "runtime/vm_version.hpp"
44 #include "services/threadService.hpp"
45 #include "trace/tracing.hpp"
46 #include "utilities/align.hpp"
47 #include "utilities/copy.hpp"
48 #include "utilities/dtrace.hpp"
49 #include "utilities/macros.hpp"
50 #if INCLUDE_ALL_GCS
51 #include "gc/g1/g1SATBCardTableModRefBS.hpp"
52 #endif // INCLUDE_ALL_GCS
53
54 /**
55 * Implementation of the jdk.internal.misc.Unsafe class
56 */
57
58
59 #define MAX_OBJECT_SIZE \
60 ( arrayOopDesc::header_size(T_DOUBLE) * HeapWordSize \
61 + ((julong)max_jint * sizeof(double)) )
62
1089 HOTSPOT_THREAD_PARK_BEGIN((uintptr_t) thread->parker(), (int) isAbsolute, time);
1090
1091 JavaThreadParkedState jtps(thread, time != 0);
1092 thread->parker()->park(isAbsolute != 0, time);
1093
1094 HOTSPOT_THREAD_PARK_END((uintptr_t) thread->parker());
1095
1096 if (event.should_commit()) {
1097 oop obj = thread->current_park_blocker();
1098 event.set_parkedClass((obj != NULL) ? obj->klass() : NULL);
1099 event.set_timeout(time);
1100 event.set_address((obj != NULL) ? (TYPE_ADDRESS) cast_from_oop<uintptr_t>(obj) : 0);
1101 event.commit();
1102 }
1103 } UNSAFE_END
1104
1105 UNSAFE_ENTRY(void, Unsafe_Unpark(JNIEnv *env, jobject unsafe, jobject jthread)) {
1106 Parker* p = NULL;
1107
1108 if (jthread != NULL) {
1109 ThreadsListHandle tlh;
1110 JavaThread* thr = NULL;
1111 oop java_thread = NULL;
1112 (void) tlh.cv_internal_thread_to_JavaThread(jthread, &thr, &java_thread);
1113 if (java_thread != NULL) {
1114 // This is a valid oop.
1115 jlong lp = java_lang_Thread::park_event(java_thread);
1116 if (lp != 0) {
1117 // This cast is OK even though the jlong might have been read
1118 // non-atomically on 32bit systems, since there, one word will
1119 // always be zero anyway and the value set is always the same
1120 p = (Parker*)addr_from_java(lp);
1121 } else {
1122 // Not cached in the java.lang.Thread oop yet (could be an
1123 // older version of library).
1124 if (thr != NULL) {
1125 // The JavaThread is alive.
1126 p = thr->parker();
1127 if (p != NULL) {
1128 // Cache the Parker in the java.lang.Thread oop for next time.
1129 java_lang_Thread::set_park_event(java_thread, addr_to_java(p));
1130 }
1131 }
1132 }
1133 }
1134 } // ThreadsListHandle is destroyed here.
1135
1136 if (p != NULL) {
1137 HOTSPOT_THREAD_UNPARK((uintptr_t) p);
1138 p->unpark();
1139 }
1140 } UNSAFE_END
1141
1142 UNSAFE_ENTRY(jint, Unsafe_GetLoadAverage0(JNIEnv *env, jobject unsafe, jdoubleArray loadavg, jint nelem)) {
1143 const int max_nelem = 3;
1144 double la[max_nelem];
1145 jint ret;
1146
1147 typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(loadavg));
1148 assert(a->is_typeArray(), "must be type array");
1149
1150 ret = os::loadavg(la, nelem);
1151 if (ret == -1) {
1152 return -1;
1153 }
1154
|