@@ -806,23 +806,37 @@ function revertJvmMethod (method) {
806806
807807function _getJvmMethodSpec ( ) {
808808 const api = getApi ( ) ;
809+ const { version } = api ;
809810
810- const adapterInConstMethod = ( api . version > 8 ) ? 1 : 0 ;
811+ let adapterHandlerLocation ;
812+ if ( version >= 17 ) {
813+ adapterHandlerLocation = 'method:early' ;
814+ } else if ( version >= 9 && version <= 16 ) {
815+ adapterHandlerLocation = 'const-method' ;
816+ } else {
817+ adapterHandlerLocation = 'method:late' ;
818+ }
811819
812820 const isNative = 1 ;
813821 const methodSize = api [ 'Method::size' ] ( isNative ) * pointerSize ;
814822 const constMethodOffset = pointerSize ;
815823 const methodDataOffset = 2 * pointerSize ;
816824 const methodCountersOffset = 3 * pointerSize ;
817- const accessFlagsOffset = 4 * pointerSize ;
825+ const adapterInMethodEarlyOffset = 4 * pointerSize ;
826+ const adapterInMethodEarlySize = ( adapterHandlerLocation === 'method:early' ) ? pointerSize : 0 ;
827+ const accessFlagsOffset = adapterInMethodEarlyOffset + adapterInMethodEarlySize ;
818828 const vtableIndexOffset = accessFlagsOffset + 4 ;
819- const i2iEntryOffset = vtableIndexOffset + 4 + pointerSize ;
829+ const i2iEntryOffset = vtableIndexOffset + 4 + 8 ;
830+ const adapterInMethodLateOffset = i2iEntryOffset + pointerSize ;
831+ const adapterInMethodOffset = ( adapterInMethodEarlySize !== 0 ) ? adapterInMethodEarlyOffset : adapterInMethodLateOffset ;
820832 const nativeFunctionOffset = methodSize - 2 * pointerSize ;
821833 const signatureHandlerOffset = methodSize - pointerSize ;
822834
823- const constantPoolOffset = pointerSize ;
824- const stackmapDataOffset = 2 * pointerSize ;
825- const constMethodSizeOffset = ( 3 + adapterInConstMethod ) * pointerSize ;
835+ const constantPoolOffset = 8 ;
836+ const stackmapDataOffset = constantPoolOffset + pointerSize ;
837+ const adapterInConstMethodOffset = stackmapDataOffset + pointerSize ;
838+ const adapterInConstMethodSize = ( adapterHandlerLocation === 'const-method' ) ? pointerSize : 0 ;
839+ const constMethodSizeOffset = adapterInConstMethodOffset + adapterInConstMethodSize ;
826840 const methodIdnumOffset = constMethodSizeOffset + 0xe ;
827841
828842 const cacheOffset = 2 * pointerSize ;
@@ -833,12 +847,12 @@ function _getJvmMethodSpec () {
833847 klassSpec = getJvmKlassSpec ( vtableOffset ) ;
834848 }
835849
836- const getAdapterPointer = adapterInConstMethod
850+ const getAdapterPointer = ( adapterInConstMethodSize !== 0 )
837851 ? function ( method , constMethod ) {
838- return constMethod . add ( constantPoolOffset + 2 * pointerSize ) ;
852+ return constMethod . add ( adapterInConstMethodOffset ) ;
839853 }
840854 : function ( method , constMethod ) {
841- return method . add ( i2iEntryOffset + pointerSize ) ;
855+ return method . add ( adapterInMethodOffset ) ;
842856 } ;
843857
844858 return {
0 commit comments