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