java - Method signatures and descriptors in class file constant pool (javap) -


i trying figure out following 2 entries under constant pool section in class file:

int foo(int x) {     return x; }  #11 = utf8               foo #12 = utf8               (i)i        // 1    #13 = utf8               x #14 = utf8                         // 2 

does entry (1) -> (i)i denotes start of function , entry (2) -> denotes end of function.

is compiler specific or vary 1 compiler another?

similar question lambda functions well.

interface { int foo(int x); } class x { x = (int x1) -> 0; }   #15 = utf8            lambda$new$0  #16 = utf8            (i)i  #17 = utf8            x1  #18 = utf8            

sorry not find on jls docs.

thanks

the constant pool not have concept of "method start" , "method end".

what seeing here string constants, have type "utf8" in constant pool. pool's point of view, these strings -- however, compiler-generated strings representing various things. these strings required , format described in jvms. there few types. lambda example:

  • lambda$new$0 - signature, described in 4.3.4.
  • (i)i - method descriptor (not same signature), described in 4.3.3
  • i - field descriptor, described in 4.3.2.

the simple i entry field of type int.

for (i) i entry, string between (..) parameter type. can list. i primitive type int. string outside (..) return type. (i) i describes method parameter list accepting int , return type of int.

specifically, jvms, method descriptor strings have format:

methoddescriptor:     ( parameterdescriptor* ) returndescriptor  parameterdescriptor:     fieldtype  returndescriptor:     fieldtype     voiddescriptor  voiddescriptor:     v 

where fieldtype (from table 4.2):

 character     type       interpretation b             byte       signed byte c             char       unicode character code point in basic                             multilingual plane, encoded utf-16 d             double     double-precision floating-point value f             float      single-precision floating-point value             int        integer j             long       long integer l classname;  reference  instance of class classname s             short      signed short z             boolean    true or false [             reference  1 array dimension 

note, however, these still strings other. when call these methods, different kind of entry - method reference - appear in constant pool. javap identifies these "nameandtype" type (as opposed "utf8" strings), , take forms (using first example):

#123 = nameandtype      #11:#12;   // "foo":(i)i 

they reference method name string descriptor string.

the javap documentation rather sparse , contains command line information. jvms closest thing detailed manual javap has.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -