public synchronized int recordBootstrapMethod ( String slashedClassName , Handle bsm , Object [ ] bsmArgs ) { if ( bsmmap == null ) { bsmmap = new HashMap < String , BsmInfo [ ] > ( ) ; } BsmInfo [ ] bsminfo = bsmmap . get ( slashedClassName ) ; if ( bsminfo == null ) { bsminfo = new BsmInfo [ 1 ] ; // TODO do we need BsmInfo or can we just use Handle directly? bsminfo [ 0 ] = new BsmInfo ( bsm , bsmArgs ) ; bsmmap . put ( slashedClassName , bsminfo ) ; return 0 ; } else { int len = bsminfo . length ; BsmInfo [ ] newarray = new BsmInfo [ len + 1 ] ; System . arraycopy ( bsminfo , 0 , newarray , 0 , len ) ; bsminfo = newarray ; bsmmap . put ( slashedClassName , bsminfo ) ; bsminfo [ len ] = new BsmInfo ( bsm , bsmArgs ) ; return len ; } // TODO [memory] search the existing bsmInfos for a matching one! Reuse! }
When an invokedynamic instruction is reached we allocate an id that recognizes that bsm and the parameters to that bsm . The index can be used when rewriting that invokedynamic