Skip to content

Commit

Permalink
Merge branch 'sapmachine' of https://github.com/SAP/SapMachine into m…
Browse files Browse the repository at this point in the history
…alloc_hook_replacement
  • Loading branch information
schmelter-sap committed Sep 24, 2023
2 parents 4df8610 + 5015a49 commit 5b9f7e5
Show file tree
Hide file tree
Showing 1,076 changed files with 47,120 additions and 41,901 deletions.
9 changes: 5 additions & 4 deletions make/RunTests.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -862,8 +862,9 @@ define SetupRunJtregTestBody

$$(eval $$(call SetupRunJtregTestCustom, $1))

clean-workdir-$1:
clean-outputdirs-$1:
$$(RM) -r $$($1_TEST_SUPPORT_DIR)
$$(RM) -r $$($1_TEST_RESULTS_DIR)

$1_COMMAND_LINE := \
$$(JAVA) $$($1_JTREG_LAUNCHER_OPTIONS) \
Expand Down Expand Up @@ -909,7 +910,7 @@ define SetupRunJtregTestBody
done
endif

run-test-$1: pre-run-test clean-workdir-$1
run-test-$1: pre-run-test clean-outputdirs-$1
$$(call LogWarn)
$$(call LogWarn, Running test '$$($1_TEST)')
$$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR) \
Expand Down Expand Up @@ -946,9 +947,9 @@ define SetupRunJtregTestBody
$$(eval $1_TOTAL := 1) \
)

$1: run-test-$1 parse-test-$1 clean-workdir-$1
$1: run-test-$1 parse-test-$1 clean-outputdirs-$1

TARGETS += $1 run-test-$1 parse-test-$1 clean-workdir-$1
TARGETS += $1 run-test-$1 parse-test-$1 clean-outputdirs-$1
TEST_TARGETS += parse-test-$1

endef
Expand Down
4 changes: 2 additions & 2 deletions make/ToolsJdk.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ TOOL_GENERATECACERTS = $(JAVA_SMALL) -cp $(BUILDTOOLS_OUTPUTDIR)/jdk_tools_class
-Dkeystore.pkcs12.macAlgorithm=NONE \
build.tools.generatecacerts.GenerateCacerts

TOOL_GENERATEEMOJIDATA = $(JAVA_SMALL) -cp $(BUILDTOOLS_OUTPUTDIR)/jdk_tools_classes \
build.tools.generateemojidata.GenerateEmojiData
TOOL_GENERATEEXTRAPROPERTIES = $(JAVA_SMALL) -cp $(BUILDTOOLS_OUTPUTDIR)/jdk_tools_classes \
build.tools.generateextraproperties.GenerateExtraProperties

TOOL_MAKEZIPREPRODUCIBLE = $(JAVA_SMALL) -cp $(BUILDTOOLS_OUTPUTDIR)/jdk_tools_classes \
build.tools.makezipreproducible.MakeZipReproducible
Expand Down
1 change: 1 addition & 0 deletions make/autoconf/flags-cflags.m4
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_CPU_DEP],
REPRODUCIBLE_CFLAGS=
]
)
AC_SUBST(REPRODUCIBLE_CFLAGS)
fi
# Prevent the __FILE__ macro from generating absolute paths into the built
Expand Down
1 change: 1 addition & 0 deletions make/autoconf/spec.gmk.in
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ LIBFFI_CFLAGS:=@LIBFFI_CFLAGS@
ENABLE_LIBFFI_BUNDLING:=@ENABLE_LIBFFI_BUNDLING@
LIBFFI_LIB_FILE:=@LIBFFI_LIB_FILE@
FILE_MACRO_CFLAGS := @FILE_MACRO_CFLAGS@
REPRODUCIBLE_CFLAGS := @REPRODUCIBLE_CFLAGS@
BRANCH_PROTECTION_CFLAGS := @BRANCH_PROTECTION_CFLAGS@

STATIC_LIBS_CFLAGS := @STATIC_LIBS_CFLAGS@
Expand Down
4 changes: 2 additions & 2 deletions make/common/NativeCompilation.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -1165,9 +1165,9 @@ define SetupNativeCompilationBody
$1_LD_OBJ_ARG := `cat $$($1_OBJ_FILE_LIST)`
endif

# If we are building static library, 'AR' on macosx may not support @-file.
# If we are building static library, 'AR' on macosx/aix may not support @-file.
ifeq ($$($1_TYPE), STATIC_LIBRARY)
ifeq ($(call isTargetOs, macosx), true)
ifeq ($(call isTargetOs, macosx aix), true)
$1_LD_OBJ_ARG := `cat $$($1_OBJ_FILE_LIST)`
endif
endif
Expand Down
2 changes: 1 addition & 1 deletion make/hotspot/gensrc/GensrcAdlc.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ ifeq ($(call check-jvm-feature, compiler2), true)
ADLC_CFLAGS += -I$(TOPDIR)/src/hotspot/share

# Add file macro mappings
ADLC_CFLAGS += $(FILE_MACRO_CFLAGS)
ADLC_CFLAGS += $(FILE_MACRO_CFLAGS) $(REPRODUCIBLE_CFLAGS)

ifeq ($(UBSAN_ENABLED), true)
ADLC_CFLAGS += $(UBSAN_CFLAGS)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 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 @@ -25,6 +25,7 @@

package build.tools.compileproperties;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
Expand All @@ -33,6 +34,9 @@
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -220,8 +224,8 @@ private static boolean createFile(String propertiesPath, String outputPath,
System.out.println("parsing: " + propertiesPath);
}
Properties p = new Properties();
try {
p.load(new FileInputStream(propertiesPath));
try (BufferedReader input = Files.newBufferedReader(Path.of(propertiesPath))) {
p.load(input);
} catch ( FileNotFoundException e ) {
ok = false;
error("Cannot find file " + propertiesPath, e);
Expand Down Expand Up @@ -267,7 +271,7 @@ private static boolean createFile(String propertiesPath, String outputPath,
Writer writer = null;
try {
writer = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(outputPath), "8859_1"));
new OutputStreamWriter(new FileOutputStream(outputPath), StandardCharsets.US_ASCII));
MessageFormat format = new MessageFormat(FORMAT);
writer.write(format.format(new Object[] { packageString, className, superClass, data }));
} catch ( IOException e ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private PropList(File file, int plane) throws IOException {

int i, j;
BufferedReader sbfr = new BufferedReader(new FileReader(file));
Matcher m = Pattern.compile("(\\p{XDigit}+)(?:\\.{2}(\\p{XDigit}+))?\\s*;\\s+(\\w+)\\s+#.*").matcher("");
Matcher m = Pattern.compile("(\\p{XDigit}+)(?:\\.{2}(\\p{XDigit}+))?\\s*;\\s+(\\w+)[;\\s].*").matcher("");
String line = null;
int lineNo = 0;
while ((line = sbfr.readLine()) != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/*
* Copyright (c) 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
* 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.
*/
package build.tools.generateextraproperties;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* Parses extra properties files of UCD, and replaces the placeholders in
* the given template source file with the generated conditions, then emits
* .java files. For example, if the properties file has:
* <blockquote>
* 0009..000D ; Type (; Value)
* 0020 ; Type (; Value)
* 2000..200A ; Type (; Value)
* </blockquote>
* and the template file contains
* <blockquote>
* %%%Type(=Value)%%%
* </blockquote>
* then the generated .java file would have the following in place:
* <blockquote>
* (cp >= 0x0009 && cp <= 0x000D) ||
* cp == 0x0020 ||
* (cp >= 0x2000 && cp <= 0x200A);
* </blockquote>
* Note that those in parentheses in the properties file and the
* template file are optional.
*
* Arguments to this utility:
* args[0]: Full path string to the template file
* args[1]: Full path string to the properties file
* args[2]: Full path string to the generated .java file
* args[3...]: Names of the property to generate the conditions
*/
public class GenerateExtraProperties {
public static void main(String[] args) {
var templateFile = Paths.get(args[0]);
var propertiesFile = Paths.get(args[1]);
var gensrcFile = Paths.get(args[2]);
var propertyNames = Arrays.copyOfRange(args, 3, args.length);
var replacementMap = new HashMap<String, String>();

try {
for (var propertyName: propertyNames) {
var pn = "; " + propertyName.replaceFirst("=", "; ");

List<Range> ranges = Files.lines(propertiesFile)
.filter(Predicate.not(l -> l.startsWith("#") || l.isBlank()))
.filter(l -> l.contains(pn))
.map(l -> new Range(l.replaceFirst(" .*", "")))
.sorted()
.collect(ArrayList<Range>::new,
(list, r) -> {
// collapsing consecutive pictographic ranges
int lastIndex = list.size() - 1;
if (lastIndex >= 0) {
Range lastRange = list.get(lastIndex);
if (lastRange.last + 1 == r.start) {
list.set(lastIndex, new Range(lastRange.start, r.last));
return;
}
}
list.add(r);
},
ArrayList<Range>::addAll);


replacementMap.put("%%%" + propertyName + "%%%",
ranges.stream()
.map(GenerateExtraProperties::rangeToString)
.collect(Collectors.joining(" ||\n", "", ";")));
}

// Generate .java file
Files.write(gensrcFile,
Files.lines(templateFile)
.flatMap(l -> Stream.of(replacementMap.getOrDefault(l.trim(), l)))
.collect(Collectors.toList()),
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
} catch (IOException e) {
e.printStackTrace();
}
}

static String rangeToString(Range r) {
if (r.start == r.last) {
return (" ".repeat(12) + "cp == 0x" + toHexString(r.start));
} else if (r.start == r.last - 1) {
return " ".repeat(12) + "cp == 0x" + toHexString(r.start) + " ||\n" +
" ".repeat(12) + "cp == 0x" + toHexString(r.last);
} else {
return " ".repeat(11) + "(cp >= 0x" + toHexString(r.start) +
" && cp <= 0x" + toHexString(r.last) + ")";
}
}

static int toInt(String hexStr) {
return Integer.parseUnsignedInt(hexStr, 16);
}

static String toHexString(int cp) {
String ret = Integer.toUnsignedString(cp, 16).toUpperCase();
if (ret.length() < 4) {
ret = "0".repeat(4 - ret.length()) + ret;
}
return ret;
}

static class Range implements Comparable<Range> {
int start;
int last;

Range (int start, int last) {
this.start = start;
this.last = last;
}

Range (String input) {
input = input.replaceFirst("\\s#.*", "");
start = toInt(input.replaceFirst("[\\s\\.].*", ""));
last = input.contains("..") ?
toInt(input.replaceFirst(".*\\.\\.", "")
.replaceFirst(";.*", "").trim())
: start;
}

@Override
public String toString() {
return "Start: " + toHexString(start) + ", Last: " + toHexString(last);
}

@Override
public int compareTo(Range other) {
return Integer.compare(start, other.start);
}
}
}
12 changes: 8 additions & 4 deletions make/langtools/tools/compileproperties/CompileProperties.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 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 @@ -25,6 +25,7 @@

package compileproperties;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
Expand All @@ -33,6 +34,9 @@
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -199,8 +203,8 @@ private boolean createFile(String propertiesPath, String outputPath,
boolean ok = true;
log.verbose("parsing: " + propertiesPath);
Properties p = new Properties();
try {
p.load(new FileInputStream(propertiesPath));
try (BufferedReader input = Files.newBufferedReader(Path.of(propertiesPath))) {
p.load(input);
} catch ( FileNotFoundException e ) {
ok = false;
log.error("Cannot find file " + propertiesPath, e);
Expand Down Expand Up @@ -246,7 +250,7 @@ private boolean createFile(String propertiesPath, String outputPath,
Writer writer = null;
try {
writer = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(outputPath), "8859_1"));
new OutputStreamWriter(new FileOutputStream(outputPath), StandardCharsets.US_ASCII));
MessageFormat format = new MessageFormat(FORMAT);
writer.write(format.format(new Object[] { packageString, className, superClass, data }));
} catch ( IOException e ) {
Expand Down
1 change: 1 addition & 0 deletions make/modules/java.base/Gensrc.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ include gensrc/GensrcExceptions.gmk
include gensrc/GensrcVarHandles.gmk
include gensrc/GensrcModuleLoaderMap.gmk
include gensrc/GensrcScopedMemoryAccess.gmk
include gensrc/GensrcRegex.gmk

# GensrcLocaleData.gmk does not set TARGETS, so we must choose which targets
# to include.
Expand Down
Loading

0 comments on commit 5b9f7e5

Please sign in to comment.