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 # Setup a rule for generating a VarHandle java class
 36 #
 37 # arg $1: type for this varhandle
 38 define GenerateVarHandle
 39   VARHANDLE_$1_type := $$(strip $$(if $$(filter reference, $1), Object, $1))
 40   VARHANDLE_$1_Type := $$(call Conv, $1, Type)
 41 
 42   $1_KEYS := $$(VARHANDLE_$1_type) CAS
 43   ifneq ($$(filter byte short char, $1),)
 44     $1_KEYS += ShorterThanInt
 45   endif
 46   ifeq ($$(filter boolean reference, $1),)
 47     $1_KEYS += AtomicAdd
 48   endif
 49   ifeq ($$(filter float double reference, $1),)
 50     $1_KEYS += Bitwise
 51   endif
 52 
 53   $$(eval $$(call SetupStreamPreProcessing, GEN_VARHANDLE_$1, \
 54       SOURCE_FILE := $$(VARHANDLES_INPUT_DIR)/X-VarHandle.java.template, \
 55       OUTPUT_FILE := $$(VARHANDLES_OUTPUT_DIR)/VarHandle$$(VARHANDLE_$1_Type)s.java, \
 56       INFO := Generating VarHandle class for $1, \
 57       SUBST_EMPTY_LINES := false, \
 58       KEYS := $$($1_KEYS), \
 59       REPLACEMENTS := \
 60           type=$$(VARHANDLE_$1_type) \
 61           Type=$$(VARHANDLE_$1_Type), \
 62   ))
 63   TARGETS += $$(GEN_VARHANDLE_$1)
 64 endef
 65 
 66 ################################################################################
 67 # Setup a rule for generating a VarHandleByteArray java class
 68 #
 69 # arg $1: type for this varhandle
 70 define GenerateVarHandleByteArray
 71   VARHANDLE_BYTEARRAY_$1_Type := $$(call Conv, $1, Type)
 72 
 73   $1_KEYS := $1
 74   ifneq ($$(filter int long float double, $1),)
 75     $1_KEYS += CAS
 76   endif
 77   ifneq ($$(filter float double, $1),)
 78     $1_KEYS += floatingPoint
 79   endif
 80   ifneq ($$(filter int long, $1),)
 81     $1_KEYS += AtomicAdd Bitwise
 82   endif
 83 
 84   $$(eval $$(call SetupStreamPreProcessing, GEN_VARHANDLE_BYTEARRAY_$1, \
 85       SOURCE_FILE := $$(VARHANDLES_INPUT_DIR)/X-VarHandleByteArrayView.java.template, \
 86       OUTPUT_FILE := $$(VARHANDLES_OUTPUT_DIR)/VarHandleByteArrayAs$$(VARHANDLE_BYTEARRAY_$1_Type)s.java, \
 87       INFO := Generating VarHandleByteArray class for $1, \
 88       SUBST_EMPTY_LINES := false, \
 89       KEYS := $$($1_KEYS), \
 90       REPLACEMENTS := \
 91           type=$1 \
 92           Type=$$(VARHANDLE_BYTEARRAY_$1_Type) \
 93           BoxType=$$(call Conv, $1, Fulltype) \
 94           rawType=$$(call Conv, $1, memtype) \
 95           RawType=$$(call Conv, $1, Memtype) \
 96           RawBoxType=$$(call Conv, $1, FullMemtype), \
 97   ))
 98   TARGETS += $$(GEN_VARHANDLE_BYTEARRAY_$1)
 99 endef
100 
101 ################################################################################
102 # Setup a rule for generating a VarHandleMemorySegment java class
103 #
104 # arg $1: type for this varhandle
105 define GenerateVarHandleMemorySegment
106   VARHANDLE_SEGMENT_$1_Type := $$(call Conv, $1, Type)
107 
108 
109   $1_KEYS := $1
110   ifneq ($$(filter int long float double, $1),)
111     $1_KEYS += CAS
112   endif
113   ifneq ($$(filter boolean byte, $1),)
114     $1_KEYS += byte
115   endif
116   ifneq ($$(filter float double, $1),)
117     $1_KEYS += floatingPoint
118   endif
119   ifneq ($$(filter boolean byte short char, $1),)
120     $1_KEYS += ShorterThanInt
121   endif
122   ifneq ($$(filter int long, $1),)
123     $1_KEYS += AtomicAdd Bitwise
124   endif
125 
126   $$(eval $$(call SetupStreamPreProcessing, GEN_VARHANDLE_SEGMENT_$1, \
127       SOURCE_FILE := $$(VARHANDLES_INPUT_DIR)/X-VarHandleSegmentView.java.template, \
128       OUTPUT_FILE := $$(VARHANDLES_OUTPUT_DIR)/VarHandleSegmentAs$$(VARHANDLE_SEGMENT_$1_Type)s.java, \
129       INFO := Generating VarHandleSegment class for $1, \
130       SUBST_EMPTY_LINES := false, \
131       KEYS := $$($1_KEYS), \
132       REPLACEMENTS := \
133           type=$1 \
134           Type=$$(VARHANDLE_SEGMENT_$1_Type) \
135           BoxType=$$(call Conv, $1, Fulltype) \
136           rawType=$$(call Conv, $1, memtype) \
137           RawType=$$(call Conv, $1, Memtype) \
138           RawBoxType=$$(call Conv, $1, FullMemtype), \
139   ))
140   TARGETS += $$(GEN_VARHANDLE_SEGMENT_$1)
141 endef
142 
143 ################################################################################
144 # Generate all VarHandle related classes
145 
146 $(foreach t, $(PRIMITIVE_TYPES) reference, \
147   $(eval $(call GenerateVarHandle,$t)) \
148 )
149 
150 $(foreach t, $(NON_BYTE_NUMBER_TYPES), \
151   $(eval $(call GenerateVarHandleByteArray,$t)) \
152 )
153 
154 $(foreach t, $(PRIMITIVE_TYPES), \
155   $(eval $(call GenerateVarHandleMemorySegment,$t)) \
156 )
157 
158 ################################################################################
159 
160 GENSRC_VARHANDLEGUARDS := $(VARHANDLES_OUTPUT_DIR)/VarHandleGuards.java
161 
162 $(GENSRC_VARHANDLEGUARDS): $(BUILD_TOOLS_JDK)
163 	$(call LogInfo, Generating $@)
164 	$(call MakeTargetDir)
165 	$(TOOL_VARHANDLEGUARDMETHODGENERATOR) \
166 	    $(GENSRC_VARHANDLEGUARDS)
167 
168 TARGETS += $(GENSRC_VARHANDLEGUARDS)
169 
170 ################################################################################
171 
172 endif # include guard
173 include MakeIncludeEnd.gmk