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