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 := \
 43       $$(strip $$(if $$(filter $(VARHANDLE_OBJECT_TYPES), $1), Object, $1))
 44   VARHANDLE_$1_InputType := \
 45       $$(strip $$(if $$(filter $(VARHANDLE_OBJECT_TYPES), $1), $1, \
 46       $$(call Conv, $1, Type)))
 47   VARHANDLE_$1_Type := \
 48       $$(strip $$(subst NonAtomicReference, Reference, \
 49       $$(subst NonAtomicFlatValue, FlatValue, $$(VARHANDLE_$1_InputType))))
 50 
 51   $1_KEYS := $$(VARHANDLE_$1_type) CAS
 52   ifneq ($$(filter $(PRIMITIVE_TYPES), $1),)
 53     # Reference types use ArrayVarHandle class
 54     $1_KEYS += Array Static
 55   else ifneq ($$(filter Reference NonAtomicReference, $1),)
 56     $1_KEYS += Reference Static
 57   else ifneq ($$(filter FlatValue NonAtomicFlatValue, $1),)
 58     # No static field is flat in Hotspot
 59     $1_KEYS += FlatValue
 60   endif
 61 
 62   ifneq ($$(filter byte short char, $1),)
 63     $1_KEYS += ShorterThanInt
 64   endif
 65   ifneq ($$(filter $(NUMBER_TYPES), $1),)
 66     $1_KEYS += AtomicAdd
 67   endif
 68   ifneq ($$(filter $(BITWISE_PRIMITIVE_TYPES), $1),)
 69     $1_KEYS += Bitwise
 70   endif
 71   ifeq ($$(filter NonAtomicReference NonAtomicFlatValue, $1),)
 72     # Everyone except NonAtomicXxx have non-plain access
 73     $1_KEYS += NonPlainAccess
 74   endif
 75 
 76   $$(eval $$(call SetupStreamPreProcessing, GEN_VARHANDLE_$1, \
 77       SOURCE_FILE := $$(VARHANDLES_INPUT_DIR)/X-VarHandle.java.template, \
 78       OUTPUT_FILE := $$(VARHANDLES_OUTPUT_DIR)/VarHandle$$(VARHANDLE_$1_InputType)s.java, \
 79       INFO := Generating VarHandle class for $1, \
 80       SUBST_EMPTY_LINES := false, \
 81       KEYS := $$($1_KEYS), \
 82       REPLACEMENTS := \
 83           type=$$(VARHANDLE_$1_type) \
 84           Type=$$(VARHANDLE_$1_Type) \
 85           InputType=$$(VARHANDLE_$1_InputType), \
 86   ))
 87   TARGETS += $$(GEN_VARHANDLE_$1)
 88 endef
 89 
 90 ################################################################################
 91 # Setup a rule for generating a VarHandleByteArray java class
 92 #
 93 # arg $1: type for this varhandle
 94 define GenerateVarHandleByteArray
 95   VARHANDLE_BYTEARRAY_$1_Type := $$(call Conv, $1, Type)
 96 
 97   $1_KEYS := $1
 98   ifneq ($$(filter int long float double, $1),)
 99     $1_KEYS += CAS
100   endif
101   ifneq ($$(filter float double, $1),)
102     $1_KEYS += floatingPoint
103   endif
104   ifneq ($$(filter int long, $1),)
105     $1_KEYS += AtomicAdd Bitwise
106   endif
107 
108   $$(eval $$(call SetupStreamPreProcessing, GEN_VARHANDLE_BYTEARRAY_$1, \
109       SOURCE_FILE := $$(VARHANDLES_INPUT_DIR)/X-VarHandleByteArrayView.java.template, \
110       OUTPUT_FILE := $$(VARHANDLES_OUTPUT_DIR)/VarHandleByteArrayAs$$(VARHANDLE_BYTEARRAY_$1_Type)s.java, \
111       INFO := Generating VarHandleByteArray class for $1, \
112       SUBST_EMPTY_LINES := false, \
113       KEYS := $$($1_KEYS), \
114       REPLACEMENTS := \
115           type=$1 \
116           Type=$$(VARHANDLE_BYTEARRAY_$1_Type) \
117           BoxType=$$(call Conv, $1, Fulltype) \
118           rawType=$$(call Conv, $1, memtype) \
119           RawType=$$(call Conv, $1, Memtype) \
120           RawBoxType=$$(call Conv, $1, FullMemtype), \
121   ))
122   TARGETS += $$(GEN_VARHANDLE_BYTEARRAY_$1)
123 endef
124 
125 ################################################################################
126 # Setup a rule for generating a VarHandleMemorySegment java class
127 #
128 # arg $1: type for this varhandle
129 define GenerateVarHandleMemorySegment
130   VARHANDLE_SEGMENT_$1_Type := $$(call Conv, $1, Type)
131 
132 
133   $1_KEYS := $1
134   ifneq ($$(filter int long float double, $1),)
135     $1_KEYS += CAS
136   endif
137   ifneq ($$(filter boolean byte, $1),)
138     $1_KEYS += byte
139   endif
140   ifneq ($$(filter float double, $1),)
141     $1_KEYS += floatingPoint
142   endif
143   ifneq ($$(filter boolean byte short char, $1),)
144     $1_KEYS += ShorterThanInt
145   endif
146   ifneq ($$(filter int long, $1),)
147     $1_KEYS += AtomicAdd Bitwise
148   endif
149 
150   $$(eval $$(call SetupStreamPreProcessing, GEN_VARHANDLE_SEGMENT_$1, \
151       SOURCE_FILE := $$(VARHANDLES_INPUT_DIR)/X-VarHandleSegmentView.java.template, \
152       OUTPUT_FILE := $$(VARHANDLES_OUTPUT_DIR)/VarHandleSegmentAs$$(VARHANDLE_SEGMENT_$1_Type)s.java, \
153       INFO := Generating VarHandleSegment class for $1, \
154       SUBST_EMPTY_LINES := false, \
155       KEYS := $$($1_KEYS), \
156       REPLACEMENTS := \
157           type=$1 \
158           Type=$$(VARHANDLE_SEGMENT_$1_Type) \
159           BoxType=$$(call Conv, $1, Fulltype) \
160           rawType=$$(call Conv, $1, memtype) \
161           RawType=$$(call Conv, $1, Memtype) \
162           RawBoxType=$$(call Conv, $1, FullMemtype), \
163   ))
164   TARGETS += $$(GEN_VARHANDLE_SEGMENT_$1)
165 endef
166 
167 ################################################################################
168 # Generate all VarHandle related classes
169 
170 $(foreach t, $(PRIMITIVE_TYPES) $(VARHANDLE_OBJECT_TYPES), \
171   $(eval $(call GenerateVarHandle,$t)) \
172 )
173 
174 $(foreach t, $(NON_BYTE_NUMBER_TYPES), \
175   $(eval $(call GenerateVarHandleByteArray,$t)) \
176 )
177 
178 $(foreach t, $(PRIMITIVE_TYPES), \
179   $(eval $(call GenerateVarHandleMemorySegment,$t)) \
180 )
181 
182 ################################################################################
183 
184 GENSRC_VARHANDLEGUARDS := $(VARHANDLES_OUTPUT_DIR)/VarHandleGuards.java
185 
186 $(GENSRC_VARHANDLEGUARDS): $(BUILD_TOOLS_JDK)
187 	$(call LogInfo, Generating $@)
188 	$(call MakeTargetDir)
189 	$(TOOL_VARHANDLEGUARDMETHODGENERATOR) \
190 	    $(GENSRC_VARHANDLEGUARDS)
191 
192 TARGETS += $(GENSRC_VARHANDLEGUARDS)
193 
194 ################################################################################
195 
196 endif # include guard
197 include MakeIncludeEnd.gmk