Skip to content

Commit

Permalink
8286789: Test forceEarlyReturn002.java timed out
Browse files Browse the repository at this point in the history
Reviewed-by: lmesnik, sspitsyn
  • Loading branch information
Alex Menkov committed Aug 30, 2023
1 parent 89d18ea commit c90cd2c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
6 changes: 0 additions & 6 deletions test/hotspot/jtreg/ProblemList-Virtual.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal003/TestDescription.java 8300
## Test fails because it expects to find vthreads in GetAllThreads
vmTestbase/nsk/jvmti/scenarios/allocation/AP11/ap11t001/TestDescription.java 8300712 generic-all

####
## NSK JDWP Tests failing with wrapper

vmTestbase/nsk/jdwp/ThreadReference/ForceEarlyReturn/forceEarlyReturn002/forceEarlyReturn002.java 8286789 generic-all


##########
## NSK JDB Tests failing with wrapper

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2023, 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
Expand Down Expand Up @@ -55,7 +55,7 @@
* When test thread has finish execution debugger suspends thread and call command for this thread, INVALID_THREAD
* error is expected, then, debugger resumes test thread and call command again, INVALID_THREAD error should
* be returned in reply.
* - debuggee starts test thread which executes infinite loop in native method, debugger calls command for
* - debuggee starts test thread which executes loop in native method, debugger calls command for
* this thread(without suspending) and expects THREAD_NOT_SUSPENDED error. Then, debugger suspends this thread
* and calls command again, OPAQUE_FRAME error is expected.
* - debugger creates ThreadStartEventRequest with suspend policy 'JDWP.SuspendPolicy.ALL' and forces debuggee start new thread.
Expand Down Expand Up @@ -227,6 +227,9 @@ public void doTest() {
// suspended thread in native, expect OPAQUE_FRAME error
sendCommand(threadID, value, true, JDWP.Error.OPAQUE_FRAME);

// signal native method to exit; the thread will be actually suspended
pipe.println(forceEarlyReturn002a.COMMAND_EXIT_THREAD_IN_NATIVE);

// create request for ThreadStart event
int requestID = createThreadStartEventRequest();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2023, 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
Expand Down Expand Up @@ -40,6 +40,8 @@ public class forceEarlyReturn002a extends AbstractJDWPDebuggee {

public final static String COMMAND_STOP_THREAD_IN_NATIVE = "stopInNative";

public final static String COMMAND_EXIT_THREAD_IN_NATIVE = "exitInNative";

public final static String COMMAND_START_NEW_THREAD = "startNewThread";

public boolean parseCommand(String command) {
Expand All @@ -49,6 +51,10 @@ public boolean parseCommand(String command) {
if (command.equals(COMMAND_STOP_THREAD_IN_NATIVE)) {
stopThreadInNative();

return true;
} else if (command.equals(COMMAND_EXIT_THREAD_IN_NATIVE)) {
exitThreadInNative();

return true;
} else if (command.equals(COMMAND_START_NEW_THREAD)) {
Thread thread = new Thread(new Runnable() {
Expand Down Expand Up @@ -87,6 +93,8 @@ public void run() {

private static native int nativeMethod(Object object);

private static native void exitThreadInNative();

public static void main(String args[]) {
new forceEarlyReturn002a().doTest(args);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2023, 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
Expand All @@ -23,23 +23,46 @@

#include "jni.h"

#if defined(_WIN32)
#include <windows.h>
#else
#include <unistd.h>
#endif

#include <atomic>

extern "C" {

static std::atomic<bool> wait_in_native(true);

static void delay(int seconds) {
#if defined(_WIN32)
Sleep(1000L * seconds);
#else
sleep(seconds);
#endif
}

JNIEXPORT jint JNICALL
Java_nsk_jdwp_ThreadReference_ForceEarlyReturn_forceEarlyReturn002_forceEarlyReturn002a_nativeMethod(JNIEnv *env, jobject classObject, jobject object)
{
static volatile int dummy_counter = 0;
// notify another thread that thread in native method
jclass klass = env->GetObjectClass(object);
jfieldID field = env->GetFieldID(klass, "threadInNative", "Z");
env->SetBooleanField(object, field, 1);

// execute infinite loop to be sure that thread in native method
while (dummy_counter == 0) {}
while (wait_in_native) {
delay(1);
}

// Should not reach here
return 0;
}

JNIEXPORT void JNICALL
Java_nsk_jdwp_ThreadReference_ForceEarlyReturn_forceEarlyReturn002_forceEarlyReturn002a_exitThreadInNative(JNIEnv *env, jobject classObject)
{
wait_in_native = false;
}

}

1 comment on commit c90cd2c

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.