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