Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2025, 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 @@ -28,6 +28,7 @@
import java.util.List;
import java.util.Map;

import jdk.test.lib.thread.TestThreadFactory;
import nsk.share.jdi.Binder;
import nsk.share.jdi.Debugee;
import vm.mlvm.share.Env;
Expand Down Expand Up @@ -437,10 +438,22 @@ public static String getStackTraceStr(List<StackFrame> frames, boolean full)
for (StackFrame f : frames) {
Location l = f.location();

String sourcePath;
try {
sourcePath = l.sourcePath();
} catch (AbsentInformationException aie) {
// Test Thread Factory support has generated methods in MainWrapper class.
if (TestThreadFactory.isTestThreadFactorySet()) {
sourcePath = "unknown";
} else {
throw aie;
}
}

buf.append(String.format("#%-4d", frameNum))
.append(l.method())
.append("\n source: ")
.append(l.sourcePath())
.append(sourcePath)
.append(":")
.append(l.lineNumber())
.append("; bci=")
Expand Down
25 changes: 22 additions & 3 deletions test/lib/jdk/test/lib/thread/TestThreadFactory.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, 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 @@ -32,8 +32,27 @@

public class TestThreadFactory {

private static ThreadFactory threadFactory = "Virtual".equals(System.getProperty("test.thread.factory"))
? virtualThreadFactory() : platformThreadFactory();
public enum TestThreadFactoryType {
NONE, VIRTUAL
}

private final static TestThreadFactoryType testThreadFactoryType =
"Virtual".equals(System.getProperty("test.thread.factory"))
? TestThreadFactoryType.VIRTUAL
: TestThreadFactoryType.NONE;

private final static ThreadFactory threadFactory =
testThreadFactoryType == TestThreadFactoryType.VIRTUAL
? virtualThreadFactory()
: platformThreadFactory();

public static TestThreadFactoryType testThreadFactoryType() {
return testThreadFactoryType;
}

public static boolean isTestThreadFactorySet() {
return !testThreadFactoryType.equals(TestThreadFactoryType.NONE);
}

public static Thread newThread(Runnable task) {
return threadFactory.newThread(task);
Expand Down