1 package org.apache.bcel.verifier.structurals;
2
3 /* ====================================================================
4 * The Apache Software License, Version 1.1
5 *
6 * Copyright (c) 2001 The Apache Software Foundation. All rights
7 * reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. The end-user documentation included with the redistribution,
22 * if any, must include the following acknowledgment:
23 * "This product includes software developed by the
24 * Apache Software Foundation (http://www.apache.org/)."
25 * Alternately, this acknowledgment may appear in the software itself,
26 * if and wherever such third-party acknowledgments normally appear.
27 *
28 * 4. The names "Apache" and "Apache Software Foundation" and
29 * "Apache BCEL" must not be used to endorse or promote products
30 * derived from this software without prior written permission. For
31 * written permission, please contact apache@apache.org.
32 *
33 * 5. Products derived from this software may not be called "Apache",
34 * "Apache BCEL", nor may "Apache" appear in their name, without
35 * prior written permission of the Apache Software Foundation.
36 *
37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48 * SUCH DAMAGE.
49 * ====================================================================
50 *
51 * This software consists of voluntary contributions made by many
52 * individuals on behalf of the Apache Software Foundation. For more
53 * information on the Apache Software Foundation, please see
54 * <http://www.apache.org/>.
55 */
56
57 import org.apache.bcel.Constants;
58 import org.apache.bcel.Repository;
59 import org.apache.bcel.generic.*;
60 import org.apache.bcel.classfile.JavaClass;
61 import org.apache.bcel.classfile.Constant;
62 import org.apache.bcel.classfile.ConstantDouble;
63 import org.apache.bcel.classfile.ConstantFloat;
64 import org.apache.bcel.classfile.ConstantInteger;
65 import org.apache.bcel.classfile.ConstantLong;
66 import org.apache.bcel.classfile.ConstantString;
67 import org.apache.bcel.verifier.Verifier;
68 import org.apache.bcel.verifier.exc.*;
69 import java.util.ArrayList;
70 import java.util.Hashtable;
71
72 /***
73 * This Visitor class may be used for a type-based Java Virtual Machine
74 * simulation.
75 * It does not check for correct types on the OperandStack or in the
76 * LocalVariables; nor does it check their sizes are sufficiently big.
77 * Thus, to use this Visitor for bytecode verifying, you have to make sure
78 * externally that the type constraints of the Java Virtual Machine instructions
79 * are satisfied. An InstConstraintVisitor may be used for this.
80 * Anyway, this Visitor does not mandate it. For example, when you
81 * visitIADD(IADD o), then there are two stack slots popped and one
82 * stack slot containing a Type.INT is pushed (where you could also
83 * pop only one slot if you know there are two Type.INT on top of the
84 * stack). Monitor-specific behaviour is not simulated.
85 *
86 * </P><B>Conventions:</B>
87 *
88 * Type.VOID will never be pushed onto the stack. Type.DOUBLE and Type.LONG
89 * that would normally take up two stack slots (like Double_HIGH and
90 * Double_LOW) are represented by a simple single Type.DOUBLE or Type.LONG
91 * object on the stack here.
92 * If a two-slot type is stored into a local variable, the next variable
93 * is given the type Type.UNKNOWN.
94 *
95 * @version $Id: ExecutionVisitor.java,v 1.1.1.1 2001/10/29 20:00:39 jvanzyl Exp $
96 * @author <A HREF="http://www.inf.fu-berlin.de/~ehaase"/>Enver Haase</A>
97 * @see #visitDSTORE(DSTORE o)
98 * @see InstConstraintVisitor
99 */
100 public class ExecutionVisitor extends EmptyVisitor implements Visitor{
101
102 /***
103 * The executionframe we're operating on.
104 */
105 private Frame frame = null;
106
107 /***
108 * The ConstantPoolGen we're working with.
109 * @see #setConstantPoolGen(ConstantPoolGen)
110 */
111 private ConstantPoolGen cpg = null;
112
113 /***
114 * Constructor. Constructs a new instance of this class.
115 */
116 public ExecutionVisitor(){}
117
118 /***
119 * The OperandStack from the current Frame we're operating on.
120 * @see #setFrame(Frame)
121 */
122 private OperandStack stack(){
123 return frame.getStack();
124 }
125
126 /***
127 * The LocalVariables from the current Frame we're operating on.
128 * @see #setFrame(Frame)
129 */
130 private LocalVariables locals(){
131 return frame.getLocals();
132 }
133
134 /***
135 * Sets the ConstantPoolGen needed for symbolic execution.
136 */
137 public void setConstantPoolGen(ConstantPoolGen cpg){
138 this.cpg = cpg;
139 }
140
141 /***
142 * The only method granting access to the single instance of
143 * the ExecutionVisitor class. Before actively using this
144 * instance, <B>SET THE ConstantPoolGen FIRST</B>.
145 * @see #setConstantPoolGen(ConstantPoolGen)
146 */
147 public void setFrame(Frame f){
148 this.frame = f;
149 }
150
151 ///*** Symbolically executes the corresponding Java Virtual Machine instruction. */
152 //public void visitWIDE(WIDE o){
153 // The WIDE instruction is modelled as a flag
154 // of the embedded instructions in BCEL.
155 // Therefore BCEL checks for possible errors
156 // when parsing in the .class file: We don't
157 // have even the possibilty to care for WIDE
158 // here.
159 //}
160
161 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
162 public void visitAALOAD(AALOAD o){
163 stack().pop(); // pop the index int
164 //System.out.print(stack().peek());
165 Type t = stack().pop(); // Pop Array type
166 if (t == Type.NULL){
167 stack().push(Type.NULL);
168 } // Do nothing stackwise --- a NullPointerException is thrown at Run-Time
169 else{
170 ArrayType at = (ArrayType) t;
171 stack().push(at.getElementType());
172 }
173 }
174 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
175 public void visitAASTORE(AASTORE o){
176 stack().pop();
177 stack().pop();
178 stack().pop();
179 }
180 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
181 public void visitACONST_NULL(ACONST_NULL o){
182 stack().push(Type.NULL);
183 }
184 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
185 public void visitALOAD(ALOAD o){
186 stack().push(locals().get(o.getIndex()));
187 }
188 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
189 public void visitANEWARRAY(ANEWARRAY o){
190 stack().pop(); //count
191 stack().push( new ArrayType(o.getType(cpg), 1) );
192 }
193 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
194 public void visitARETURN(ARETURN o){
195 stack().pop();
196 }
197 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
198 public void visitARRAYLENGTH(ARRAYLENGTH o){
199 stack().pop();
200 stack().push(Type.INT);
201 }
202
203 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
204 public void visitASTORE(ASTORE o){
205 locals().set(o.getIndex(), stack().pop());
206 //System.err.println("TODO-DEBUG: set LV '"+o.getIndex()+"' to '"+locals().get(o.getIndex())+"'.");
207 }
208
209 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
210 public void visitATHROW(ATHROW o){
211 Type t = stack().pop();
212 stack().clear();
213 if (t.equals(Type.NULL))
214 stack().push(Type.getType("Ljava/lang/NullPointerException;"));
215 else
216 stack().push(t);
217 }
218
219 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
220 public void visitBALOAD(BALOAD o){
221 stack().pop();
222 stack().pop();
223 stack().push(Type.INT);
224 }
225
226 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
227 public void visitBASTORE(BASTORE o){
228 stack().pop();
229 stack().pop();
230 stack().pop();
231 }
232
233 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
234 public void visitBIPUSH(BIPUSH o){
235 stack().push(Type.INT);
236 }
237
238 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
239 public void visitCALOAD(CALOAD o){
240 stack().pop();
241 stack().pop();
242 stack().push(Type.INT);
243 }
244 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
245 public void visitCASTORE(CASTORE o){
246 stack().pop();
247 stack().pop();
248 stack().pop();
249 }
250 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
251 public void visitCHECKCAST(CHECKCAST o){
252 // It's possibly wrong to do so, but SUN's
253 // ByteCode verifier seems to do (only) this, too.
254 // TODO: One could use a sophisticated analysis here to check
255 // if a type cannot possibly be cated to another and by
256 // so doing predict the ClassCastException at run-time.
257 stack().pop();
258 stack().push(o.getType(cpg));
259 }
260
261 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
262 public void visitD2F(D2F o){
263 stack().pop();
264 stack().push(Type.FLOAT);
265 }
266 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
267 public void visitD2I(D2I o){
268 stack().pop();
269 stack().push(Type.INT);
270 }
271 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
272 public void visitD2L(D2L o){
273 stack().pop();
274 stack().push(Type.LONG);
275 }
276 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
277 public void visitDADD(DADD o){
278 stack().pop();
279 stack().pop();
280 stack().push(Type.DOUBLE);
281 }
282 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
283 public void visitDALOAD(DALOAD o){
284 stack().pop();
285 stack().pop();
286 stack().push(Type.DOUBLE);
287 }
288 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
289 public void visitDASTORE(DASTORE o){
290 stack().pop();
291 stack().pop();
292 stack().pop();
293 }
294 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
295 public void visitDCMPG(DCMPG o){
296 stack().pop();
297 stack().pop();
298 stack().push(Type.INT);
299 }
300 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
301 public void visitDCMPL(DCMPL o){
302 stack().pop();
303 stack().pop();
304 stack().push(Type.INT);
305 }
306 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
307 public void visitDCONST(DCONST o){
308 stack().push(Type.DOUBLE);
309 }
310 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
311 public void visitDDIV(DDIV o){
312 stack().pop();
313 stack().pop();
314 stack().push(Type.DOUBLE);
315 }
316 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
317 public void visitDLOAD(DLOAD o){
318 stack().push(Type.DOUBLE);
319 }
320 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
321 public void visitDMUL(DMUL o){
322 stack().pop();
323 stack().pop();
324 stack().push(Type.DOUBLE);
325 }
326 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
327 public void visitDNEG(DNEG o){
328 stack().pop();
329 stack().push(Type.DOUBLE);
330 }
331 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
332 public void visitDREM(DREM o){
333 stack().pop();
334 stack().pop();
335 stack().push(Type.DOUBLE);
336 }
337 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
338 public void visitDRETURN(DRETURN o){
339 stack().pop();
340 }
341 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
342 public void visitDSTORE(DSTORE o){
343 locals().set(o.getIndex(), stack().pop());
344 locals().set(o.getIndex()+1, Type.UNKNOWN);
345 }
346 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
347 public void visitDSUB(DSUB o){
348 stack().pop();
349 stack().pop();
350 stack().push(Type.DOUBLE);
351 }
352 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
353 public void visitDUP(DUP o){
354 Type t = stack().pop();
355 stack().push(t);
356 stack().push(t);
357 }
358 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
359 public void visitDUP_X1(DUP_X1 o){
360 Type w1 = stack().pop();
361 Type w2 = stack().pop();
362 stack().push(w1);
363 stack().push(w2);
364 stack().push(w1);
365 }
366 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
367 public void visitDUP_X2(DUP_X2 o){
368 Type w1 = stack().pop();
369 Type w2 = stack().pop();
370 if (w2.getSize() == 2){
371 stack().push(w1);
372 stack().push(w2);
373 stack().push(w1);
374 }
375 else{
376 Type w3 = stack().pop();
377 stack().push(w1);
378 stack().push(w3);
379 stack().push(w2);
380 stack().push(w1);
381 }
382 }
383 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
384 public void visitDUP2(DUP2 o){
385 Type t = stack().pop();
386 if (t.getSize() == 2){
387 stack().push(t);
388 stack().push(t);
389 }
390 else{ // t.getSize() is 1
391 Type u = stack().pop();
392 stack().push(u);
393 stack().push(t);
394 stack().push(u);
395 stack().push(t);
396 }
397 }
398 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
399 public void visitDUP2_X1(DUP2_X1 o){
400 Type t = stack().pop();
401 if (t.getSize() == 2){
402 Type u = stack().pop();
403 stack().push(t);
404 stack().push(u);
405 stack().push(t);
406 }
407 else{ //t.getSize() is1
408 Type u = stack().pop();
409 Type v = stack().pop();
410 stack().push(u);
411 stack().push(t);
412 stack().push(v);
413 stack().push(u);
414 stack().push(t);
415 }
416 }
417 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
418 public void visitDUP2_X2(DUP2_X2 o){
419 Type t = stack().pop();
420 if (t.getSize() == 2){
421 Type u = stack().pop();
422 if (u.getSize() == 2){
423 stack().push(t);
424 stack().push(u);
425 stack().push(t);
426 }else{
427 Type v = stack().pop();
428 stack().push(t);
429 stack().push(v);
430 stack().push(u);
431 stack().push(t);
432 }
433 }
434 else{ //t.getSize() is 1
435 Type u = stack().pop();
436 Type v = stack().pop();
437 if (v.getSize() == 2){
438 stack().push(u);
439 stack().push(t);
440 stack().push(v);
441 stack().push(u);
442 stack().push(t);
443 }else{
444 Type w = stack().pop();
445 stack().push(u);
446 stack().push(t);
447 stack().push(w);
448 stack().push(v);
449 stack().push(u);
450 stack().push(t);
451 }
452 }
453 }
454 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
455 public void visitF2D(F2D o){
456 stack().pop();
457 stack().push(Type.DOUBLE);
458 }
459 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
460 public void visitF2I(F2I o){
461 stack().pop();
462 stack().push(Type.INT);
463 }
464 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
465 public void visitF2L(F2L o){
466 stack().pop();
467 stack().push(Type.LONG);
468 }
469 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
470 public void visitFADD(FADD o){
471 stack().pop();
472 stack().pop();
473 stack().push(Type.FLOAT);
474 }
475 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
476 public void visitFALOAD(FALOAD o){
477 stack().pop();
478 stack().pop();
479 stack().push(Type.FLOAT);
480 }
481 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
482 public void visitFASTORE(FASTORE o){
483 stack().pop();
484 stack().pop();
485 stack().pop();
486 }
487 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
488 public void visitFCMPG(FCMPG o){
489 stack().pop();
490 stack().pop();
491 stack().push(Type.INT);
492 }
493 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
494 public void visitFCMPL(FCMPL o){
495 stack().pop();
496 stack().pop();
497 stack().push(Type.INT);
498 }
499 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
500 public void visitFCONST(FCONST o){
501 stack().push(Type.FLOAT);
502 }
503 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
504 public void visitFDIV(FDIV o){
505 stack().pop();
506 stack().pop();
507 stack().push(Type.FLOAT);
508 }
509 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
510 public void visitFLOAD(FLOAD o){
511 stack().push(Type.FLOAT);
512 }
513 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
514 public void visitFMUL(FMUL o){
515 stack().pop();
516 stack().pop();
517 stack().push(Type.FLOAT);
518 }
519 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
520 public void visitFNEG(FNEG o){
521 stack().pop();
522 stack().push(Type.FLOAT);
523 }
524 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
525 public void visitFREM(FREM o){
526 stack().pop();
527 stack().pop();
528 stack().push(Type.FLOAT);
529 }
530 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
531 public void visitFRETURN(FRETURN o){
532 stack().pop();
533 }
534 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
535 public void visitFSTORE(FSTORE o){
536 locals().set(o.getIndex(), stack().pop());
537 }
538 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
539 public void visitFSUB(FSUB o){
540 stack().pop();
541 stack().pop();
542 stack().push(Type.FLOAT);
543 }
544 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
545 public void visitGETFIELD(GETFIELD o){
546 stack().pop();
547 Type t = o.getFieldType(cpg);
548 if ( t.equals(Type.BOOLEAN) ||
549 t.equals(Type.CHAR) ||
550 t.equals(Type.BYTE) ||
551 t.equals(Type.SHORT) )
552 t = Type.INT;
553 stack().push(t);
554 }
555 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
556 public void visitGETSTATIC(GETSTATIC o){
557 Type t = o.getFieldType(cpg);
558 if ( t.equals(Type.BOOLEAN) ||
559 t.equals(Type.CHAR) ||
560 t.equals(Type.BYTE) ||
561 t.equals(Type.SHORT) )
562 t = Type.INT;
563 stack().push(t);
564 }
565 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
566 public void visitGOTO(GOTO o){
567 // no stack changes.
568 }
569 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
570 public void visitGOTO_W(GOTO_W o){
571 // no stack changes.
572 }
573 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
574 public void visitI2B(I2B o){
575 stack().pop();
576 stack().push(Type.INT);
577 }
578 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
579 public void visitI2C(I2C o){
580 stack().pop();
581 stack().push(Type.INT);
582 }
583 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
584 public void visitI2D(I2D o){
585 stack().pop();
586 stack().push(Type.DOUBLE);
587 }
588 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
589 public void visitI2F(I2F o){
590 stack().pop();
591 stack().push(Type.FLOAT);
592 }
593 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
594 public void visitI2L(I2L o){
595 stack().pop();
596 stack().push(Type.LONG);
597 }
598 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
599 public void visitI2S(I2S o){
600 stack().pop();
601 stack().push(Type.INT);
602 }
603 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
604 public void visitIADD(IADD o){
605 stack().pop();
606 stack().pop();
607 stack().push(Type.INT);
608 }
609 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
610 public void visitIALOAD(IALOAD o){
611 stack().pop();
612 stack().pop();
613 stack().push(Type.INT);
614 }
615 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
616 public void visitIAND(IAND o){
617 stack().pop();
618 stack().pop();
619 stack().push(Type.INT);
620 }
621 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
622 public void visitIASTORE(IASTORE o){
623 stack().pop();
624 stack().pop();
625 stack().pop();
626 }
627 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
628 public void visitICONST(ICONST o){
629 stack().push(Type.INT);
630 }
631 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
632 public void visitIDIV(IDIV o){
633 stack().pop();
634 stack().pop();
635 stack().push(Type.INT);
636 }
637 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
638 public void visitIF_ACMPEQ(IF_ACMPEQ o){
639 stack().pop();
640 stack().pop();
641 }
642 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
643 public void visitIF_ACMPNE(IF_ACMPNE o){
644 stack().pop();
645 stack().pop();
646 }
647 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
648 public void visitIF_ICMPEQ(IF_ICMPEQ o){
649 stack().pop();
650 stack().pop();
651 }
652 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
653 public void visitIF_ICMPGE(IF_ICMPGE o){
654 stack().pop();
655 stack().pop();
656 }
657 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
658 public void visitIF_ICMPGT(IF_ICMPGT o){
659 stack().pop();
660 stack().pop();
661 }
662 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
663 public void visitIF_ICMPLE(IF_ICMPLE o){
664 stack().pop();
665 stack().pop();
666 }
667 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
668 public void visitIF_ICMPLT(IF_ICMPLT o){
669 stack().pop();
670 stack().pop();
671 }
672 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
673 public void visitIF_ICMPNE(IF_ICMPNE o){
674 stack().pop();
675 stack().pop();
676 }
677 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
678 public void visitIFEQ(IFEQ o){
679 stack().pop();
680 }
681 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
682 public void visitIFGE(IFGE o){
683 stack().pop();
684 }
685 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
686 public void visitIFGT(IFGT o){
687 stack().pop();
688 }
689 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
690 public void visitIFLE(IFLE o){
691 stack().pop();
692 }
693 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
694 public void visitIFLT(IFLT o){
695 stack().pop();
696 }
697 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
698 public void visitIFNE(IFNE o){
699 stack().pop();
700 }
701 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
702 public void visitIFNONNULL(IFNONNULL o){
703 stack().pop();
704 }
705 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
706 public void visitIFNULL(IFNULL o){
707 stack().pop();
708 }
709 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
710 public void visitIINC(IINC o){
711 // stack is not changed.
712 }
713 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
714 public void visitILOAD(ILOAD o){
715 stack().push(Type.INT);
716 }
717 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
718 public void visitIMUL(IMUL o){
719 stack().pop();
720 stack().pop();
721 stack().push(Type.INT);
722 }
723 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
724 public void visitINEG(INEG o){
725 stack().pop();
726 stack().push(Type.INT);
727 }
728 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
729 public void visitINSTANCEOF(INSTANCEOF o){
730 stack().pop();
731 stack().push(Type.INT);
732 }
733 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
734 public void visitINVOKEINTERFACE(INVOKEINTERFACE o){
735 stack().pop(); //objectref
736 for (int i=0; i<o.getArgumentTypes(cpg).length; i++){
737 stack().pop();
738 }
739 // We are sure the invoked method will xRETURN eventually
740 // We simulate xRETURNs functionality here because we
741 // don't really "jump into" and simulate the invoked
742 // method.
743 if (o.getReturnType(cpg) != Type.VOID){
744 Type t = o.getReturnType(cpg);
745 if ( t.equals(Type.BOOLEAN) ||
746 t.equals(Type.CHAR) ||
747 t.equals(Type.BYTE) ||
748 t.equals(Type.SHORT) )
749 t = Type.INT;
750 stack().push(t);
751 }
752 }
753 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
754 public void visitINVOKESPECIAL(INVOKESPECIAL o){
755 if (o.getMethodName(cpg).equals(Constants.CONSTRUCTOR_NAME)){
756 UninitializedObjectType t = (UninitializedObjectType) stack().peek(o.getArgumentTypes(cpg).length);
757 if (t == frame._this){
758 frame._this = null;
759 }
760 stack().initializeObject(t);
761 locals().initializeObject(t);
762 }
763 stack().pop(); //objectref
764 for (int i=0; i<o.getArgumentTypes(cpg).length; i++){
765 stack().pop();
766 }
767 // We are sure the invoked method will xRETURN eventually
768 // We simulate xRETURNs functionality here because we
769 // don't really "jump into" and simulate the invoked
770 // method.
771 if (o.getReturnType(cpg) != Type.VOID){
772 Type t = o.getReturnType(cpg);
773 if ( t.equals(Type.BOOLEAN) ||
774 t.equals(Type.CHAR) ||
775 t.equals(Type.BYTE) ||
776 t.equals(Type.SHORT) )
777 t = Type.INT;
778 stack().push(t);
779 }
780 }
781 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
782 public void visitINVOKESTATIC(INVOKESTATIC o){
783 for (int i=0; i<o.getArgumentTypes(cpg).length; i++){
784 stack().pop();
785 }
786 // We are sure the invoked method will xRETURN eventually
787 // We simulate xRETURNs functionality here because we
788 // don't really "jump into" and simulate the invoked
789 // method.
790 if (o.getReturnType(cpg) != Type.VOID){
791 Type t = o.getReturnType(cpg);
792 if ( t.equals(Type.BOOLEAN) ||
793 t.equals(Type.CHAR) ||
794 t.equals(Type.BYTE) ||
795 t.equals(Type.SHORT) )
796 t = Type.INT;
797 stack().push(t);
798 }
799 }
800 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
801 public void visitINVOKEVIRTUAL(INVOKEVIRTUAL o){
802 stack().pop(); //objectref
803 for (int i=0; i<o.getArgumentTypes(cpg).length; i++){
804 stack().pop();
805 }
806 // We are sure the invoked method will xRETURN eventually
807 // We simulate xRETURNs functionality here because we
808 // don't really "jump into" and simulate the invoked
809 // method.
810 if (o.getReturnType(cpg) != Type.VOID){
811 Type t = o.getReturnType(cpg);
812 if ( t.equals(Type.BOOLEAN) ||
813 t.equals(Type.CHAR) ||
814 t.equals(Type.BYTE) ||
815 t.equals(Type.SHORT) )
816 t = Type.INT;
817 stack().push(t);
818 }
819 }
820 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
821 public void visitIOR(IOR o){
822 stack().pop();
823 stack().pop();
824 stack().push(Type.INT);
825 }
826 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
827 public void visitIREM(IREM o){
828 stack().pop();
829 stack().pop();
830 stack().push(Type.INT);
831 }
832 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
833 public void visitIRETURN(IRETURN o){
834 stack().pop();
835 }
836 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
837 public void visitISHL(ISHL o){
838 stack().pop();
839 stack().pop();
840 stack().push(Type.INT);
841 }
842 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
843 public void visitISHR(ISHR o){
844 stack().pop();
845 stack().pop();
846 stack().push(Type.INT);
847 }
848 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
849 public void visitISTORE(ISTORE o){
850 locals().set(o.getIndex(), stack().pop());
851 }
852 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
853 public void visitISUB(ISUB o){
854 stack().pop();
855 stack().pop();
856 stack().push(Type.INT);
857 }
858 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
859 public void visitIUSHR(IUSHR o){
860 stack().pop();
861 stack().pop();
862 stack().push(Type.INT);
863 }
864 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
865 public void visitIXOR(IXOR o){
866 stack().pop();
867 stack().pop();
868 stack().push(Type.INT);
869 }
870
871 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
872 public void visitJSR(JSR o){
873 stack().push(new ReturnaddressType(o.physicalSuccessor()));
874 //System.err.println("TODO-----------:"+o.physicalSuccessor());
875 }
876
877 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
878 public void visitJSR_W(JSR_W o){
879 stack().push(new ReturnaddressType(o.physicalSuccessor()));
880 }
881
882 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
883 public void visitL2D(L2D o){
884 stack().pop();
885 stack().push(Type.DOUBLE);
886 }
887 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
888 public void visitL2F(L2F o){
889 stack().pop();
890 stack().push(Type.FLOAT);
891 }
892 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
893 public void visitL2I(L2I o){
894 stack().pop();
895 stack().push(Type.INT);
896 }
897 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
898 public void visitLADD(LADD o){
899 stack().pop();
900 stack().pop();
901 stack().push(Type.LONG);
902 }
903 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
904 public void visitLALOAD(LALOAD o){
905 stack().pop();
906 stack().pop();
907 stack().push(Type.LONG);
908 }
909 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
910 public void visitLAND(LAND o){
911 stack().pop();
912 stack().pop();
913 stack().push(Type.LONG);
914 }
915 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
916 public void visitLASTORE(LASTORE o){
917 stack().pop();
918 stack().pop();
919 stack().pop();
920 }
921 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
922 public void visitLCMP(LCMP o){
923 stack().pop();
924 stack().pop();
925 stack().push(Type.INT);
926 }
927 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
928 public void visitLCONST(LCONST o){
929 stack().push(Type.LONG);
930 }
931 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
932 public void visitLDC(LDC o){
933 Constant c = cpg.getConstant(o.getIndex());
934 if (c instanceof ConstantInteger){
935 stack().push(Type.INT);
936 }
937 if (c instanceof ConstantFloat){
938 stack().push(Type.FLOAT);
939 }
940 if (c instanceof ConstantString){
941 stack().push(Type.STRING);
942 }
943 }
944 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
945 public void visitLDC_W(LDC_W o){
946 Constant c = cpg.getConstant(o.getIndex());
947 if (c instanceof ConstantInteger){
948 stack().push(Type.INT);
949 }
950 if (c instanceof ConstantFloat){
951 stack().push(Type.FLOAT);
952 }
953 if (c instanceof ConstantString){
954 stack().push(Type.STRING);
955 }
956 }
957 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
958 public void visitLDC2_W(LDC2_W o){
959 Constant c = cpg.getConstant(o.getIndex());
960 if (c instanceof ConstantLong){
961 stack().push(Type.LONG);
962 }
963 if (c instanceof ConstantDouble){
964 stack().push(Type.DOUBLE);
965 }
966 }
967 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
968 public void visitLDIV(LDIV o){
969 stack().pop();
970 stack().pop();
971 stack().push(Type.LONG);
972 }
973 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
974 public void visitLLOAD(LLOAD o){
975 stack().push(locals().get(o.getIndex()));
976 }
977 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
978 public void visitLMUL(LMUL o){
979 stack().pop();
980 stack().pop();
981 stack().push(Type.LONG);
982 }
983 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
984 public void visitLNEG(LNEG o){
985 stack().pop();
986 stack().push(Type.LONG);
987 }
988 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
989 public void visitLOOKUPSWITCH(LOOKUPSWITCH o){
990 stack().pop(); //key
991 }
992 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
993 public void visitLOR(LOR o){
994 stack().pop();
995 stack().pop();
996 stack().push(Type.LONG);
997 }
998 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
999 public void visitLREM(LREM o){
1000 stack().pop();
1001 stack().pop();
1002 stack().push(Type.LONG);
1003 }
1004 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
1005 public void visitLRETURN(LRETURN o){
1006 stack().pop();
1007 }
1008 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
1009 public void visitLSHL(LSHL o){
1010 stack().pop();
1011 stack().pop();
1012 stack().push(Type.LONG);
1013 }
1014 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
1015 public void visitLSHR(LSHR o){
1016 stack().pop();
1017 stack().pop();
1018 stack().push(Type.LONG);
1019 }
1020 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
1021 public void visitLSTORE(LSTORE o){
1022 locals().set(o.getIndex(), stack().pop());
1023 locals().set(o.getIndex()+1, Type.UNKNOWN);
1024 }
1025 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
1026 public void visitLSUB(LSUB o){
1027 stack().pop();
1028 stack().pop();
1029 stack().push(Type.LONG);
1030 }
1031 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
1032 public void visitLUSHR(LUSHR o){
1033 stack().pop();
1034 stack().pop();
1035 stack().push(Type.LONG);
1036 }
1037 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
1038 public void visitLXOR(LXOR o){
1039 stack().pop();
1040 stack().pop();
1041 stack().push(Type.LONG);
1042 }
1043 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
1044 public void visitMONITORENTER(MONITORENTER o){
1045 stack().pop();
1046 }
1047 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
1048 public void visitMONITOREXIT(MONITOREXIT o){
1049 stack().pop();
1050 }
1051 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
1052 public void visitMULTIANEWARRAY(MULTIANEWARRAY o){
1053 for (int i=0; i<o.getDimensions(); i++){
1054 stack().pop();
1055 }
1056 stack().push(o.getType(cpg));
1057 }
1058 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
1059 public void visitNEW(NEW o){
1060 stack().push(new UninitializedObjectType((ObjectType) (o.getType(cpg))));
1061 }
1062 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
1063 public void visitNEWARRAY(NEWARRAY o){
1064 stack().pop();
1065 stack().push(o.getType());
1066 }
1067 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
1068 public void visitNOP(NOP o){
1069 }
1070 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
1071 public void visitPOP(POP o){
1072 stack().pop();
1073 }
1074 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
1075 public void visitPOP2(POP2 o){
1076 Type t = stack().pop();
1077 if (t.getSize() == 1){
1078 stack().pop();
1079 }
1080 }
1081 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
1082 public void visitPUTFIELD(PUTFIELD o){
1083 stack().pop();
1084 stack().pop();
1085 }
1086 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
1087 public void visitPUTSTATIC(PUTSTATIC o){
1088 stack().pop();
1089 }
1090 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
1091 public void visitRET(RET o){
1092 // do nothing, return address
1093 // is in in the local variables.
1094 }
1095 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
1096 public void visitRETURN(RETURN o){
1097 // do nothing.
1098 }
1099 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
1100 public void visitSALOAD(SALOAD o){
1101 stack().pop();
1102 stack().pop();
1103 stack().push(Type.INT);
1104 }
1105 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
1106 public void visitSASTORE(SASTORE o){
1107 stack().pop();
1108 stack().pop();
1109 stack().pop();
1110 }
1111 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
1112 public void visitSIPUSH(SIPUSH o){
1113 stack().push(Type.INT);
1114 }
1115 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
1116 public void visitSWAP(SWAP o){
1117 Type t = stack().pop();
1118 Type u = stack().pop();
1119 stack().push(t);
1120 stack().push(u);
1121 }
1122 /*** Symbolically executes the corresponding Java Virtual Machine instruction. */
1123 public void visitTABLESWITCH(TABLESWITCH o){
1124 stack().pop();
1125 }
1126 }
This page was automatically generated by Maven