hangal / unifi

Unit Finder for Java. Program analysis tool to find dimensionality errors in programs automatically.
3 stars 2 forks source link

IndexoutofBounds Exception when instrumenting some class files. #1

Open vihari opened 11 years ago

vihari commented 11 years ago

unifi.drivers.Analyze INFO: Instrumenting method edu.stanford.muse.email.EmailFetcherThread.run()V :::: aload_244 ::: 239 //This is the instruction and byte code offset respectively ?? idx = 7 no.of words : 1 local vars length: 4 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6 at unifi.MethodUnits.get_local_var_unit(MethodUnits.java:459) at unifi.drivers.Instrumenter.instrumentMethod(Instrumenter.java:359) at unifi.drivers.Instrumenter.instrumentClass(Instrumenter.java:161) at unifi.drivers.Instrumenter.instrumentJar(Instrumenter.java:87) at unifi.drivers.Instrumenter.main(Instrumenter.java:473) where one expects an idx of 2 in the above case.

vihari commented 11 years ago

This is a simple rather hacky fix, where the index in local var table is extracted from the instruction rather than int indx = lv_map.pos_to_logical_LV_num (oPos); There seems to be a bug in pos_to_logical_LV_num function. With this modification muse was successfully instrumented, there are still some problems with instrumenting which is when observed with socialite and is discussed in issue #2.

vihari commented 11 years ago

Consider this unifi.drivers.Analyze INFO: Instrumenting method socialite.dist.worker.WorkerNode.run()V Method max locals 7 //pos, physical index in lvtable and logical index ::: 0 ::: 0 :::logical::: 0 ::: 241 ::: 0 :::logical::: 0 ::: 87 ::: 0 :::logical::: 0 ::: 127 ::: 0 :::logical::: 0 ::: 192 ::: 0 :::logical::: 0 ::: 201 ::: 0 :::logical::: 0 ::: 11 ::: 1 :::logical::: 1 ::: 267 ::: 1 :::logical::: 7 ::: 279 ::: 1 :::logical::: 7 ::: 18 ::: 2 :::logical::: 2 ::: 27 ::: 2 :::logical::: 2 ::: 37 ::: 2 :::logical::: 2 ::: 43 ::: 3 :::logical::: 3 ::: 80 ::: 3 :::logical::: 3 ::: 65 ::: 3 :::logical::: 3 ::: 98 ::: 3 :::logical::: 3 ::: 91 ::: 3 :::logical::: 3 ::: 226 ::: 3 :::logical::: 3 ::: 105 ::: 3 :::logical::: 3 ::: 117 ::: 4 :::logical::: 4 ::: 131 ::: 4 :::logical::: 4 ::: 136 ::: 4 :::logical::: 4 ::: 185 ::: 4 :::logical::: 4 ::: 183 ::: 5 :::logical::: 5 ::: 163 ::: 6 :::logical::: 6 ::: 196 ::: 6 :::logical::: 8 :::: aload_345 ::: 65 ??????????? idx = 3 no.of words : 1 local vars length: 4 real local vars: 4 :::: aload25 6 ::: 163 ??????????? idx = 6 no.of words : 1 local vars length: 4 real local vars: 4 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5 at unifi.MethodUnits.get_local_var_unit(MethodUnits.java:462) at unifi.drivers.Instrumenter.instrumentMethod(Instrumenter.java:389) at unifi.drivers.Instrumenter.instrumentClass(Instrumenter.java:164) at unifi.drivers.Instrumenter.instrumentJar(Instrumenter.java:90) at unifi.drivers.Instrumenter.main(Instrumenter.java:503)

real_locals value is 4 and hence the size of local_vars. While the right answer seems to be 8. Line 286 MethodUnits.java // TOFIX: why do we add +2 here ? //+2 because lv is 0 based index and n_param_words>=1 because of "this" param int max_local_words = lv_map.highest_lv () + 2; real_locals = max_local_words - _n_param_words;