View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   https://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.bcel.verifier.tests;
21  
22  import org.apache.bcel.generic.DNEG;
23  import org.apache.bcel.generic.DREM;
24  import org.apache.bcel.generic.DUP2;
25  import org.apache.bcel.generic.DUP2_X1;
26  import org.apache.bcel.generic.DUP2_X2;
27  import org.apache.bcel.generic.DUP_X2;
28  import org.apache.bcel.generic.FADD;
29  import org.apache.bcel.generic.FNEG;
30  import org.apache.bcel.generic.FREM;
31  import org.apache.bcel.generic.FSUB;
32  import org.apache.bcel.generic.IUSHR;
33  import org.apache.bcel.generic.LAND;
34  import org.apache.bcel.generic.LNEG;
35  import org.apache.bcel.generic.LOR;
36  import org.apache.bcel.generic.LSHL;
37  import org.apache.bcel.generic.LUSHR;
38  import org.apache.bcel.generic.POP;
39  import org.apache.bcel.generic.POP2;
40  
41  /*
42   * A selection of JVM opcodes, each one in a minimal method.
43   */
44  public class JvmOpCodes {
45  
46      long l1;
47      long l2;
48  
49      /**
50       * Tests {@link DNEG}.
51       */
52      double dneg(final double a) {
53          return -a;
54      }
55  
56      /**
57       * Tests {@link DREM}.
58       */
59      double drem(final double a, final double b) {
60          return a % b;
61      }
62  
63      /**
64       * Tests {@link DUP2}.
65       */
66      long dup2(long a) {
67          return a++;
68      }
69  
70      /**
71       * Tests {@link DUP2_X1}.
72       */
73      void dup2x1(final String[] s) {
74          s[0] += "s"; // Form 1
75          l2 = l1 = 1; // Form 2
76      }
77  
78      /**
79       * Tests {@link DUP2_X2}.
80       */
81      long dup2x2(final long[] array, final int i, final long l) {
82          return array[i] = l;
83      }
84  
85      /**
86       * Tests {@link DUP_X2}.
87       */
88      int dupx2(final int[] array, final int i, final int l) {
89          return array[i] = l;
90      }
91  
92      /**
93       * Tests {@link FADD}.
94       */
95      float fadd(final float a, final float b) {
96          return a + b;
97      }
98  
99      /**
100      * Tests {@link FNEG}.
101      */
102     float fneg(final float a) {
103         return -a;
104     }
105 
106     /**
107      * Tests {@link FREM}.
108      */
109     float frem(final float a, final float b) {
110         return a % b;
111     }
112 
113     /**
114      * Tests {@link FSUB}.
115      */
116     float fsub(final float a, final float b) {
117         return a - b;
118     }
119 
120     /**
121      * Tests {@link IUSHR}.
122      */
123     int iushr(final int a, final int b) {
124         return a >>> b;
125     }
126 
127     /**
128      * Tests {@link LAND}.
129      */
130     long land(final long a, final long b) {
131         return a & b;
132     }
133 
134     /**
135      * Tests {@link LNEG}.
136      */
137     long lneg(final long a) {
138         return -a;
139     }
140 
141     /**
142      * Tests {@link LOR}.
143      */
144     long lor(final long a, final long b) {
145         return a | b;
146     }
147 
148     /**
149      * Tests {@link LSHL}.
150      */
151     long lshl(final long a, final long b) {
152         return a << b;
153     }
154 
155     /**
156      * Tests {@link LUSHR}.
157      */
158     long lushr(final long a, final long b) {
159         return a >>> b;
160     }
161 
162     /**
163      * Tests {@link POP}.
164      */
165     void pop() {
166         Math.round(0.5f);
167     }
168 
169     /**
170      * Tests {@link POP2}.
171      */
172     void pop2() {
173         Math.round(0.5d);
174     }
175 }