8198844: Clean up GensrcX11Wrappers

Reviewed-by: erikj, prr
This commit is contained in:
Magnus Ihse Bursie 2018-03-06 00:59:49 +01:00
parent f62bc01efe
commit 5f52842c26
10 changed files with 2083 additions and 3111 deletions

View File

@ -399,10 +399,13 @@ docs-zip:
update-build-docs:
+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f UpdateBuildDocs.gmk)
update-x11wrappers:
+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f UpdateX11Wrappers.gmk)
ALL_TARGETS += docs-jdk-api-javadoc docs-jdk-api-modulegraph \
docs-javase-api-javadoc docs-javase-api-modulegraph \
docs-reference-api-javadoc docs-reference-api-modulegraph docs-jdk-specs \
docs-jdk-index docs-zip update-build-docs
docs-jdk-index docs-zip update-build-docs update-x11wrappers
################################################################################
# Cross compilation support
@ -724,9 +727,9 @@ else
# If not already set, set the JVM target so that the JVM will be built.
JVM_MAIN_TARGETS ?= hotspot
# Building java.base-jmod requires all of VM (ie hotspot) to be built.
java.base-jmod: $(JVM_MAIN_TARGETS)
java.base-jmod: $(JVM_MAIN_TARGETS)
# Declare dependencies from <module>-jmod to all other module targets
# When creating a BUILDJDK, the java compilation has already been done by the
@ -830,7 +833,7 @@ else
# If not already set, then set the JVM specific docs targets
JVM_DOCS_TARGETS ?= hotspot-$(JVM_VARIANT_MAIN)-gensrc
# The gensrc steps for hotspot and jdk.jdi create html spec files.
docs-jdk-specs: $(JVM_DOCS_TARGETS) jdk.jdi-gensrc \
docs-jdk-index
@ -894,6 +897,8 @@ else
generate-summary: jmods buildtools-modules
update-x11wrappers: java.base-copy buildtools-jdk
endif
################################################################################

101
make/UpdateX11Wrappers.gmk Normal file
View File

@ -0,0 +1,101 @@
#
# Copyright (c) 2012, 2018, 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.
#
################################################################################
default: all
include $(SPEC)
include MakeBase.gmk
include NativeCompilation.gmk
include ToolsJdk.gmk
################################################################################
# This file is responsible for extracting the x11 native struct offsets to
# the xawt Java library. The tool needs to be run on the os/arch that
# will host the final jvm, thus the tool cannot be used when cross compiling.
#
# Two versions of the generated offset file, sizes-32.txt and sizes-64.txt are
# committed into the source code repository. These are the ones used in
# GensrcX11Wrappers.gmk to generate the Java code during the build.
################################################################################
ifeq ($(COMPILE_TYPE), cross)
$(error It is not possible to update the x11wrappers when cross-compiling)
endif
X11WRAPPERS_OUTPUT := $(SUPPORT_OUTPUTDIR)/x11wrappers
GENSRC_X11WRAPPERS_DATADIR := $(TOPDIR)/make/data/x11wrappergen
BITS := $(OPENJDK_TARGET_CPU_BITS)
# Generate the C code for the program that will output the offset file.
$(X11WRAPPERS_OUTPUT)/src/data_generator.c: $(GENSRC_X11WRAPPERS_DATADIR)/xlibtypes.txt $(BUILD_TOOLS_JDK)
$(call LogInfo, Generating X11 wrapper data generator source code)
$(call MakeDir, $(@D))
$(call ExecuteWithLog, $@, \
$(TOOL_WRAPPERGENERATOR) gen_c_source $@ $(GENSRC_X11WRAPPERS_DATADIR)/xlibtypes.txt $(BITS))
DATA_GENERATOR_INCLUDES := \
-I$(TOPDIR)/src/hotspot/share/include \
-I$(TOPDIR)/src/hotspot/os/$(HOTSPOT_TARGET_OS_TYPE)/include \
-I$(SUPPORT_OUTPUTDIR)/modules_include/java.base \
-I$(SUPPORT_OUTPUTDIR)/modules_include/java.base/$(OPENJDK_TARGET_OS_INCLUDE_SUBDIR) \
-I$(TOPDIR)/src/java.base/share/native/libjava \
-I$(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/libjava \
-I$(TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/common/awt \
-I$(TOPDIR)/src/java.desktop/share/native/common/awt/debug \
-I$(TOPDIR)/src/java.desktop/share/native/libawt/awt/image/cvutils \
#
# Compile the generated C code into an executable.
$(eval $(call SetupNativeCompilation, BUILD_DATA_GENERATOR, \
PROGRAM := data_generator, \
OUTPUT_DIR := $(X11WRAPPERS_OUTPUT)/bin, \
EXTRA_FILES := $(X11WRAPPERS_OUTPUT)/src/data_generator.c, \
CFLAGS := $(X_CFLAGS) $(DATA_GENERATOR_INCLUDES) $(CFLAGS_JDKEXE), \
LDFLAGS := $(LDFLAGS_JDKEXE), \
LIBS := $(X_LIBS) -lc, \
OBJECT_DIR := $(X11WRAPPERS_OUTPUT)/objs, \
))
# Run the executable to create the data file.
$(GENSRC_X11WRAPPERS_DATADIR)/sizes-$(BITS).txt: $(BUILD_DATA_GENERATOR_TARGET)
$(call LogInfo, Generating X11 wrapper data files)
$(call MakeDir, $(@D))
$(call ExecuteWithLog, $(X11WRAPPERS_OUTPUT)/generation, \
$(BUILD_DATA_GENERATOR_TARGET) | $(SORT) > $@)
$(ECHO) IMPORTANT: If you update the X11 wrapper data files, they most certainly
$(ECHO) need to be updated for both 32 and 64 bit platforms. You have now
$(ECHO) updated them for $(BITS) bit platforms only.
TARGETS += $(GENSRC_X11WRAPPERS_DATADIR)/sizes-$(BITS).txt
################################################################################
all: $(TARGETS)
.PHONY: all default

View File

@ -1,26 +0,0 @@
!XGetWindowProperty|int
w long
property Atom
long_offset long
long_length long
delete Bool
req_type Atom
actual_type Atom out
actual_format int out
number_of_items long out
bytes_after long out
data pointer out free
!XQueryTree|int
w long
root long out
parent long out
children pointer out free
nchildren int out
!XTranslateCoordinates|int
scr_w long
dest_w long
src_x int
src_y int
dest_x int out
dest_y int out
child long out

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,9 @@
//
//
// This file is used for automated generation of java classes to wrap native structures.
// The detail on format of this file see WrapperGenerator.java
// For details on format of this file, see WrapperGenerator.java
//
// WARNING: if you modified this file, you need to regenerate sizes.64-solaris-i386
// WARNING: If you modify this file, you need to regenerate sizes-32.txt and sizes-64.txt.
// Run "make update-x11wrappers" to do this.
//
XExtData

View File

@ -30,10 +30,10 @@ $(eval $(call IncludeCustomExtension, gensrc/Gensrc-java.desktop.gmk))
ifneq ($(OPENJDK_TARGET_OS), windows)
include GensrcIcons.gmk
endif
ifneq ($(OPENJDK_TARGET_OS), macosx)
include GensrcX11Wrappers.gmk
endif
ifneq ($(filter $(OPENJDK_TARGET_OS), linux solaris aix), )
include GensrcX11Wrappers.gmk
endif
include GensrcSwing.gmk

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2012, 2018, 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
@ -23,106 +23,32 @@
# questions.
#
# This file is responsible for extracting the x11 native struct offsets to
# the xawt Java library. The tool needs to be run on the os/arch that
# will host the final jvm, thus the tool cannot be used when cross compiling.
# Generate java sources using the X11 offsets that are precalculated in files
# make/data/x11wrappergen/sizes-<address size>.txt.
# To enable cross compiling, the two versions of the generated offset file,
# sizes.32 and sizes.64 are committed into the source code repository.
# These are the ones used.
GENSRC_X11WRAPPERS_OUTPUT_TOP := $(SUPPORT_OUTPUTDIR)/gensrc/java.desktop
# However when not cross compiling, the offset generator tool is built and
# run, to verify that it still generates the same sizes.32 and sizes.64.
GENSRC_X11WRAPPERS_MARKER := $(GENSRC_X11WRAPPERS_OUTPUT_TOP)/_x11wrappers.marker
GENSRC_X11WRAPPERS :=
# Put temporary c-code and executable to calculate offsets here.
# Also put verification offset file here as well.
GENSRC_X11WRAPPERS_TMP := $(SUPPORT_OUTPUTDIR)/gensrc/java.desktop/_x11wrappers
# Put the generated Java classes used to interface X11 from awt here.
GENSRC_X11WRAPPERS_DST := $(SUPPORT_OUTPUTDIR)/gensrc/java.desktop/sun/awt/X11
GENSRC_X11WRAPPERS_OUTPUTDIR := $(GENSRC_X11WRAPPERS_OUTPUT_TOP)/sun/awt/X11
# The pre-calculated offset file are stored here:
GENSRC_SIZER_DIR := $(TOPDIR)/make/data/x11wrappergen
GENSRC_X11WRAPPERS_DATADIR := $(TOPDIR)/make/data/x11wrappergen
GENSRC_X11WRAPPERS_DATA := $(GENSRC_X11WRAPPERS_DATADIR)/sizes-$(OPENJDK_TARGET_CPU_BITS).txt
# Normal case is to generate only according to target bits
GENSRC_X11_VERSION := $(OPENJDK_TARGET_CPU_BITS)
ifeq ($(OPENJDK_TARGET_CPU_BITS), 64)
ifneq ($(OPENJDK_TARGET_OS), linux)
# On all 64-bit systems except Linux, generate both 32 and 64 bit versions
GENSRC_X11_VERSION := 32 64
endif
else
ifeq ($(OPENJDK_TARGET_OS), solaris)
# As a special case, solaris 32-bit also generates the 64-bit version
GENSRC_X11_VERSION := 32 64
endif
endif
$(info ExecuteWithLog is $(call ExecuteWithLog $(GENSRC_X11WRAPPERS_OUTPUT_TOP)/foobar, CMDLINE))
GENSRC_X11_SIZES_USED := $(addprefix $(GENSRC_X11WRAPPERS_TMP)/sizes., $(GENSRC_X11_VERSION))
# Copy only the sizes.* files that are actually needed. WrapperGenerator picks up any it finds from the
# file prefix it is given so those not needed need to be hidden.
$(GENSRC_X11WRAPPERS_TMP)/sizes.%: $(GENSRC_SIZER_DIR)/sizes.%
$(call MakeDir, $(@D))
$(RM) '$@'
$(SORT) $< > $@
# Run the tool on the offset files copied from the source repository to generate several Java classes
# used in awt.
$(SUPPORT_OUTPUTDIR)/gensrc/java.desktop/_the.generated.x11: $(GENSRC_X11_SIZES_USED) $(BUILD_TOOLS_JDK)
$(call MakeDir, $(GENSRC_X11WRAPPERS_DST))
$(TOOL_WRAPPERGENERATOR) $(GENSRC_X11WRAPPERS_DST) $(GENSRC_SIZER_DIR)/xlibtypes.txt "gen" $(GENSRC_X11WRAPPERS_TMP)/sizes
# Run the tool on the offset files to generate several Java classes used in awt.
$(GENSRC_X11WRAPPERS_MARKER): $(BUILD_TOOLS_JDK) $(GENSRC_X11WRAPPERS_DATA) \
$(GENSRC_X11WRAPPERS_DATADIR)/xlibtypes.txt
$(call MakeDir, $(GENSRC_X11WRAPPERS_OUTPUTDIR))
$(call LogInfo, Generating X11 wrapper source files)
$(call ExecuteWithLog, $@, \
$(TOOL_WRAPPERGENERATOR) gen_java $(GENSRC_X11WRAPPERS_OUTPUTDIR) \
$(GENSRC_X11WRAPPERS_DATADIR)/xlibtypes.txt $(GENSRC_X11WRAPPERS_DATA) \
$(OPENJDK_TARGET_CPU_BITS))
$(TOUCH) $@
GENSRC_X11WRAPPERS += $(SUPPORT_OUTPUTDIR)/gensrc/java.desktop/_the.generated.x11
ifneq ($(COMPILE_TYPE), cross)
# This is not a cross compile, regenerate the offset file, so that we
# can compare it with the version in the source code repository.
# Generate the C code for the program that will output the offset file.
$(GENSRC_X11WRAPPERS_TMP)/sizer.%.c: $(GENSRC_SIZER_DIR)/xlibtypes.txt $(BUILD_TOOLS_JDK)
$(call LogInfo, Generating X11 wrapper ($*-bit version))
$(call MakeDir, $(@D))
$(TOOL_WRAPPERGENERATOR) $(@D) $(GENSRC_SIZER_DIR)/xlibtypes.txt "sizer" $*
# use -m32/-m64 only if the compiler supports it
ifeq ($(COMPILER_SUPPORTS_TARGET_BITS_FLAG), true)
MEMORY_MODEL_FLAG="$(COMPILER_TARGET_BITS_FLAG)$*"
endif
SIZER_CFLAGS := \
-I$(TOPDIR)/src/hotspot/share/include \
-I$(TOPDIR)/src/hotspot/os/$(HOTSPOT_TARGET_OS_TYPE)/include \
-I$(SUPPORT_OUTPUTDIR)/modules_include/java.base \
-I$(SUPPORT_OUTPUTDIR)/modules_include/java.base/$(OPENJDK_TARGET_OS_INCLUDE_SUBDIR) \
-I$(TOPDIR)/src/java.base/share/native/libjava \
-I$(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/libjava \
-I$(TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/common/awt \
-I$(TOPDIR)/src/java.desktop/share/native/common/awt/debug \
-I$(TOPDIR)/src/java.desktop/share/native/libawt/awt/image/cvutils \
#
# Compile the C code into an executable.
$(GENSRC_X11WRAPPERS_TMP)/sizer.%.exe: $(GENSRC_X11WRAPPERS_TMP)/sizer.%.c
$(call MakeDir, $(@D))
(cd $(@D) && $(CC) $(MEMORY_MODEL_FLAG) -o $@ $< \
$(X_CFLAGS) \
$(X_LIBS) \
$(SIZER_CFLAGS) -lc)
.PRECIOUS: $(GENSRC_X11WRAPPERS_TMP)/sizer.%.exe $(GENSRC_X11WRAPPERS_TMP)/sizer.%.c
# Run the executable create the offset file and check that it is identical
# to the offset file in the source code repository.
$(GENSRC_X11WRAPPERS_TMP)/sizes.%.verification: $(GENSRC_X11WRAPPERS_TMP)/sizer.%.exe
$(call LogInfo, Verifying X11 wrapper sizes)
$(call MakeDir, $(@D))
$(GENSRC_X11WRAPPERS_TMP)/sizer.$*.exe | $(SORT) > $@.tmp
$(DIFF) $(GENSRC_X11WRAPPERS_TMP)/sizes.$*.verification.tmp $(GENSRC_X11WRAPPERS_TMP)/sizes.$*
mv $@.tmp $@
GENSRC_X11WRAPPERS += $(GENSRC_X11WRAPPERS_TMP)/sizes.$(OPENJDK_TARGET_CPU_BITS).verification
endif
GENSRC_JAVA_DESKTOP += $(GENSRC_X11WRAPPERS)
GENSRC_JAVA_DESKTOP += $(GENSRC_X11WRAPPERS_MARKER)

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2018, 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
@ -1109,7 +1109,6 @@ public class WrapperGenerator {
}
public void writeJavaWrapperClass(String outputDir) {
// (new File(outputDir, package_path)).mkdirs();
try {
for (Enumeration e = symbolTable.elements() ; e.hasMoreElements() ;) {
BaseType tp = (BaseType) e.nextElement();
@ -1126,7 +1125,6 @@ public class WrapperGenerator {
}
}
public void writeNativeSizer(String file)
{
int type;
@ -1136,7 +1134,6 @@ public class WrapperGenerator {
StructType stp;
Enumeration eo;
try {
FileOutputStream fs = new FileOutputStream(file);
@ -1158,7 +1155,6 @@ public class WrapperGenerator {
pw.println(" unsigned long status;\n");
pw.println("} PropMwmHints;\n");
pw.println("\n\nint main(){");
j=0;
for ( eo = symbolTable.elements() ; eo.hasMoreElements() ;) {
@ -1182,7 +1178,6 @@ public class WrapperGenerator {
pw.println("printf(\"Atom\t%d\\n\",(int)sizeof(Atom));");
pw.println("printf(\"Window\t%d\\n\",(int)sizeof(Window));");
for (eo = symbolTable.elements() ; eo.hasMoreElements() ;) {
@ -1234,7 +1229,8 @@ public class WrapperGenerator {
symbolTable.put("Atom", new AtomicType(AtomicType.TYPE_ATOM, "", "Atom"));
symbolTable.put("ulong", new AtomicType(AtomicType.TYPE_ULONG, "", "ulong"));
}
public WrapperGenerator(String outputDir, String xlibFilename) {
public WrapperGenerator(String xlibFilename) {
initTypes();
try {
BufferedReader in = new BufferedReader(new FileReader(xlibFilename));
@ -1303,33 +1299,19 @@ public class WrapperGenerator {
catch (Exception e) {
e.printStackTrace();
}
}
private void makeSizer(String outputDir) {
if (wide) {
sizerFileName = "sizer.64.c";
} else {
sizerFileName = "sizer.32.c";
}
File fp = new File(outputDir, sizerFileName);
private void makeSizer(String sizerFileName) {
File fp = new File(sizerFileName);
writeNativeSizer(fp.getAbsolutePath());
}
private boolean readSizeInfo(String sizeInfo) {
private boolean readFileSizeInfo(String filename, boolean wide) {
try {
File f = new File(sizeInfo+".32");
boolean res = true;
FileInputStream fis = null;
if (f.exists()) {
fis = new FileInputStream(f);
res = readSizeInfo(fis, false);
fis.close();
}
f = new File(sizeInfo+".64");
if (f.exists()) {
fis = new FileInputStream(f);
res &= readSizeInfo(fis, true);
fis.close();
}
FileInputStream fis = new FileInputStream(filename);
res = readSizeInfo(fis, wide);
fis.close();
return res;
} catch (Exception e) {
e.printStackTrace();
@ -1337,8 +1319,8 @@ public class WrapperGenerator {
}
}
private void startGeneration(String outputDir, String sizeInfo) {
if (readSizeInfo(sizeInfo))
private void startGeneration(String outputDir, String filename, boolean wide) {
if (readFileSizeInfo(filename, wide))
{
writeJavaWrapperClass(outputDir);
}
@ -1348,21 +1330,22 @@ public class WrapperGenerator {
}
public static void main(String[] args) {
if (args.length < 4) {
System.out.println("Usage:\nWrapperGenerator <output_dir> <xlibtypes.txt> <action> [<platform> | <sizes info file>]");
System.out.println("Where <action>: gen, sizer");
System.out.println(" <platform>: 32, 64");
System.out.println("Usage:\nWrapperGenerator gen_java <output_dir> <xlibtypes.txt> <sizes-*.txt> <platform>");
System.out.println(" or");
System.out.println("WrapperGenerator gen_c_source <output_file> <xlibtypes.txt> <platform>");
System.out.println("Where <platform>: 32, 64");
System.exit(1);
}
WrapperGenerator xparser = new WrapperGenerator(args[0], args[1]);
if (args[2].equals("sizer")) {
WrapperGenerator xparser = new WrapperGenerator(args[2]);
if (args[0].equals("gen_c_source")) {
xparser.wide = args[3].equals("64");
xparser.makeSizer(args[0]);
} else if (args[2].equals("gen")) {
xparser.startGeneration(args[0], args[3]);
xparser.makeSizer(args[1]);
} else if (args[0].equals("gen_java")) {
boolean wide = args[4].equals("64");
xparser.startGeneration(args[1], args[3], wide);
}
}
}