Skip to content
Draft
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ jobs:

steps:
- name: 'Check out repository'
uses: actions/checkout@v4
uses: actions/checkout@v6
with:
fetch-depth: 1

- name: 'Set up Java Development Kit'
uses: oracle-actions/setup-java@v1
- name: 'Set up Java Development Kits'
uses: actions/setup-java@v5
with:
website: oracle.com
release: 21
distribution: 'oracle'
java-version: |
25
21

- name: 'Build JTReg'
shell: bash
Expand All @@ -43,13 +45,14 @@ jobs:
MAKE_ARGS: test
HEADLESS: 1
run: |
export JDK25HOME=$JAVA_HOME_25_X64
bash make/build.sh --skip-download

freebsd-x64:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- name: Run tests in FreeBSD
id: test
uses: vmactions/freebsd-vm@v1
Expand Down
2 changes: 1 addition & 1 deletion doc/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ bash build/make.sh $(pwd)/build/test/ControlTest.ok
```

Some tests depend on specific versions of JDK being available, specified
by the following variables: `JDK8HOME`, `JDK9HOME`, `JDK14HOME`, `JDK18HOME`.
by the following variables: `JDK8HOME`, `JDK9HOME`, `JDK14HOME`, `JDK18HOME`, `JDK25HOME`.
A test that requires any of these version of JDK will be skipped if the
variable is not set.

Expand Down
6 changes: 6 additions & 0 deletions make/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ endif
ifndef JDK18HOME
@echo "Warning: JDK18HOME not set; some tests may not have been executed"
endif
ifndef JDK25HOME
@echo "Warning: JDK25HOME not set; some tests may not have been executed"
endif
ifdef HEADLESS
@echo "Warning: HEADLESS is set; some tests may not have been executed"
endif
Expand Down Expand Up @@ -109,6 +112,9 @@ ifdef JDK14HOME
endif
ifdef JDK18HOME
@echo "JDK18HOME = $(JDK18HOME)"
endif
ifdef JDK25HOME
@echo "JDK25HOME = $(JDK25HOME)"
endif
@echo "JDKHOME = $(JDKHOME)"
@echo "JAVATEST_HOME = $(JAVATEST_HOME)"
Expand Down
85 changes: 81 additions & 4 deletions src/share/classes/com/sun/javatest/regtest/agent/MainWrapper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2026, 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 @@ -27,8 +27,13 @@

import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* This class is the wrapper for all main/othervm tests.
Expand Down Expand Up @@ -107,6 +112,49 @@ private static void handleTestException(Throwable e) {
}
}

// Similar to jdk.internal.misc.MethodFinder#findMainMethod
private static Method findMainMethod(Class<?> cls) throws NoSuchMethodException {
List<Method> methods = Stream.of(cls.getDeclaredMethods())
.filter(m -> "main".equals(m.getName()))
.collect(Collectors.toList()); // no .toList() with --release 8

// JLA.findMethod(cls, true, "main", String[].class);
Method mainMethod = methods.stream()
.filter(method -> Modifier.isPublic(method.getModifiers()))
.filter(method -> method.getParameterCount() == 1)
.filter(method -> method.getParameterTypes()[0] == String[].class)
.findAny()
.orElse(null);

if (mainMethod == null) {
// JLA.findMethod(cls, false, "main", String[].class);
mainMethod = methods.stream()
.filter(method -> method.getParameterCount() == 1)
.filter(method -> method.getParameterTypes()[0] == String[].class)
.findAny()
.orElse(null);
}

if (mainMethod == null || !isValidMainMethod(mainMethod)) {
// JLA.findMethod(cls, false, "main");
mainMethod = methods.stream()
.filter(method -> method.getParameterCount() == 0)
.findAny()
.orElse(null);
}

if (mainMethod != null && isValidMainMethod(mainMethod)) {
return mainMethod;
}
throw new NoSuchMethodException("main() nor main(String[])");
}

private static boolean isValidMainMethod(Method mainMethodCandidate) {
return mainMethodCandidate.getReturnType() == void.class &&
!Modifier.isPrivate(mainMethodCandidate.getModifiers());

}

static class MainTask implements Runnable {
MainTask(String moduleName, String className, String[] args) {
this.moduleName = moduleName;
Expand All @@ -133,9 +181,37 @@ public void run() {
}

// RUN JAVA PROGRAM
Class<?> c = Class.forName(className, false, cl);
Method mainMethod = c.getMethod("main", String[].class);
mainMethod.invoke(null, (Object) args);
Class<?> mainClass = Class.forName(className, false, cl);
Method mainMethod = findMainMethod(mainClass);

boolean isStatic = Modifier.isStatic(mainMethod.getModifiers());
Object instance = null;

// Similar to sun.launcher.LauncherHelper#checkAndLoadMain
if (!isStatic) {
Constructor<?> constructor;
constructor = mainClass.getDeclaredConstructor();
try {
constructor.setAccessible(true);
instance = constructor.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace(System.err);
System.err.println();
System.err.println("JavaTest Message: cannot instantiate class " + className);
System.err.println();
AStatus.error(MAIN_CANT_INIT_TEST + e).exit();
}
}

// Similar to sun.launcher.LauncherHelper#executeMainClass
mainMethod.setAccessible(true);
Object receiver = isStatic ? null : instance;

if (mainMethod.getParameterCount() == 0) {
mainMethod.invoke(receiver);
} else {
mainMethod.invoke(receiver, (Object) args);
}

} catch (InvocationTargetException e) {
Throwable throwable = e.getTargetException();
Expand Down Expand Up @@ -228,6 +304,7 @@ public void uncaughtException(Thread t, Throwable e) {
MAIN_CANT_READ_ARGS = "JavaTest Error: Can't read main args file.",
MAIN_THREAD_INTR = "Thread interrupted: ",
MAIN_THREW_EXCEPT = "`main' threw exception: ",
MAIN_CANT_INIT_TEST = "Can't create an instance of: ",
MAIN_CANT_LOAD_TEST = "Can't load test: ",
MAIN_CANT_FIND_MAIN = "Can't find `main' method",
MAIN_SKIPPED = "Skipped: ";
Expand Down
30 changes: 30 additions & 0 deletions test/compactsourcefile/Compact.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2026, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
* @test
* @run main Compact
*/
void main() {
IO.println("Compact");
}
30 changes: 30 additions & 0 deletions test/compactsourcefile/CompactArgs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2026, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
* @test
* @run main CompactArgs
*/
void main(String... args) {
IO.println("CompactArgs");
}
43 changes: 43 additions & 0 deletions test/compactsourcefile/CompactSourceFileTest.gmk
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# Copyright (c) 2026, 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
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#

#----------------------------------------------------------------------

ifdef JDK25HOME

$(BUILDTESTDIR)/CompactSourceFile.ok: \
$(JTREG_IMAGEDIR)/lib/jtreg.jar \
$(JTREG_IMAGEDIR)/bin/jtreg
$(RM) $(@:%.ok=%) ; $(MKDIR) $(@:%.ok=%)
JTREG_JAVA=$(JDKJAVA) $(JTREG_IMAGEDIR)/bin/jtreg $(JTREG_OPTS) \
-w:$(@:%.ok=%)/work -r:$(@:%.ok=%)/report \
-jdk:$(JDK25HOME) \
$(TESTDIR)/compactsourcefile \
> $(@:%.ok=%/jt.log) 2>&1
echo "test passed at `date`" > $@

TESTS.jtreg += $(BUILDTESTDIR)/CompactSourceFile.ok

endif
30 changes: 30 additions & 0 deletions test/compactsourcefile/CompactStatic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2026, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
* @test
* @run main CompactStatic
*/
static void main() {
IO.println("CompactStatic");
}
30 changes: 30 additions & 0 deletions test/compactsourcefile/CompactStaticArgs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2026, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
* @test
* @run main CompactStaticArgs
*/
static void main(String... args) {
IO.println("CompactStaticArgs");
}
Empty file.