You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ExecutionVisitor.java 37KB

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