@@ -269,8 +269,23 @@ const runtime = {
269269 E : Object . freeze ( { exit : true } ) ,
270270 xc : 0 ,
271271 // slowCall's counterpart for a virtual call that missed its inlining guard:
272- // dispatches through the site's cache and calls a compiled target directly
273- callv ( t : JThread , f : Frame , ic : any [ ] , args : any [ ] , pc : number , xp : number , xi : number ) : any {
272+ // dispatches through the site's cache and calls a compiled target directly.
273+ // Up to four argument slots come as parameters, more in an array.
274+ callv ( t : JThread , f : Frame , ic : any [ ] , pc : number , xp : number , xi : number , a0 : any , a1 ?: any , a2 ?: any , a3 ?: any ) : any {
275+ f . pc = pc ;
276+ const tm : JMethod = a0 !== null && a0 . cls === ic [ 0 ] ? ic [ 1 ] : runtime . select ( a0 , ic , pc ) ;
277+ let cf : Frame | null ;
278+ if ( tm . jit !== null && ( cf = t . enter ( tm , a0 ) ) !== null ) {
279+ if ( ( tm . jit as ( ...a : any [ ] ) => number ) ( t , cf , a0 , a1 , a2 , a3 ) !== 0 ) {
280+ t . unpool ( cf ) ;
281+ runtime . xc = xp ;
282+ return runtime . E ;
283+ }
284+ return t . ret ;
285+ }
286+ return runtime . callvSlow ( t , tm , [ a0 , a1 , a2 , a3 ] , xp , xi ) ;
287+ } ,
288+ callvMany ( t : JThread , f : Frame , ic : any [ ] , args : any [ ] , pc : number , xp : number , xi : number ) : any {
274289 f . pc = pc ;
275290 const recv = args [ 0 ] as JObject | null ;
276291 const tm : JMethod = recv !== null && recv . cls === ic [ 0 ] ? ic [ 1 ] : runtime . select ( recv , ic , pc ) ;
@@ -283,9 +298,13 @@ const runtime = {
283298 }
284299 return t . ret ;
285300 }
286- const native : any [ ] = [ recv ] ;
301+ return runtime . callvSlow ( t , tm , args , xp , xi ) ;
302+ } ,
303+ // a native or interpreted target: slots are argument slots, natives take values
304+ callvSlow ( t : JThread , tm : JMethod , slots : any [ ] , xp : number , xi : number ) : any {
305+ const native : any [ ] = [ slots [ 0 ] ] ;
287306 for ( let i = 1 , p = 0 ; p < tm . params . length ; p ++ ) {
288- native . push ( args [ i ] ) ;
307+ native . push ( slots [ i ] ) ;
289308 i += isWide ( tm . params [ p ] ) ? 2 : 1 ;
290309 }
291310 return runtime . slowCall ( t , tm , native , xp , xi ) ;
@@ -1356,7 +1375,8 @@ function genGuardMiss(g: Gen, pc: number, next: number, d: number, target: JMeth
13561375 const ret = target . ret ;
13571376 const xp = g . xcode ( pc , base , EXIT_SUSPEND ) , xi = g . xcode ( pc , d , EXIT_INTERPRET ) ;
13581377 const cell = g . K ( [ null , null , target . key ] ) ;
1359- return `v=rt.callv(t,f,${ cell } ,[${ args } ],${ pc } ,${ xp } ,${ xi } );if(v===rt.E){x=rt.xc;break X;}${ ret === "V" ? "" : `s${ base } =v;` } ` +
1378+ const call = n <= 4 ? `rt.callv(t,f,${ cell } ,${ pc } ,${ xp } ,${ xi } ,${ args } )` : `rt.callvMany(t,f,${ cell } ,[${ args } ],${ pc } ,${ xp } ,${ xi } )` ;
1379+ return `v=${ call } ;if(v===rt.E){x=rt.xc;break X;}${ ret === "V" ? "" : `s${ base } =v;` } ` +
13601380 `if(t.state!==0)${ g . exit ( next , ret === "V" ? base : base + ( isWide ( ret ) ? 2 : 1 ) , EXIT_SUSPEND ) } ` ;
13611381}
13621382
0 commit comments