57301
|
1 |
diff -r 7d5a4a48e876 src/java.base/share/classes/java/lang/System.java
|
|
2 |
--- a/src/java.base/share/classes/java/lang/System.java Wed Mar 27 14:40:36 2019 -0700
|
|
3 |
+++ b/src/java.base/share/classes/java/lang/System.java Wed Apr 03 09:46:50 2019 +0100
|
|
4 |
@@ -2172,6 +2172,12 @@
|
|
5 |
public void blockedOn(Interruptible b) {
|
|
6 |
Thread.blockedOn(b);
|
|
7 |
}
|
|
8 |
+ public void setNativeTid(long tid) {
|
|
9 |
+ Thread.setNativeTid(tid);
|
|
10 |
+ }
|
|
11 |
+ public long nativeTid() {
|
|
12 |
+ return Thread.nativeTid();
|
|
13 |
+ }
|
|
14 |
public void registerShutdownHook(int slot, boolean registerShutdownInProgress, Runnable hook) {
|
|
15 |
Shutdown.add(slot, registerShutdownInProgress, hook);
|
|
16 |
}
|
|
17 |
diff -r 7d5a4a48e876 src/java.base/share/classes/java/lang/Thread.java
|
|
18 |
--- a/src/java.base/share/classes/java/lang/Thread.java Wed Mar 27 14:40:36 2019 -0700
|
|
19 |
+++ b/src/java.base/share/classes/java/lang/Thread.java Wed Apr 03 09:46:50 2019 +0100
|
|
20 |
@@ -241,6 +241,18 @@
|
|
21 |
}
|
|
22 |
|
|
23 |
/**
|
|
24 |
+ * Native thread id, cached here for use for threads are blocked in I/O
|
|
25 |
+ * operations.
|
|
26 |
+ */
|
|
27 |
+ private long nativeTid;
|
|
28 |
+ static void setNativeTid(long tid) {
|
|
29 |
+ Thread.currentThread().nativeTid = tid;
|
|
30 |
+ }
|
|
31 |
+ static long nativeTid() {
|
|
32 |
+ return Thread.currentThread().nativeTid;
|
|
33 |
+ }
|
|
34 |
+
|
|
35 |
+ /**
|
|
36 |
* The minimum priority that a thread can have.
|
|
37 |
*/
|
|
38 |
public static final int MIN_PRIORITY = 1;
|
|
39 |
diff -r 7d5a4a48e876 src/java.base/share/classes/jdk/internal/access/JavaLangAccess.java
|
|
40 |
--- a/src/java.base/share/classes/jdk/internal/access/JavaLangAccess.java Wed Mar 27 14:40:36 2019 -0700
|
|
41 |
+++ b/src/java.base/share/classes/jdk/internal/access/JavaLangAccess.java Wed Apr 03 09:46:50 2019 +0100
|
|
42 |
@@ -107,6 +107,16 @@
|
|
43 |
void blockedOn(Interruptible b);
|
|
44 |
|
|
45 |
/**
|
|
46 |
+ * Set the current thread's native ID
|
|
47 |
+ */
|
|
48 |
+ void setNativeTid(long tid);
|
|
49 |
+
|
|
50 |
+ /**
|
|
51 |
+ * Returns the current thread's native ID
|
|
52 |
+ */
|
|
53 |
+ long nativeTid();
|
|
54 |
+
|
|
55 |
+ /**
|
|
56 |
* Registers a shutdown hook.
|
|
57 |
*
|
|
58 |
* It is expected that this method with registerShutdownInProgress=true
|
|
59 |
diff -r 7d5a4a48e876 src/java.base/unix/classes/sun/nio/ch/NativeThread.java
|
|
60 |
--- a/src/java.base/unix/classes/sun/nio/ch/NativeThread.java Wed Mar 27 14:40:36 2019 -0700
|
|
61 |
+++ b/src/java.base/unix/classes/sun/nio/ch/NativeThread.java Wed Apr 03 09:46:50 2019 +0100
|
|
62 |
@@ -25,7 +25,6 @@
|
|
63 |
|
|
64 |
package sun.nio.ch;
|
|
65 |
|
|
66 |
-
|
|
67 |
// Signalling operations on native threads
|
|
68 |
//
|
|
69 |
// On some operating systems (e.g., Linux), closing a channel while another
|
|
70 |
@@ -33,23 +32,35 @@
|
|
71 |
// thread to be released. This class provides access to the native threads
|
|
72 |
// upon which Java threads are built, and defines a simple signal mechanism
|
|
73 |
// that can be used to release a native thread from a blocking I/O operation.
|
|
74 |
-// On systems that do not require this type of signalling, the current() method
|
|
75 |
-// always returns -1 and the signal(long) method has no effect.
|
|
76 |
|
|
77 |
+import jdk.internal.access.JavaLangAccess;
|
|
78 |
+import jdk.internal.access.SharedSecrets;
|
|
79 |
|
|
80 |
public class NativeThread {
|
|
81 |
+ private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
|
|
82 |
|
|
83 |
- // Returns an opaque token representing the native thread underlying the
|
|
84 |
- // invoking Java thread. On systems that do not require signalling, this
|
|
85 |
- // method always returns -1.
|
|
86 |
- //
|
|
87 |
- public static native long current();
|
|
88 |
+ /**
|
|
89 |
+ * Returns the current thread's ID.
|
|
90 |
+ */
|
|
91 |
+ public static long current() {
|
|
92 |
+ long tid = JLA.nativeTid();
|
|
93 |
+ if (tid == 0) {
|
|
94 |
+ tid = current0();
|
|
95 |
+ JLA.setNativeTid(tid);
|
|
96 |
+ }
|
|
97 |
+ return tid;
|
|
98 |
+ }
|
|
99 |
|
|
100 |
- // Signals the given native thread so as to release it from a blocking I/O
|
|
101 |
- // operation. On systems that do not require signalling, this method has
|
|
102 |
- // no effect.
|
|
103 |
- //
|
|
104 |
- public static native void signal(long nt);
|
|
105 |
+ /**
|
|
106 |
+ * Signals the given thread.
|
|
107 |
+ */
|
|
108 |
+ public static void signal(long tid) {
|
|
109 |
+ signal0(tid);
|
|
110 |
+ }
|
|
111 |
+
|
|
112 |
+ private static native long current0();
|
|
113 |
+
|
|
114 |
+ private static native void signal0(long tid);
|
|
115 |
|
|
116 |
private static native void init();
|
|
117 |
|
|
118 |
diff -r 7d5a4a48e876 src/java.base/unix/native/libnio/ch/NativeThread.c
|
|
119 |
--- a/src/java.base/unix/native/libnio/ch/NativeThread.c Wed Mar 27 14:40:36 2019 -0700
|
|
120 |
+++ b/src/java.base/unix/native/libnio/ch/NativeThread.c Wed Apr 03 09:46:50 2019 +0100
|
|
121 |
@@ -77,7 +77,7 @@
|
|
122 |
}
|
|
123 |
|
|
124 |
JNIEXPORT jlong JNICALL
|
|
125 |
-Java_sun_nio_ch_NativeThread_current(JNIEnv *env, jclass cl)
|
|
126 |
+Java_sun_nio_ch_NativeThread_current0(JNIEnv *env, jclass cl)
|
|
127 |
{
|
|
128 |
#ifdef __solaris__
|
|
129 |
return (jlong)thr_self();
|
|
130 |
@@ -87,7 +87,7 @@
|
|
131 |
}
|
|
132 |
|
|
133 |
JNIEXPORT void JNICALL
|
|
134 |
-Java_sun_nio_ch_NativeThread_signal(JNIEnv *env, jclass cl, jlong thread)
|
|
135 |
+Java_sun_nio_ch_NativeThread_signal0(JNIEnv *env, jclass cl, jlong thread)
|
|
136 |
{
|
|
137 |
int ret;
|
|
138 |
#ifdef __solaris__
|