1 #!/bin/bash
  2 
  3 javac -d . ../../../../../../make/jdk/src/classes/build/tools/spp/Spp.java
  4 
  5 SPP=build.tools.spp.Spp
  6 
  7 # Generates variable handle tests for objects and all primitive types
  8 # This is likely to be a temporary testing approach as it may be more
  9 # desirable to generate code using ASM which will allow more flexibility
 10 # in the kinds of tests that are generated.
 11 
 12 for type in boolean byte short char int long float double String Value
 13 do
 14   Type="$(tr '[:lower:]' '[:upper:]' <<< ${type:0:1})${type:1}"
 15   args="-K$type -Dtype=$type -DType=$Type"
 16 
 17   args="$args -KCAS"
 18 
 19   case $type in
 20     byte|short|char|int|long|float|double)
 21       args="$args -KAtomicAdd"
 22       ;;
 23   esac
 24 
 25   case $type in
 26     boolean|byte|short|char|int|long)
 27       args="$args -KBitwise"
 28       ;;
 29   esac
 30 
 31  # Object = objects of identity or value class
 32  # Value = value class 
 33   case $type in
 34     String)
 35       args="$args -KObject"
 36       ;;
 37     Value)
 38       args="$args -KObject -KValue"
 39       ;;
 40   esac
 41 
 42   wrong_primitive_type=boolean
 43 
 44   case $type in
 45     boolean)
 46       value1=true
 47       value2=false
 48       value3=false
 49       wrong_primitive_type=int
 50       ;;
 51     byte)
 52       value1=(byte)0x01
 53       value2=(byte)0x23
 54       value3=(byte)0x45
 55       ;;
 56     short)
 57       value1=(short)0x0123
 58       value2=(short)0x4567
 59       value3=(short)0x89AB
 60       ;;
 61     char)
 62       value1=\'\\\\u0123\'
 63       value2=\'\\\\u4567\'
 64       value3=\'\\\\u89AB\'
 65       ;;
 66     int)
 67       value1=0x01234567
 68       value2=0x89ABCDEF
 69       value3=0xCAFEBABE
 70       ;;
 71     long)
 72       value1=0x0123456789ABCDEFL
 73       value2=0xCAFEBABECAFEBABEL
 74       value3=0xDEADBEEFDEADBEEFL
 75       ;;
 76     float)
 77       value1=1.0f
 78       value2=2.0f
 79       value3=3.0f
 80       ;;
 81     double)
 82       value1=1.0d
 83       value2=2.0d
 84       value3=3.0d
 85       ;;
 86     String)
 87       value1=\"foo\"
 88       value2=\"bar\"
 89       value3=\"baz\"
 90       ;;
 91     Value)
 92       value1="Value.getInstance(10)"
 93       value2="Value.getInstance(20)"
 94       value3="Value.getInstance(30)"
 95       ;;
 96   esac
 97 
 98   args="$args -Dvalue1=$value1 -Dvalue2=$value2 -Dvalue3=$value3 -Dwrong_primitive_type=$wrong_primitive_type"
 99 
100   echo $args
101   out=VarHandleTestAccess${Type}.java
102   rm -f $out
103   java $SPP -nel $args -iX-VarHandleTestAccess.java.template -o$out
104   out=VarHandleTestMethodHandleAccess${Type}.java
105   rm -f $out
106   java $SPP -nel $args -iX-VarHandleTestMethodHandleAccess.java.template -o$out
107   out=VarHandleTestMethodType${Type}.java
108   rm -f $out
109   java $SPP -nel $args -iX-VarHandleTestMethodType.java.template -o$out
110 done
111 
112 for type in short char int long float double
113 do
114   Type="$(tr '[:lower:]' '[:upper:]' <<< ${type:0:1})${type:1}"
115   args="-K$type -Dtype=$type -DType=$Type"
116 
117   BoxType=$Type
118   case $type in
119     char)
120       BoxType=Character
121       ;;
122     int)
123       BoxType=Integer
124       ;;
125   esac
126   args="$args -DBoxType=$BoxType"
127 
128   case $type in
129     int|long|float|double)
130       args="$args -KCAS"
131       ;;
132   esac
133 
134   case $type in
135     int|long)
136       args="$args -KAtomicAdd"
137       ;;
138   esac
139 
140   case $type in
141     int|long)
142       args="$args -KBitwise"
143       ;;
144   esac
145 
146   # The value of `value3` is chosen such that when added to `value1` or `value2`
147   # it will result in carrying of bits over to the next byte, thereby detecting
148   # possible errors in endianness conversion e.g. if say for atomic addition the
149   # augend is incorrectly processed
150   case $type in
151     short)
152       value1=(short)0x0102
153       value2=(short)0x1112
154       value3=(short)0xFFFE
155       ;;
156     char)
157       value1=(char)0x0102
158       value2=(char)0x1112
159       value3=(char)0xFFFE
160       ;;
161     int)
162       value1=0x01020304
163       value2=0x11121314
164       value3=0xFFFEFDFC
165       ;;
166     long)
167       value1=0x0102030405060708L
168       value2=0x1112131415161718L
169       value3=0xFFFEFDFCFBFAF9F8L
170       ;;
171     float)
172       value1=0x01020304
173       value2=0x11121314
174       value3=0xFFFEFDFC
175       ;;
176     double)
177       value1=0x0102030405060708L
178       value2=0x1112131415161718L
179       value3=0xFFFEFDFCFBFAF9F8L
180       ;;
181   esac
182 
183   args="$args -Dvalue1=$value1 -Dvalue2=$value2 -Dvalue3=$value3"
184 
185   echo $args
186   out=VarHandleTestByteArrayAs${Type}.java
187   rm -f $out
188   java $SPP -nel $args -iX-VarHandleTestByteArrayView.java.template -o$out
189 done
190 
191 rm -fr build