1#!/bin/bash
2
3#
4# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
5# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6#
7# This code is free software; you can redistribute it and/or modify it
8# under the terms of the GNU General Public License version 2 only, as
9# published by the Free Software Foundation.
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
26javac -d . ../../../../jdk/make/src/classes/build/tools/spp/Spp.java
27
28SPP=build.tools.spp.Spp
29
30# Generates unsafe access tests for objects and all primitive types
31# $1 = package name to Unsafe, sun.misc | jdk.internal.misc
32# $2 = test class qualifier name, SunMisc | JdkInternalMisc
33# $3 = module name containing the Unsafe class, for @modules
34function generate {
35    package=$1
36    Qualifier=$2
37    module=$3
38
39    for type in boolean byte short char int long float double Object
40    do
41      Type="$(tr '[:lower:]' '[:upper:]' <<< ${type:0:1})${type:1}"
42      args="-K$type -Dtype=$type -DType=$Type"
43
44      case $type in
45        Object|int|long)
46          args="$args -KCAS -KOrdered"
47          ;;
48      esac
49
50      case $type in
51        int|long)
52          args="$args -KAtomicAdd"
53          ;;
54      esac
55
56      if [ "$package" == "jdk.internal.misc" ]; then
57        case $type in
58          boolean|byte|char|short|float|double)
59            args="$args -KCAS"
60            ;;
61        esac
62        case $type in
63          byte|char|short|float|double)
64            args="$args -KAtomicAdd"
65            ;;
66        esac
67      fi
68
69      case $type in
70        short|char|int|long)
71          args="$args -KUnaligned"
72          ;;
73      esac
74
75      case $type in
76        boolean)
77          value1=true
78          value2=false
79          value3=false
80          ;;
81        byte)
82          value1=(byte)0x01
83          value2=(byte)0x23
84          value3=(byte)0x45
85          ;;
86        short)
87          value1=(short)0x0123
88          value2=(short)0x4567
89          value3=(short)0x89AB
90          ;;
91        char)
92          value1=\'\\\\u0123\'
93          value2=\'\\\\u4567\'
94          value3=\'\\\\u89AB\'
95          ;;
96        int)
97          value1=0x01234567
98          value2=0x89ABCDEF
99          value3=0xCAFEBABE
100          ;;
101        long)
102          value1=0x0123456789ABCDEFL
103          value2=0xCAFEBABECAFEBABEL
104          value3=0xDEADBEEFDEADBEEFL
105          ;;
106        float)
107          value1=1.0f
108          value2=2.0f
109          value3=3.0f
110          ;;
111        double)
112          value1=1.0d
113          value2=2.0d
114          value3=3.0d
115          ;;
116        Object)
117          value1=\"foo\"
118          value2=\"bar\"
119          value3=\"baz\"
120          ;;
121      esac
122
123      args="$args -Dvalue1=$value1 -Dvalue2=$value2 -Dvalue3=$value3"
124
125      echo $args
126      java $SPP -nel -K$Qualifier -Dpackage=$package -DQualifier=$Qualifier -Dmodule=$module \
127          $args < X-UnsafeAccessTest.java.template > ${Qualifier}UnsafeAccessTest${Type}.java
128    done
129}
130
131generate sun.misc SunMisc jdk.unsupported
132generate jdk.internal.misc JdkInternalMisc java.base
133
134rm -fr build
135