Skip to content

Commit 2ba7eea

Browse files
authored
Merge pull request openjdk#33 from plummercj/fibers
Merge some commits I've accumulated in my personal fork.
2 parents 8dbd4e7 + a536251 commit 2ba7eea

File tree

8 files changed

+43
-88
lines changed

8 files changed

+43
-88
lines changed

src/jdk.jdwp.agent/share/native/libjdwp/ThreadReferenceImpl.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,25 @@ name(PacketInputStream *in, PacketOutputStream *out)
4949
return JNI_TRUE;
5050
}
5151

52-
WITH_LOCAL_REFS(env, 3) {
53-
/* Get the thread name */
52+
WITH_LOCAL_REFS(env, 1) {
53+
5454
jvmtiThreadInfo info;
5555
jvmtiError error;
5656

5757
(void)memset(&info, 0, sizeof(info));
58+
5859
error = JVMTI_FUNC_PTR(gdata->jvmti,GetThreadInfo)
59-
(gdata->jvmti, thread, &info);
60+
(gdata->jvmti, thread, &info);
6061

6162
if (error != JVMTI_ERROR_NONE) {
6263
outStream_setError(out, map2jdwpError(error));
6364
} else {
6465
(void)outStream_writeString(out, info.name);
6566
}
6667

67-
if ( info.name != NULL ) {
68+
if ( info.name != NULL )
6869
jvmtiDeallocate(info.name);
69-
}
70+
7071
} END_WITH_LOCAL_REFS(env);
7172

7273
return JNI_TRUE;
@@ -169,9 +170,11 @@ threadGroup(PacketInputStream *in, PacketOutputStream *out)
169170

170171
jvmtiThreadInfo info;
171172
jvmtiError error;
173+
172174
(void)memset(&info, 0, sizeof(info));
175+
173176
error = JVMTI_FUNC_PTR(gdata->jvmti,GetThreadInfo)
174-
(gdata->jvmti, thread, &info);
177+
(gdata->jvmti, thread, &info);
175178

176179
if (error != JVMTI_ERROR_NONE) {
177180
outStream_setError(out, map2jdwpError(error));

src/jdk.jdwp.agent/share/native/libjdwp/debugLoop.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ debugLoop_run(void)
8383
jboolean shouldListen;
8484
jdwpPacket p;
8585
jvmtiStartFunction func;
86-
JNIEnv *env = getEnv();
8786

8887
/* Initialize all statics */
8988
/* We may be starting a new connection after an error */
@@ -158,15 +157,8 @@ debugLoop_run(void)
158157
*/
159158
outStream_setError(&out, JDWP_ERROR(VM_DEAD));
160159
} else {
161-
/* Provide 64 localrefs by default. */
162-
/* vthread fixme: Now that this default set of localrefs is in place, we can remove a
163-
* bunch of WITH_LOCAL_REFS/END_WITH_LOCAL_REFS blocks. The only ones needed are
164-
* ones that could potentially go over 64, likes ones within loops. Note this only
165-
* refers to command handlers called from here, not all uses of WITH_LOCAL_REFS. */
166-
WITH_LOCAL_REFS(env, 64) {
167-
/* Call the command handler */
168-
replyToSender = func(&in, &out);
169-
} END_WITH_LOCAL_REFS(env);
160+
/* Call the command handler */
161+
replyToSender = func(&in, &out);
170162
}
171163

172164
/* Reply to the sender */

src/jdk.jdwp.agent/share/native/libjdwp/eventFilter.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -977,27 +977,6 @@ eventFilter_setStepFilter(HandlerNode *node, jint index,
977977
return JVMTI_ERROR_NONE;
978978
}
979979

980-
/*
981-
* Finds the step filter in a node, and sets the thread for that filter.
982-
* vthread fixme: not used. delete once we know for sure we'll never need it.
983-
*/
984-
void
985-
eventFilter_setStepFilterThread(HandlerNode *node, jthread thread)
986-
{
987-
JNIEnv *env = getEnv();
988-
Filter *filter = FILTERS_ARRAY(node);
989-
int i;
990-
for (i = 0; i < FILTER_COUNT(node); ++i, ++filter) {
991-
switch (filter->modifier) {
992-
case JDWP_REQUEST_MODIFIER(Step):
993-
tossGlobalRef(env, &(filter->u.Step.thread));
994-
saveGlobalRef(env, thread, &(filter->u.Step.thread));
995-
return;
996-
}
997-
}
998-
JDI_ASSERT(JNI_FALSE); /* We should have found a step filter, but didn't. */
999-
}
1000-
1001980
jvmtiError
1002981
eventFilter_setSourceNameMatchFilter(HandlerNode *node,
1003982
jint index,

src/jdk.jdwp.agent/share/native/libjdwp/eventFilter.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ jvmtiError eventFilter_setStepFilter(HandlerNode *node,
6666
jint index,
6767
jthread thread,
6868
jint size, jint depth);
69-
void eventFilter_setStepFilterThread(HandlerNode *node, jthread thread);
7069
jvmtiError eventFilter_setSourceNameMatchFilter(HandlerNode *node,
7170
jint index,
7271
char *sourceNamePattern);

src/jdk.jdwp.agent/share/native/libjdwp/eventHandler.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ filterAndAddVThread(JNIEnv *env, EventInfo *evinfo, EventIndex ei, jbyte eventSe
675675
* consumes the event.
676676
*/
677677
static void
678-
event_callback_helper(JNIEnv *env, EventInfo *evinfo)
678+
event_callback(JNIEnv *env, EventInfo *evinfo)
679679
{
680680
struct bag *eventBag;
681681
jbyte eventSessionID = currentSessionID; /* session could change */
@@ -743,8 +743,7 @@ event_callback_helper(JNIEnv *env, EventInfo *evinfo)
743743
* resources can be allocated. This must be done before
744744
* grabbing any locks.
745745
*/
746-
eventBag = threadControl_onEventHandlerEntry(
747-
eventSessionID, evinfo, currentException);
746+
eventBag = threadControl_onEventHandlerEntry(eventSessionID, evinfo, currentException);
748747
if ( eventBag == NULL ) {
749748
jboolean invoking;
750749
do {
@@ -829,16 +828,6 @@ event_callback_helper(JNIEnv *env, EventInfo *evinfo)
829828
}
830829
}
831830

832-
static void
833-
event_callback(JNIEnv *env, EventInfo *evinfo)
834-
{
835-
/* vthread fixme: There are a bunch of WITH_LOCAL_REFS that we can remove now that
836-
* we are doing one here. */
837-
WITH_LOCAL_REFS(env, 64) {
838-
event_callback_helper(env, evinfo);
839-
} END_WITH_LOCAL_REFS(env);
840-
}
841-
842831
/* Returns a local ref to the declaring class for an object. */
843832
static jclass
844833
getObjectClass(jobject object)

src/jdk.jdwp.agent/share/native/libjdwp/stepControl.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -86,14 +86,6 @@ disableStepping(jthread thread)
8686
}
8787
}
8888

89-
void stepControl_enableStepping(jthread thread) {
90-
enableStepping(thread);
91-
}
92-
93-
void stepControl_disableStepping(jthread thread) {
94-
disableStepping(thread);
95-
}
96-
9789
static jvmtiError
9890
getFrameLocation(jthread thread,
9991
jclass *pclazz, jmethodID *pmethod, jlocation *plocation)
@@ -358,13 +350,12 @@ handleFramePopEvent(JNIEnv *env, EventInfo *evinfo,
358350
* Resume stepping in the original frame.
359351
*/
360352
LOG_STEP(("handleFramePopEvent: starting singlestep, have methodEnter handler && depth==INTO && fromDepth >= afterPopDepth (%d>=%d)", fromDepth, afterPopDepth));
353+
enableStepping(thread);
354+
(void)eventHandler_free(step->methodEnterHandlerNode);
355+
step->methodEnterHandlerNode = NULL;
361356
} else {
362357
LOG_STEP(("handleFramePopEvent: starting singlestep, have methodEnter handler && depth==INTO && fromDepth < afterPopDepth (%d<%d)", fromDepth, afterPopDepth));
363-
JDI_ASSERT(fromDepth >= afterPopDepth);
364358
}
365-
enableStepping(thread);
366-
(void)eventHandler_free(step->methodEnterHandlerNode);
367-
step->methodEnterHandlerNode = NULL;
368359
}
369360
LOG_STEP(("handleFramePopEvent: finished"));
370361
}
@@ -613,7 +604,7 @@ stepControl_handleStep(JNIEnv *env, jthread thread,
613604
"installing event method enter handler");
614605
}
615606
}
616-
LOG_STEP(("stepControl_handleStep: NotifyFramePop, (fromDepth currentDepth)(%d %d) ",
607+
LOG_STEP(("stepControl_handleStep: NotifyFramePop (fromDepth=%d currentDepth=%d)",
617608
fromDepth, currentDepth));
618609

619610
error = JVMTI_FUNC_PTR(gdata->jvmti,NotifyFramePop)

src/jdk.jdwp.agent/share/native/libjdwp/stepControl.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ jvmtiError stepControl_endStep(jthread thread);
6565
void stepControl_clearRequest(jthread thread, StepRequest *step);
6666
void stepControl_resetRequest(jthread thread);
6767

68-
void stepControl_enableStepping(jthread thread);
69-
void stepControl_disableStepping(jthread thread);
70-
7168
void stepControl_lock(void);
7269
void stepControl_unlock(void);
7370

src/jdk.jdwp.agent/share/native/libjdwp/threadControl.c

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,8 @@ nonTlsSearch(JNIEnv *env, ThreadList *list, jthread thread)
235235
* All assume that the threadLock is held before calling.
236236
*/
237237

238-
239238
/*
240239
* Search for a thread on the list. If list==NULL, search all lists.
241-
* TODO: TLS cache is temporary diabled for all threads, not added for virtual threads yet
242-
* It cause intermittent failures because ThreadNode data is broken.
243-
* Need to enable setThreadLocalStorage in 2 places.
244240
*/
245241
static ThreadNode *
246242
findThread(ThreadList *list, jthread thread)
@@ -1285,10 +1281,14 @@ commonResumeList(JNIEnv *env)
12851281
/* count number of threads to hard resume */
12861282
(void) enumerateOverThreadList(env, &runningThreads, resumeCountHelper,
12871283
&reqCnt);
1284+
(void) enumerateOverThreadList(env, &runningVThreads, resumeCountHelper,
1285+
&reqCnt);
12881286
if (reqCnt == 0) {
12891287
/* nothing to hard resume so do just the accounting part */
12901288
(void) enumerateOverThreadList(env, &runningThreads, resumeCopyHelper,
12911289
NULL);
1290+
(void) enumerateOverThreadList(env, &runningVThreads, resumeCopyHelper,
1291+
NULL);
12921292
return JVMTI_ERROR_NONE;
12931293
}
12941294

@@ -1307,13 +1307,15 @@ commonResumeList(JNIEnv *env)
13071307
reqPtr = reqList;
13081308
(void) enumerateOverThreadList(env, &runningThreads, resumeCopyHelper,
13091309
&reqPtr);
1310+
(void) enumerateOverThreadList(env, &runningVThreads, resumeCopyHelper,
1311+
&reqPtr);
13101312

13111313
error = JVMTI_FUNC_PTR(gdata->jvmti,ResumeThreadList)
13121314
(gdata->jvmti, reqCnt, reqList, results);
13131315
for (i = 0; i < reqCnt; i++) {
13141316
ThreadNode *node;
13151317

1316-
node = findThread(&runningThreads, reqList[i]);
1318+
node = findRunningThread(reqList[i]);
13171319
if (node == NULL) {
13181320
EXIT_ERROR(AGENT_ERROR_INVALID_THREAD,"missing entry in running thread table");
13191321
}
@@ -1623,7 +1625,12 @@ threadControl_suspendAll(void)
16231625
}
16241626
}
16251627

1626-
/* Increment suspend count of each virtual thread that we are tracking. */
1628+
/*
1629+
* Increment suspendCount of each virtual thread that we are tracking. Note the
1630+
* compliment to this that happens during the resumeAll() is handled by
1631+
* commonResumeList(), so it's a bit orthogonal to how we handle incrementing
1632+
* the suspendCount.
1633+
*/
16271634
error = enumerateOverThreadList(env, &runningVThreads, incrementSupendCountHelper, NULL);
16281635
JDI_ASSERT(error == JVMTI_ERROR_NONE);
16291636
}
@@ -1681,16 +1688,6 @@ threadControl_suspendAll(void)
16811688
return error;
16821689
}
16831690

1684-
static jvmtiError
1685-
decrementSupendCountHelper(JNIEnv *env, ThreadNode *node, void *arg)
1686-
{
1687-
// Some vthreads might already have a suspendCount of 0. Just ignore them.
1688-
if (node->suspendCount > 0) {
1689-
node->suspendCount--;
1690-
}
1691-
return JVMTI_ERROR_NONE;
1692-
}
1693-
16941691
static jvmtiError
16951692
resumeHelper(JNIEnv *env, ThreadNode *node, void *ignored)
16961693
{
@@ -1727,10 +1724,6 @@ threadControl_resumeAll(void)
17271724
EXIT_ERROR(error, "cannot resume all virtual threads");
17281725
}
17291726
}
1730-
1731-
/* Decrement suspend count of each virtual thread that we are tracking. */
1732-
error = enumerateOverThreadList(env, &runningVThreads, decrementSupendCountHelper, NULL);
1733-
JDI_ASSERT(error == JVMTI_ERROR_NONE);
17341727
}
17351728

17361729
/*
@@ -2567,6 +2560,18 @@ threadControl_reset(void)
25672560
env = getEnv();
25682561
eventHandler_lock(); /* for proper lock order */
25692562
debugMonitorEnter(threadLock);
2563+
2564+
if (gdata->vthreadsSupported) {
2565+
if (suspendAllCount > 0) {
2566+
/* Tell JVMTI to resume all virtual threads. */
2567+
jvmtiError error = JVMTI_FUNC_PTR(gdata->jvmti,ResumeAllVirtualThreads)
2568+
(gdata->jvmti);
2569+
if (error != JVMTI_ERROR_NONE) {
2570+
EXIT_ERROR(error, "cannot resume all virtual threads");
2571+
}
2572+
}
2573+
}
2574+
25702575
(void)enumerateOverThreadList(env, &runningThreads, resetHelper, NULL);
25712576
(void)enumerateOverThreadList(env, &otherThreads, resetHelper, NULL);
25722577
(void)enumerateOverThreadList(env, &runningVThreads, resetHelper, NULL);

0 commit comments

Comments
 (0)