1 #
  2 # Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved.
  3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4 #
  5 # This code is free software; you can redistribute it and/or modify it
  6 # under the terms of the GNU General Public License version 2 only, as
  7 # published by the Free Software Foundation.  Oracle designates this
  8 # particular file as subject to the "Classpath" exception as provided
  9 # by Oracle in the LICENSE file that accompanied this code.
 10 #
 11 # This code is distributed in the hope that it will be useful, but WITHOUT
 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14 # version 2 for more details (a copy is included in the LICENSE file that
 15 # accompanied this code).
 16 #
 17 # You should have received a copy of the GNU General Public License version
 18 # 2 along with this work; if not, write to the Free Software Foundation,
 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20 #
 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22 # or visit www.oracle.com if you need additional information or have any
 23 # questions.
 24 #
 25 
 26 include MakeIncludeStart.gmk
 27 ifeq ($(INCLUDE), true)
 28 
 29 ################################################################################
 30 
 31 VARHANDLES_INPUT_DIR := $(MODULE_SRC)/share/classes/java/lang/invoke
 32 VARHANDLES_OUTPUT_DIR := $(SUPPORT_OUTPUTDIR)/gensrc/java.base/java/lang/invoke
 33 # These guys are cased because make cannot preserve case...
 34 VARHANDLE_OBJECT_TYPES := Reference FlatValue NonAtomicReference NonAtomicFlatValue
 35 
 36 ################################################################################
 37 # Setup a rule for generating a VarHandle java class
 38 #
 39 # arg $1: type for this varhandle
 40 define GenerateVarHandle
 41   # Underlying erased signature type, Object or a primitive type
 42   VARHANDLE_$1_type := $$(strip $$(if $$(filter $(VARHANDLE_OBJECT_TYPES), $1), Object, $1))
 43   VARHANDLE_$1_InputType := $$(strip $$(if $$(filter $(VARHANDLE_OBJECT_TYPES), $1), $1, $$(call Conv, $1, Type)))
 44   VARHANDLE_$1_Type := $$(strip $$(subst NonAtomicReference, Reference, $$(subst NonAtomicFlatValue, FlatValue, $$(VARHANDLE_$1_InputType))))
 45 
 46   $1_KEYS := $$(VARHANDLE_$1_type) CAS
 47   ifneq ($$(filter $(PRIMITIVE_TYPES), $1),)
 48     # Reference types use ArrayVarHandle class
 49     $1_KEYS += Array Static
 50   else ifneq ($$(filter Reference NonAtomicReference, $1),)
 51     $1_KEYS += Reference Static
 52   else ifneq ($$(filter FlatValue NonAtomicFlatValue, $1),)
 53     # No static field is flat in Hotspot
 54     $1_KEYS += FlatValue
 55   endif
 56 
 57   ifneq ($$(filter byte short char, $1),)
 58     $1_KEYS += ShorterThanInt
 59   endif
 60   ifneq ($$(filter $(NUMBER_TYPES), $1),)
 61     $1_KEYS += AtomicAdd
 62   endif
 63   ifneq ($$(filter $(BITWISE_PRIMITIVE_TYPES), $1),)
 64     $1_KEYS += Bitwise
 65   endif
 66   ifeq ($$(filter NonAtomicReference NonAtomicFlatValue, $1),)
 67     # Everyone except NonAtomicXxx have non-plain access
 68     $1_KEYS += NonPlainAccess
 69   endif
 70 
 71   $$(eval $$(call SetupStreamPreProcessing, GEN_VARHANDLE_$1, \
 72       SOURCE_FILE := $$(VARHANDLES_INPUT_DIR)/X-VarHandle.java.template, \
 73       OUTPUT_FILE := $$(VARHANDLES_OUTPUT_DIR)/VarHandle$$(VARHANDLE_$1_InputType)s.java, \
 74       INFO := Generating VarHandle class for $1, \
 75       SUBST_EMPTY_LINES := false, \
 76       KEYS := $$($1_KEYS), \
 77       REPLACEMENTS := \
 78           type=$$(VARHANDLE_$1_type) \
 79           Type=$$(VARHANDLE_$1_Type) \
 80           InputType=$$(VARHANDLE_$1_InputType), \
 81   ))
 82   TARGETS += $$(GEN_VARHANDLE_$1)
 83 endef
 84 
 85 ################################################################################
 86 # Setup a rule for generating a VarHandleByteArray java class
 87 #
 88 # arg $1: type for this varhandle
 89 define GenerateVarHandleByteArray
 90   VARHANDLE_BYTEARRAY_$1_Type := $$(call Conv, $1, Type)
 91 
 92   $1_KEYS := $1
 93   ifneq ($$(filter int long float double, $1),)
 94     $1_KEYS += CAS
 95   endif
 96   ifneq ($$(filter float double, $1),)
 97     $1_KEYS += floatingPoint
 98   endif
 99   ifneq ($$(filter int long, $1),)
100     $1_KEYS += AtomicAdd Bitwise
101   endif
102 
103   $$(eval $$(call SetupStreamPreProcessing, GEN_VARHANDLE_BYTEARRAY_$1, \
104       SOURCE_FILE := $$(VARHANDLES_INPUT_DIR)/X-VarHandleByteArrayView.java.template, \
105       OUTPUT_FILE := $$(VARHANDLES_OUTPUT_DIR)/VarHandleByteArrayAs$$(VARHANDLE_BYTEARRAY_$1_Type)s.java, \
106       INFO := Generating VarHandleByteArray class for $1, \
107       SUBST_EMPTY_LINES := false, \
108       KEYS := $$($1_KEYS), \
109       REPLACEMENTS := \
110           type=$1 \
111           Type=$$(VARHANDLE_BYTEARRAY_$1_Type) \
112           BoxType=$$(call Conv, $1, Fulltype) \
113           rawType=$$(call Conv, $1, memtype) \
114           RawType=$$(call Conv, $1, Memtype) \
115           RawBoxType=$$(call Conv, $1, FullMemtype), \
116   ))
117   TARGETS += $$(GEN_VARHANDLE_BYTEARRAY_$1)
118 endef
119 
120 ################################################################################
121 # Setup a rule for generating a VarHandleMemorySegment java class
122 #
123 # arg $1: type for this varhandle
124 define GenerateVarHandleMemorySegment
125   VARHANDLE_SEGMENT_$1_Type := $$(call Conv, $1, Type)
126 
127 
128   $1_KEYS := $1
129   ifneq ($$(filter int long float double, $1),)
130     $1_KEYS += CAS
131   endif
132   ifneq ($$(filter boolean byte, $1),)
133     $1_KEYS += byte
134   endif
135   ifneq ($$(filter float double, $1),)
136     $1_KEYS += floatingPoint
137   endif
138   ifneq ($$(filter boolean byte short char, $1),)
139     $1_KEYS += ShorterThanInt
140   endif
141   ifneq ($$(filter int long, $1),)
142     $1_KEYS += AtomicAdd Bitwise
143   endif
144 
145   $$(eval $$(call SetupStreamPreProcessing, GEN_VARHANDLE_SEGMENT_$1, \
146       SOURCE_FILE := $$(VARHANDLES_INPUT_DIR)/X-VarHandleSegmentView.java.template, \
147       OUTPUT_FILE := $$(VARHANDLES_OUTPUT_DIR)/VarHandleSegmentAs$$(VARHANDLE_SEGMENT_$1_Type)s.java, \
148       INFO := Generating VarHandleSegment class for $1, \
149       SUBST_EMPTY_LINES := false, \
150       KEYS := $$($1_KEYS), \
151       REPLACEMENTS := \
152           type=$1 \
153           Type=$$(VARHANDLE_SEGMENT_$1_Type) \
154           BoxType=$$(call Conv, $1, Fulltype) \
155           rawType=$$(call Conv, $1, memtype) \
156           RawType=$$(call Conv, $1, Memtype) \
157           RawBoxType=$$(call Conv, $1, FullMemtype), \
158   ))
159   TARGETS += $$(GEN_VARHANDLE_SEGMENT_$1)
160 endef
161 
162 ################################################################################
163 # Generate all VarHandle related classes
164 
165 $(foreach t, $(PRIMITIVE_TYPES) $(VARHANDLE_OBJECT_TYPES), \
166   $(eval $(call GenerateVarHandle,$t)) \
167 )
168 
169 $(foreach t, $(NON_BYTE_NUMBER_TYPES), \
170   $(eval $(call GenerateVarHandleByteArray,$t)) \
171 )
172 
173 $(foreach t, $(PRIMITIVE_TYPES), \
174   $(eval $(call GenerateVarHandleMemorySegment,$t)) \
175 )
176 
177 ################################################################################
178 
179 GENSRC_VARHANDLEGUARDS := $(VARHANDLES_OUTPUT_DIR)/VarHandleGuards.java
180 
181 $(GENSRC_VARHANDLEGUARDS): $(BUILD_TOOLS_JDK)
182 	$(call LogInfo, Generating $@)
183 	$(call MakeTargetDir)
184 	$(TOOL_VARHANDLEGUARDMETHODGENERATOR) \
185 	    $(GENSRC_VARHANDLEGUARDS)
186 
187 TARGETS += $(GENSRC_VARHANDLEGUARDS)
188 
189 ################################################################################
190 
191 endif # include guard
192 include MakeIncludeEnd.gmk