Skip to content

Commit

Permalink
Merge branch 'openjdk:master' into goetz_backport_8256660
Browse files Browse the repository at this point in the history
  • Loading branch information
GoeLin authored Apr 9, 2024
2 parents 0b03224 + aa16bfe commit f39e847
Show file tree
Hide file tree
Showing 20 changed files with 1,232 additions and 694 deletions.
23 changes: 21 additions & 2 deletions src/hotspot/os/aix/os_aix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1313,10 +1313,9 @@ bool os::dll_address_to_library_name(address addr, char* buf,

// Loads .dll/.so and in case of error it checks if .dll/.so was built
// for the same architecture as Hotspot is running on.
void *os::dll_load(const char *filename, char *ebuf, int ebuflen) {
static void* dll_load_library(const char *filename, char *ebuf, int ebuflen) {

log_info(os)("attempting shared library load of %s", filename);

if (ebuf && ebuflen > 0) {
ebuf[0] = '\0';
ebuf[ebuflen - 1] = '\0';
Expand Down Expand Up @@ -1359,6 +1358,26 @@ void* os::dll_lookup(void* handle, const char* name) {
void* os::get_default_process_handle() {
return (void*)::dlopen(NULL, RTLD_LAZY);
}
// Load library named <filename>
// If filename matches <name>.so, and loading fails, repeat with <name>.a.
void *os::dll_load(const char *filename, char *ebuf, int ebuflen) {
void* result = nullptr;
char* const file_path = strdup(filename);
char* const pointer_to_dot = strrchr(file_path, '.');
const char old_extension[] = ".so";
const char new_extension[] = ".a";
STATIC_ASSERT(sizeof(old_extension) >= sizeof(new_extension));
// First try to load the existing file.
result = dll_load_library(filename, ebuf, ebuflen);
// If the load fails,we try to reload by changing the extension to .a for .so files only.
// Shared object in .so format dont have braces, hence they get removed for archives with members.
if (result == nullptr && pointer_to_dot != nullptr && strcmp(pointer_to_dot, old_extension) == 0) {
snprintf(pointer_to_dot, sizeof(old_extension), "%s", new_extension);
result = dll_load_library(file_path, ebuf, ebuflen);
}
FREE_C_HEAP_ARRAY(char, file_path);
return result;
}

void os::print_dll_info(outputStream *st) {
st->print_cr("Dynamic libraries:");
Expand Down
9 changes: 4 additions & 5 deletions src/java.base/share/classes/java/util/Formatter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 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 @@ -4526,10 +4526,9 @@ private StringBuilder localizedMagnitude(StringBuilder sb,
}

// apply zero padding
if (width != -1 && f.contains(Flags.ZERO_PAD)) {
for (int k = sb.length(); k < width; k++) {
sb.insert(begin, zero);
}
if (width > sb.length() && f.contains(Flags.ZERO_PAD)) {
String zeros = String.valueOf(zero).repeat(width - sb.length());
sb.insert(begin, zeros);
}

return sb;
Expand Down
21 changes: 14 additions & 7 deletions src/java.base/unix/native/libjli/java_md_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,27 @@ char* findLastPathComponent(char *buffer, const char *comp) {
/*
* Removes the trailing file name and any intermediate platform
* directories, if any, and its enclosing directory.
* Second parameter is a hint about the type of a file. JNI_TRUE is for
* shared libraries and JNI_FALSE is for executables.
* Ex: if a buffer contains "/foo/bin/javac" or "/foo/bin/x64/javac", the
* truncated resulting buffer will contain "/foo".
*/
jboolean
TruncatePath(char *buf)
TruncatePath(char *buf, jboolean pathisdll)
{
// try bin directory, maybe an executable
char *p = findLastPathComponent(buf, "/bin/");
/*
* If the file is a library, try lib directory first and then bin
* directory.
* If the file is an executable, try bin directory first and then lib
* directory.
*/

char *p = findLastPathComponent(buf, pathisdll ? "/lib/" : "/bin/");
if (p != NULL) {
*p = '\0';
return JNI_TRUE;
}
// try lib directory, maybe a library
p = findLastPathComponent(buf, "/lib/");
p = findLastPathComponent(buf, pathisdll ? "/bin/" : "/lib/");
if (p != NULL) {
*p = '\0';
return JNI_TRUE;
Expand All @@ -79,7 +86,7 @@ GetApplicationHome(char *buf, jint bufsize)
} else {
return JNI_FALSE;
}
return TruncatePath(buf);
return TruncatePath(buf, JNI_FALSE);
}

/*
Expand All @@ -94,7 +101,7 @@ GetApplicationHomeFromDll(char *buf, jint bufsize)
if (dladdr((void*)&GetApplicationHomeFromDll, &info) != 0) {
char *path = realpath(info.dli_fname, buf);
if (path == buf) {
return TruncatePath(buf);
return TruncatePath(buf, JNI_TRUE);
}
}
return JNI_FALSE;
Expand Down
81 changes: 81 additions & 0 deletions test/hotspot/jtreg/gtest/GTestResultParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (c) 2019, 2024, 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.
*/

import javax.xml.XMLConstants;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import java.io.IOException;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class GTestResultParser {
private final List<String> _failedTests;

public GTestResultParser(Path file) {
List<String> failedTests = new ArrayList<>();
try (Reader r = Files.newBufferedReader(file)) {
XMLInputFactory factory = XMLInputFactory.newInstance();
factory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
factory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
XMLStreamReader xmlReader = factory.createXMLStreamReader(r);
String testSuite = null;
String testCase = null;
while (xmlReader.hasNext()) {
int code = xmlReader.next();
if (code == XMLStreamConstants.START_ELEMENT) {
switch (xmlReader.getLocalName()) {
case "testsuite":
testSuite = xmlReader.getAttributeValue("", "name");
break;
case "testcase":
testCase = xmlReader.getAttributeValue("", "name");
break;
case "failure":
String failedStr = testSuite + "::" + testCase;
if (!failedTests.contains(failedStr)) {
failedTests.add(failedStr);
}
break;
default:
// ignore
}
}
}
} catch (XMLStreamException e) {
throw new IllegalArgumentException("can't open parse xml " + file, e);
} catch (IOException e) {
throw new IllegalArgumentException("can't open result file " + file, e);
}
_failedTests = Collections.unmodifiableList(failedTests);
}

public List<String> failedTests() {
return _failedTests;
}
}
56 changes: 37 additions & 19 deletions test/hotspot/jtreg/gtest/GTestWrapper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2019, 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 @@ -25,24 +25,22 @@
* @summary a jtreg wrapper for gtest tests
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.xml
* @requires vm.flagless
* @run main/native GTestWrapper
*/

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
import java.util.stream.Collectors;

import java.io.File;
import java.nio.file.Paths;
import java.nio.file.Path;

import jdk.test.lib.Platform;
import jdk.test.lib.Utils;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class GTestWrapper {
public static void main(String[] args) throws Throwable {
Expand Down Expand Up @@ -77,13 +75,33 @@ public static void main(String[] args) throws Throwable {
env.put(pathVar, path + File.pathSeparator + ldLibraryPath);
}

pb.command(new String[] {
execPath.toString(),
"-jdk",
System.getProperty("test.jdk"),
"--gtest_catch_exceptions=0"
});
ProcessTools.executeCommand(pb).shouldHaveExitValue(0);
Path resultFile = Paths.get("test_result.xml");
pb.command(execPath.toAbsolutePath().toString(),
"-jdk", Utils.TEST_JDK,
"--gtest_output=xml:" + resultFile);
int exitCode = ProcessTools.executeCommand(pb).getExitValue();
if (exitCode != 0) {
List<String> failedTests = failedTests(resultFile);
String message = "gtest execution failed; exit code = " + exitCode + ".";
if (!failedTests.isEmpty()) {
message += " the failed tests: " + failedTests;
}
throw new AssertionError(message);
}
}

private static List<String> failedTests(Path xml) {
if (!Files.exists(xml)) {
System.err.println("WARNING: test result file (" + xml + ") hasn't been found");
}

try {
return new GTestResultParser(xml).failedTests();
} catch (Throwable t) {
System.err.println("WARNING: failed to parse result file (" + xml + ") " + t);
t.printStackTrace();
}
return Collections.emptyList();
}

private static String getJVMVariantSubDir() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private static enum MethodGroup {
MODE("isInt", "isMixed", "isComp"),
IGNORED("isEmulatedClient", "isDebugBuild", "isFastDebugBuild", "isSlowDebugBuild",
"hasSA", "isRoot", "isTieredSupported", "areCustomLoadersSupportedForCDS",
"isHardenedOSX", "hasOSXPlistEntries");
"isHardenedOSX", "hasOSXPlistEntries", "isOracleLinux7");

public final List<String> methodNames;

Expand Down
68 changes: 0 additions & 68 deletions test/jdk/java/util/Currency/Bug4512215.java

This file was deleted.

Loading

0 comments on commit f39e847

Please sign in to comment.