Skip to content

Commit

Permalink
8271959: [lworld] Convert Optional and VBS classes to value class
Browse files Browse the repository at this point in the history
Reviewed-by: erikj, mchung
  • Loading branch information
Roger Riggs committed Mar 8, 2023
1 parent 0baf5d1 commit 4f71167
Show file tree
Hide file tree
Showing 15 changed files with 357 additions and 51 deletions.
45 changes: 44 additions & 1 deletion make/CompileJavaModules.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ CreateHkTargets = \

################################################################################
# Setup the main compilation

$(eval $(call SetupJavaCompilation, $(MODULE), \
SMALL_JAVA := false, \
MODULE := $(MODULE), \
Expand All @@ -117,6 +116,50 @@ $(eval $(call SetupJavaCompilation, $(MODULE), \

TARGETS += $($(MODULE))

################################################################################
# Setup compilation for value classes in the module
# TBD: When $(DOCLINT) was included there was an NPE in JavacTypes.getOverriddenMethods

# Directory and file name suffix for jar file containing value classes
VALUECLASSES_STR := valueclasses

ifneq ($(COMPILER), bootjdk)
MODULE_VALUECLASS_SRC_DIRS := $(call FindModuleValueClassSrcDirs, $(MODULE))
MODULE_VALUECLASS_SOURCEPATH := $(call GetModuleValueClassSrcPath)

ifneq ($(MODULE_VALUECLASS_SRC_DIRS),)
$(eval $(call SetupJavaCompilation, $(MODULE)-$(VALUECLASSES_STR), \
SMALL_JAVA := false, \
MODULE := $(MODULE), \
SRC := $(wildcard $(MODULE_VALUECLASS_SRC_DIRS)), \
INCLUDES := $(JDK_USER_DEFINED_FILTER), \
FAIL_NO_SRC := $(FAIL_NO_SRC), \
BIN := $(SUPPORT_OUTPUTDIR)/$(VALUECLASSES_STR)/, \
JAR := $(JDK_OUTPUTDIR)/lib/$(VALUECLASSES_STR)/$(MODULE)-$(VALUECLASSES_STR).jar, \
HEADERS := $(SUPPORT_OUTPUTDIR)/headers, \
DISABLED_WARNINGS := $(DISABLED_WARNINGS_java), \
EXCLUDES := $(EXCLUDES), \
EXCLUDE_FILES := $(EXCLUDE_FILES) \
KEEP_ALL_TRANSLATIONS := $(KEEP_ALL_TRANSLATIONS), \
DEPENDS := $($(MODULE)), \
JAVAC_FLAGS := \
$(JAVAC_FLAGS) \
--module-source-path $(MODULE_VALUECLASS_SOURCEPATH) \
--module-path $(JDK_OUTPUTDIR)/modules \
--system none, \
))

TARGETS += $($(MODULE)-$(VALUECLASSES_STR))

$(eval $(call SetupCopyFiles, $(MODULE)-copy-valueclass-jar, \
FILES := $(JDK_OUTPUTDIR)/lib/$(VALUECLASSES_STR)/$(MODULE)-$(VALUECLASSES_STR).jar, \
DEST := $(SUPPORT_OUTPUTDIR)/modules_libs/$(MODULE)/$(VALUECLASSES_STR), \
))

TARGETS += $($(MODULE)-copy-valueclass-jar)
endif
endif

# Declare dependencies between java compilations of different modules.
# Since the other modules are declared in different invocations of this file,
# use the macro to find the correct target file to depend on.
Expand Down
18 changes: 17 additions & 1 deletion make/common/Modules.gmk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2014, 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 @@ -80,6 +80,10 @@ GENERATED_SRC_DIRS += \
$(SUPPORT_OUTPUTDIR)/gensrc \
#

GENERATED_VALUE_CLASS_SUBDIRS += \
$(SUPPORT_OUTPUTDIR)/gensrc-valueclasses \
#

TOP_SRC_DIRS += \
$(TOPDIR)/src \
#
Expand Down Expand Up @@ -146,6 +150,12 @@ FindModuleSrcDirs = \
$(addsuffix /$(strip $1), $(GENERATED_SRC_DIRS) $(IMPORT_MODULES_SRC)) \
$(foreach sub, $(SRC_SUBDIRS), $(addsuffix /$(strip $1)/$(sub), $(TOP_SRC_DIRS)))))

# Find value class source dirs for a particular module (only generated)
# $1 - Module to find source dirs for
FindModuleValueClassSrcDirs = \
$(strip $(wildcard \
$(addsuffix /$(strip $1), $(GENERATED_VALUE_CLASS_SUBDIRS))))

# Find all specs dirs for a particular module
# $1 - Module to find specs dirs for
FindModuleSpecsDirs = \
Expand All @@ -164,6 +174,12 @@ GetModuleSrcPath = \
$(addsuffix /*, $(GENERATED_SRC_DIRS) $(IMPORT_MODULES_SRC)) \
$(foreach sub, $(SRC_SUBDIRS), $(addsuffix /*/$(sub), $(TOP_SRC_DIRS))))

# Construct the complete module source path for value classes
GetModuleValueClassSrcPath = \
$(call PathList, \
$(addsuffix /*, $(GENERATED_VALUE_CLASS_SUBDIRS) $(GENERATED_SRC_DIRS) $(IMPORT_MODULES_SRC)) \
$(foreach sub, $(SRC_SUBDIRS), $(addsuffix /*/$(sub), $(TOP_SRC_DIRS))))

################################################################################
# Extract module dependencies from module-info.java files, both normal
# dependencies ("requires"), and indirect exports ("requires transitive").
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 @@ -36,6 +36,7 @@ include gensrc/GensrcVarHandles.gmk
include gensrc/GensrcModuleLoaderMap.gmk
include gensrc/GensrcEmojiData.gmk
include gensrc/GensrcScopedMemoryAccess.gmk
include gensrc/GensrcValueClasses.gmk

# GensrcLocaleData.gmk does not set TARGETS, so we must choose which targets
# to include.
Expand Down
57 changes: 57 additions & 0 deletions make/modules/java.base/gensrc/GensrcValueClasses.gmk
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#
# 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
#

################################################################################
# Generate the value class replacements for selected java.base source files

java.base-VALUE_CLASS-REPLACEMENTS := \
java/util/Optional.java \
java/util/OptionalInt.java \
java/util/OptionalLong.java \
java/util/OptionalDouble.java \
java/time/LocalDate.java \
java/time/LocalDateTime.java \
java/time/LocalTime.java \
java/time/Duration.java \
java/time/Instant.java \
java/time/MonthDay.java \
java/time/ZonedDateTime.java \
java/time/OffsetDateTime.java \
java/time/OffsetTime.java \
java/time/YearMonth.java \
java/time/Year.java \
java/time/Period.java \
#

java.base-VALUE-CLASS-FILES := \
$(foreach f, $(java.base-VALUE_CLASS-REPLACEMENTS), $(addprefix $(TOPDIR)/src/java.base/share/classes/, $(f)))

$(eval $(call SetupTextFileProcessing, JAVA_BASE_VALUECLASS_REPLACEMENTS, \
SOURCE_FILES := $(java.base-VALUE-CLASS-FILES), \
SOURCE_BASE_DIR := $(TOPDIR)/src/java.base/share/classes, \
OUTPUT_DIR := $(SUPPORT_OUTPUTDIR)/gensrc-valueclasses/java.base/, \
REPLACEMENTS := \
public final class => public final value class, \
))

TARGETS += $(JAVA_BASE_VALUECLASS_REPLACEMENTS)
Loading

0 comments on commit 4f71167

Please sign in to comment.