Skip to content
Permalink
Browse files
Merge pull request #33 from plummercj/fibers
Merge some commits I've accumulated in my personal fork.
  • Loading branch information
plummercj committed Mar 5, 2021
2 parents 8dbd4e7 + a536251 commit 2ba7eea525f52877f66b4a6bfd1a2b2815bd7ef7
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 88 deletions.
@@ -49,24 +49,25 @@ name(PacketInputStream *in, PacketOutputStream *out)
return JNI_TRUE;
}

WITH_LOCAL_REFS(env, 3) {
/* Get the thread name */
WITH_LOCAL_REFS(env, 1) {

jvmtiThreadInfo info;
jvmtiError error;

(void)memset(&info, 0, sizeof(info));

error = JVMTI_FUNC_PTR(gdata->jvmti,GetThreadInfo)
(gdata->jvmti, thread, &info);
(gdata->jvmti, thread, &info);

if (error != JVMTI_ERROR_NONE) {
outStream_setError(out, map2jdwpError(error));
} else {
(void)outStream_writeString(out, info.name);
}

if ( info.name != NULL ) {
if ( info.name != NULL )
jvmtiDeallocate(info.name);
}

} END_WITH_LOCAL_REFS(env);

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

jvmtiThreadInfo info;
jvmtiError error;

(void)memset(&info, 0, sizeof(info));

error = JVMTI_FUNC_PTR(gdata->jvmti,GetThreadInfo)
(gdata->jvmti, thread, &info);
(gdata->jvmti, thread, &info);

if (error != JVMTI_ERROR_NONE) {
outStream_setError(out, map2jdwpError(error));
@@ -83,7 +83,6 @@ debugLoop_run(void)
jboolean shouldListen;
jdwpPacket p;
jvmtiStartFunction func;
JNIEnv *env = getEnv();

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

/* Reply to the sender */
@@ -977,27 +977,6 @@ eventFilter_setStepFilter(HandlerNode *node, jint index,
return JVMTI_ERROR_NONE;
}

/*
* Finds the step filter in a node, and sets the thread for that filter.
* vthread fixme: not used. delete once we know for sure we'll never need it.
*/
void
eventFilter_setStepFilterThread(HandlerNode *node, jthread thread)
{
JNIEnv *env = getEnv();
Filter *filter = FILTERS_ARRAY(node);
int i;
for (i = 0; i < FILTER_COUNT(node); ++i, ++filter) {
switch (filter->modifier) {
case JDWP_REQUEST_MODIFIER(Step):
tossGlobalRef(env, &(filter->u.Step.thread));
saveGlobalRef(env, thread, &(filter->u.Step.thread));
return;
}
}
JDI_ASSERT(JNI_FALSE); /* We should have found a step filter, but didn't. */
}

jvmtiError
eventFilter_setSourceNameMatchFilter(HandlerNode *node,
jint index,
@@ -66,7 +66,6 @@ jvmtiError eventFilter_setStepFilter(HandlerNode *node,
jint index,
jthread thread,
jint size, jint depth);
void eventFilter_setStepFilterThread(HandlerNode *node, jthread thread);
jvmtiError eventFilter_setSourceNameMatchFilter(HandlerNode *node,
jint index,
char *sourceNamePattern);
@@ -675,7 +675,7 @@ filterAndAddVThread(JNIEnv *env, EventInfo *evinfo, EventIndex ei, jbyte eventSe
* consumes the event.
*/
static void
event_callback_helper(JNIEnv *env, EventInfo *evinfo)
event_callback(JNIEnv *env, EventInfo *evinfo)
{
struct bag *eventBag;
jbyte eventSessionID = currentSessionID; /* session could change */
@@ -743,8 +743,7 @@ event_callback_helper(JNIEnv *env, EventInfo *evinfo)
* resources can be allocated. This must be done before
* grabbing any locks.
*/
eventBag = threadControl_onEventHandlerEntry(
eventSessionID, evinfo, currentException);
eventBag = threadControl_onEventHandlerEntry(eventSessionID, evinfo, currentException);
if ( eventBag == NULL ) {
jboolean invoking;
do {
@@ -829,16 +828,6 @@ event_callback_helper(JNIEnv *env, EventInfo *evinfo)
}
}

static void
event_callback(JNIEnv *env, EventInfo *evinfo)
{
/* vthread fixme: There are a bunch of WITH_LOCAL_REFS that we can remove now that
* we are doing one here. */
WITH_LOCAL_REFS(env, 64) {
event_callback_helper(env, evinfo);
} END_WITH_LOCAL_REFS(env);
}

/* Returns a local ref to the declaring class for an object. */
static jclass
getObjectClass(jobject object)
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -86,14 +86,6 @@ disableStepping(jthread thread)
}
}

void stepControl_enableStepping(jthread thread) {
enableStepping(thread);
}

void stepControl_disableStepping(jthread thread) {
disableStepping(thread);
}

static jvmtiError
getFrameLocation(jthread thread,
jclass *pclazz, jmethodID *pmethod, jlocation *plocation)
@@ -358,13 +350,12 @@ handleFramePopEvent(JNIEnv *env, EventInfo *evinfo,
* Resume stepping in the original frame.
*/
LOG_STEP(("handleFramePopEvent: starting singlestep, have methodEnter handler && depth==INTO && fromDepth >= afterPopDepth (%d>=%d)", fromDepth, afterPopDepth));
enableStepping(thread);
(void)eventHandler_free(step->methodEnterHandlerNode);
step->methodEnterHandlerNode = NULL;
} else {
LOG_STEP(("handleFramePopEvent: starting singlestep, have methodEnter handler && depth==INTO && fromDepth < afterPopDepth (%d<%d)", fromDepth, afterPopDepth));
JDI_ASSERT(fromDepth >= afterPopDepth);
}
enableStepping(thread);
(void)eventHandler_free(step->methodEnterHandlerNode);
step->methodEnterHandlerNode = NULL;
}
LOG_STEP(("handleFramePopEvent: finished"));
}
@@ -613,7 +604,7 @@ stepControl_handleStep(JNIEnv *env, jthread thread,
"installing event method enter handler");
}
}
LOG_STEP(("stepControl_handleStep: NotifyFramePop, (fromDepth currentDepth)(%d %d) ",
LOG_STEP(("stepControl_handleStep: NotifyFramePop (fromDepth=%d currentDepth=%d)",
fromDepth, currentDepth));

error = JVMTI_FUNC_PTR(gdata->jvmti,NotifyFramePop)
@@ -65,9 +65,6 @@ jvmtiError stepControl_endStep(jthread thread);
void stepControl_clearRequest(jthread thread, StepRequest *step);
void stepControl_resetRequest(jthread thread);

void stepControl_enableStepping(jthread thread);
void stepControl_disableStepping(jthread thread);

void stepControl_lock(void);
void stepControl_unlock(void);

@@ -235,12 +235,8 @@ nonTlsSearch(JNIEnv *env, ThreadList *list, jthread thread)
* All assume that the threadLock is held before calling.
*/


/*
* Search for a thread on the list. If list==NULL, search all lists.
* TODO: TLS cache is temporary diabled for all threads, not added for virtual threads yet
* It cause intermittent failures because ThreadNode data is broken.
* Need to enable setThreadLocalStorage in 2 places.
*/
static ThreadNode *
findThread(ThreadList *list, jthread thread)
@@ -1285,10 +1281,14 @@ commonResumeList(JNIEnv *env)
/* count number of threads to hard resume */
(void) enumerateOverThreadList(env, &runningThreads, resumeCountHelper,
&reqCnt);
(void) enumerateOverThreadList(env, &runningVThreads, resumeCountHelper,
&reqCnt);
if (reqCnt == 0) {
/* nothing to hard resume so do just the accounting part */
(void) enumerateOverThreadList(env, &runningThreads, resumeCopyHelper,
NULL);
(void) enumerateOverThreadList(env, &runningVThreads, resumeCopyHelper,
NULL);
return JVMTI_ERROR_NONE;
}

@@ -1307,13 +1307,15 @@ commonResumeList(JNIEnv *env)
reqPtr = reqList;
(void) enumerateOverThreadList(env, &runningThreads, resumeCopyHelper,
&reqPtr);
(void) enumerateOverThreadList(env, &runningVThreads, resumeCopyHelper,
&reqPtr);

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

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

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

static jvmtiError
decrementSupendCountHelper(JNIEnv *env, ThreadNode *node, void *arg)
{
// Some vthreads might already have a suspendCount of 0. Just ignore them.
if (node->suspendCount > 0) {
node->suspendCount--;
}
return JVMTI_ERROR_NONE;
}

static jvmtiError
resumeHelper(JNIEnv *env, ThreadNode *node, void *ignored)
{
@@ -1727,10 +1724,6 @@ threadControl_resumeAll(void)
EXIT_ERROR(error, "cannot resume all virtual threads");
}
}

/* Decrement suspend count of each virtual thread that we are tracking. */
error = enumerateOverThreadList(env, &runningVThreads, decrementSupendCountHelper, NULL);
JDI_ASSERT(error == JVMTI_ERROR_NONE);
}

/*
@@ -2567,6 +2560,18 @@ threadControl_reset(void)
env = getEnv();
eventHandler_lock(); /* for proper lock order */
debugMonitorEnter(threadLock);

if (gdata->vthreadsSupported) {
if (suspendAllCount > 0) {
/* Tell JVMTI to resume all virtual threads. */
jvmtiError error = JVMTI_FUNC_PTR(gdata->jvmti,ResumeAllVirtualThreads)
(gdata->jvmti);
if (error != JVMTI_ERROR_NONE) {
EXIT_ERROR(error, "cannot resume all virtual threads");
}
}
}

(void)enumerateOverThreadList(env, &runningThreads, resetHelper, NULL);
(void)enumerateOverThreadList(env, &otherThreads, resetHelper, NULL);
(void)enumerateOverThreadList(env, &runningVThreads, resetHelper, NULL);

0 comments on commit 2ba7eea

Please sign in to comment.