How does the java compiler assign index's in the local variables table? -


alright i'm writing compiler , i'm trying use information in local variables table figure out names/types variables.

i have following code:

public void noob() {     try {         int hello = 0;         short yo = 1;         byte y = 2;         int[] e = new int[9];          system.out.println(y + ", " + hello + ", " + yo+", "+e);      } catch (exception var6) {         var6.printstacktrace();     } } 

when reading variables table following:

localvariable{uid=-1, start=0, end=69, nameindex=30, typeindex=31, varindex=0, name='this', typename='lmain;'} localvariable{uid=-1, start=2, end=60, nameindex=37, typeindex=18, varindex=1, name='hello', typename='i'} localvariable{uid=-1, start=4, end=60, nameindex=38, typeindex=39, varindex=2, name='yo', typename='s'} localvariable{uid=-1, start=6, end=60, nameindex=40, typeindex=41, varindex=3, name='y', typename='b'} localvariable{uid=-1, start=12, end=60, nameindex=42, typeindex=43, varindex=4, name='e', typename='[i'} localvariable{uid=-1, start=64, end=68, nameindex=44, typeindex=45, varindex=1, name='var6', typename='ljava/lang/exception;'} 

(ignore uid column).

i noticed varindex not unqiue every variable. why hello (int) , var6(exception) share same varindex?

the compiler smart enough reuse variable slots variables scopes not overlap. because can never both used @ same time, there no need store them separately.

since hello , var6 have no overlap, slot can reused.


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -