1 #
  2 # Copyright (c) 2015, 2025, 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 
 34 ################################################################################
 35 
 36 GENSRC_VARHANDLES :=
 37 
 38 VARHANDLES_GENSRC_DIR := $(SUPPORT_OUTPUTDIR)/gensrc/java.base/java/lang/invoke
 39 VARHANDLES_SRC_DIR := $(MODULE_SRC)/share/classes/java/lang/invoke
 40 
 41 ################################################################################
 42 # Setup a rule for generating a VarHandle java class
 43 # Param 1 - Variable declaration prefix
 44 # Param 2 - Type with first letter capitalized
 45 define GenerateVarHandle
 46 
 47   $1_InputType := $2
 48   $1_type := $$(call lowercase, $2)
 49   $1_Type := $2
 50 
 51   $1_FILENAME := $(VARHANDLES_GENSRC_DIR)/VarHandle$$($1_InputType)s.java
 52 
 53   $1_ARGS += -KCAS
 54 
 55   ifneq ($$(findstring $$($1_InputType), Byte Short Char Int Long Float Double), )
 56     $1_ARGS += -KAtomicAdd
 57     $1_ARGS += -KNonPlainAccess
 58     $1_ARGS += -KStatic
 59     $1_ARGS += -KArray
 60   endif
 61 
 62   ifneq ($$(findstring $$($1_InputType), Byte Short Char Int Long), )
 63     $1_ARGS += -KBitwise
 64   endif
 65 
 66   ifeq ($$($1_InputType), Boolean)
 67     $1_ARGS += -KBitwise
 68     $1_ARGS += -KNonPlainAccess
 69     $1_ARGS += -KStatic
 70     $1_ARGS += -KArray
 71   endif
 72 
 73   ifneq ($$(findstring $$($1_InputType), Byte Short Char), )
 74     $1_ARGS += -KShorterThanInt
 75   endif
 76 
 77   ifeq ($$($1_InputType), Reference)
 78     $1_ARGS += -KReference
 79     $1_ARGS += -KNonPlainAccess
 80     $1_ARGS += -KStatic
 81     $1_type := Object
 82   endif
 83 
 84   ifeq ($$($1_InputType), NonAtomicReference)
 85       $1_ARGS += -KReference
 86       $1_ARGS += -KStatic
 87       $1_type := Object
 88       $1_Type := Reference
 89   endif
 90 
 91   ifeq ($$($1_InputType), FlatValue)
 92     $1_ARGS += -KFlatValue
 93     $1_ARGS += -KNonPlainAccess
 94     $1_type := Object
 95     $1_Type := FlatValue
 96   endif
 97 
 98   ifeq ($$($1_InputType), NonAtomicFlatValue)
 99     $1_ARGS += -KFlatValue
100     $1_type := Object
101     $1_Type := FlatValue
102   endif
103 
104   $$($1_FILENAME): $(VARHANDLES_SRC_DIR)/X-VarHandle.java.template $(BUILD_TOOLS_JDK)
105         ifeq ($$($1_InputType), Reference)
106 	  $$(eval $1_type := Object)
107 	  $$(eval $1_Type := Reference)
108         else ifeq ($$($1_InputType), NonAtomicReference)
109 	  $$(eval $1_type := Object)
110 	  $$(eval $1_Type := Reference)
111         else ifeq ($$($1_InputType), FlatValue)
112 	  $$(eval $1_type := Object)
113 	  $$(eval $1_Type := FlatValue)
114         else ifeq ($$($1_InputType), NonAtomicFlatValue)
115 	  $$(eval $1_type := Object)
116 	  $$(eval $1_Type := FlatValue)
117         else
118 	  $$(eval $1_type := $$$$($1_type))
119 	  $$(eval $1_Type := $$$$($1_InputType))
120         endif
121 	$$(call MakeDir, $$(@D))
122 	$(RM) $$@
123 	$(TOOL_SPP) -nel -K$$($1_type) -Dtype=$$($1_type) -DType=$$($1_Type) -DInputType=$$($1_InputType) \
124 	    $$($1_ARGS) -i$$< -o$$@
125 
126   GENSRC_VARHANDLES += $$($1_FILENAME)
127 endef
128 
129 ################################################################################
130 
131 ################################################################################
132 # Setup a rule for generating a VarHandleByteArray java class
133 # Param 1 - Variable declaration prefix
134 # Param 2 - Type with first letter capitalized
135 define GenerateVarHandleByteArray
136 
137   $1_Type := $2
138 
139   $1_FILENAME := $(VARHANDLES_GENSRC_DIR)/VarHandleByteArrayAs$$($1_Type)s.java
140 
141   ifeq ($$($1_Type), Short)
142     $1_type := short
143     $1_BoxType := $$($1_Type)
144 
145     $1_rawType := $$($1_type)
146     $1_RawType := $$($1_Type)
147     $1_RawBoxType := $$($1_BoxType)
148   endif
149 
150   ifeq ($$($1_Type), Char)
151     $1_type := char
152     $1_BoxType := Character
153 
154     $1_rawType := $$($1_type)
155     $1_RawType := $$($1_Type)
156     $1_RawBoxType := $$($1_BoxType)
157   endif
158 
159   ifeq ($$($1_Type), Int)
160     $1_type := int
161     $1_BoxType := Integer
162 
163     $1_rawType := $$($1_type)
164     $1_RawType := $$($1_Type)
165     $1_RawBoxType := $$($1_BoxType)
166 
167     $1_ARGS += -KCAS
168     $1_ARGS += -KAtomicAdd
169     $1_ARGS += -KBitwise
170   endif
171 
172   ifeq ($$($1_Type), Long)
173     $1_type := long
174     $1_BoxType := $$($1_Type)
175 
176     $1_rawType := $$($1_type)
177     $1_RawType := $$($1_Type)
178     $1_RawBoxType := $$($1_BoxType)
179 
180     $1_ARGS += -KCAS
181     $1_ARGS += -KAtomicAdd
182     $1_ARGS += -KBitwise
183   endif
184 
185   ifeq ($$($1_Type), Float)
186     $1_type := float
187     $1_BoxType := $$($1_Type)
188 
189     $1_rawType := int
190     $1_RawType := Int
191     $1_RawBoxType := Integer
192 
193     $1_ARGS += -KCAS
194     $1_ARGS += -KfloatingPoint
195   endif
196 
197   ifeq ($$($1_Type), Double)
198     $1_type := double
199     $1_BoxType := $$($1_Type)
200 
201     $1_rawType := long
202     $1_RawType := Long
203     $1_RawBoxType := Long
204 
205     $1_ARGS += -KCAS
206     $1_ARGS += -KfloatingPoint
207   endif
208 
209   $$($1_FILENAME): $(VARHANDLES_SRC_DIR)/X-VarHandleByteArrayView.java.template $(BUILD_TOOLS_JDK)
210 	$$(call MakeDir, $$(@D))
211 	$(RM) $$@
212 	$(TOOL_SPP) -nel -K$$($1_type) \
213 	    -Dtype=$$($1_type) -DType=$$($1_Type) -DBoxType=$$($1_BoxType) \
214 	    -DrawType=$$($1_rawType) -DRawType=$$($1_RawType) -DRawBoxType=$$($1_RawBoxType) \
215 	    $$($1_ARGS) -i$$< -o$$@
216 
217   GENSRC_VARHANDLES += $$($1_FILENAME)
218 endef
219 
220 ################################################################################
221 
222 ################################################################################
223 # Setup a rule for generating a memory segment var handle view class
224 # Param 1 - Variable declaration prefix
225 # Param 2 - Type with first letter capitalized
226 define GenerateVarHandleMemorySegment
227 
228   $1_Type := $2
229 
230   $1_FILENAME := $(VARHANDLES_GENSRC_DIR)/VarHandleSegmentAs$$($1_Type)s.java
231 
232   ifeq ($$($1_Type), Boolean)
233     $1_type := boolean
234     $1_BoxType := $$($1_Type)
235 
236     $1_rawType := $$($1_type)
237     $1_RawType := $$($1_Type)
238     $1_RawBoxType := $$($1_BoxType)
239 
240     $1_ARGS += -Kbyte
241     $1_ARGS += -KShorterThanInt
242   endif
243 
244   ifeq ($$($1_Type), Byte)
245     $1_type := byte
246     $1_BoxType := $$($1_Type)
247 
248     $1_rawType := $$($1_type)
249     $1_RawType := $$($1_Type)
250     $1_RawBoxType := $$($1_BoxType)
251 
252     $1_ARGS += -Kbyte
253     $1_ARGS += -KShorterThanInt
254   endif
255 
256   ifeq ($$($1_Type), Short)
257     $1_type := short
258     $1_BoxType := $$($1_Type)
259 
260     $1_rawType := $$($1_type)
261     $1_RawType := $$($1_Type)
262     $1_RawBoxType := $$($1_BoxType)
263 
264     $1_ARGS += -KShorterThanInt
265   endif
266 
267   ifeq ($$($1_Type), Char)
268     $1_type := char
269     $1_BoxType := Character
270 
271     $1_rawType := $$($1_type)
272     $1_RawType := $$($1_Type)
273     $1_RawBoxType := $$($1_BoxType)
274 
275     $1_ARGS += -KShorterThanInt
276   endif
277 
278   ifeq ($$($1_Type), Int)
279     $1_type := int
280     $1_BoxType := Integer
281 
282     $1_rawType := $$($1_type)
283     $1_RawType := $$($1_Type)
284     $1_RawBoxType := $$($1_BoxType)
285 
286     $1_ARGS += -KCAS
287     $1_ARGS += -KAtomicAdd
288     $1_ARGS += -KBitwise
289   endif
290 
291   ifeq ($$($1_Type), Long)
292     $1_type := long
293     $1_BoxType := $$($1_Type)
294 
295     $1_rawType := $$($1_type)
296     $1_RawType := $$($1_Type)
297     $1_RawBoxType := $$($1_BoxType)
298 
299     $1_ARGS += -KCAS
300     $1_ARGS += -KAtomicAdd
301     $1_ARGS += -KBitwise
302   endif
303 
304   ifeq ($$($1_Type), Float)
305     $1_type := float
306     $1_BoxType := $$($1_Type)
307 
308     $1_rawType := int
309     $1_RawType := Int
310     $1_RawBoxType := Integer
311 
312     $1_ARGS += -KCAS
313     $1_ARGS += -KfloatingPoint
314   endif
315 
316   ifeq ($$($1_Type), Double)
317     $1_type := double
318     $1_BoxType := $$($1_Type)
319 
320     $1_rawType := long
321     $1_RawType := Long
322     $1_RawBoxType := Long
323 
324     $1_ARGS += -KCAS
325     $1_ARGS += -KfloatingPoint
326   endif
327 
328   $$($1_FILENAME): $(VARHANDLES_SRC_DIR)/X-VarHandleSegmentView.java.template $(BUILD_TOOLS_JDK)
329 	$$(call MakeDir, $$(@D))
330 	$(RM) $$@
331 	$(TOOL_SPP) -nel -K$$($1_type) \
332 	    -Dtype=$$($1_type) -DType=$$($1_Type) -DBoxType=$$($1_BoxType) \
333 	    -DrawType=$$($1_rawType) -DRawType=$$($1_RawType) -DRawBoxType=$$($1_RawBoxType) \
334 	    $$($1_ARGS) -i$$< -o$$@
335 
336   GENSRC_VARHANDLES += $$($1_FILENAME)
337 endef
338 
339 ################################################################################
340 
341 # List the types to generate source for, with capitalized first letter
342 VARHANDLES_TYPES := Boolean Byte Short Char Int Long Float Double Reference FlatValue NonAtomicReference NonAtomicFlatValue
343 $(foreach t, $(VARHANDLES_TYPES), \
344   $(eval $(call GenerateVarHandle,VAR_HANDLE_$t,$t)))
345 
346 # List the types to generate source for, with capitalized first letter
347 VARHANDLES_BYTE_ARRAY_TYPES := Short Char Int Long Float Double
348 $(foreach t, $(VARHANDLES_BYTE_ARRAY_TYPES), \
349   $(eval $(call GenerateVarHandleByteArray,VAR_HANDLE_BYTE_ARRAY_$t,$t)))
350 
351 # List the types to generate source for, with capitalized first letter
352 VARHANDLES_MEMORY_SEGMENT_TYPES := Boolean Byte Short Char Int Long Float Double
353 $(foreach t, $(VARHANDLES_MEMORY_SEGMENT_TYPES), \
354   $(eval $(call GenerateVarHandleMemorySegment,VAR_HANDLE_MEMORY_SEGMENT_$t,$t)))
355 
356 TARGETS += $(GENSRC_VARHANDLES)
357 
358 ################################################################################
359 
360 GENSRC_VARHANDLEGUARDS := $(VARHANDLES_OUTPUT_DIR)/VarHandleGuards.java
361 
362 $(GENSRC_VARHANDLEGUARDS): $(BUILD_TOOLS_JDK)
363 	$(call LogInfo, Generating $@)
364 	$(call MakeTargetDir)
365 	$(TOOL_VARHANDLEGUARDMETHODGENERATOR) \
366 	    $(GENSRC_VARHANDLEGUARDS)
367 
368 TARGETS += $(GENSRC_VARHANDLEGUARDS)
369 
370 ################################################################################
371 
372 endif # include guard
373 include MakeIncludeEnd.gmk