@@ -566,55 +566,6 @@ public Object invokeWithArguments(Object... arguments) throws Throwable {
566566 }
567567 }
568568
569- /** Factory method: Spread selected argument. */
570- static MethodHandle makeSpreadArguments (MethodHandle target ,
571- Class <?> spreadArgType , int spreadArgPos , int spreadArgCount ) {
572- MethodType targetType = target .type ();
573-
574- for (int i = 0 ; i < spreadArgCount ; i ++) {
575- Class <?> arg = VerifyType .spreadArgElementType (spreadArgType , i );
576- if (arg == null ) arg = Object .class ;
577- targetType = targetType .changeParameterType (spreadArgPos + i , arg );
578- }
579- target = target .asType (targetType );
580-
581- MethodType srcType = targetType
582- .replaceParameterTypes (spreadArgPos , spreadArgPos + spreadArgCount , spreadArgType );
583- // Now build a LambdaForm.
584- MethodType lambdaType = srcType .invokerType ();
585- Name [] names = arguments (spreadArgCount + 2 , lambdaType );
586- int nameCursor = lambdaType .parameterCount ();
587- int [] indexes = new int [targetType .parameterCount ()];
588-
589- for (int i = 0 , argIndex = 1 ; i < targetType .parameterCount () + 1 ; i ++, argIndex ++) {
590- Class <?> src = lambdaType .parameterType (i );
591- if (i == spreadArgPos ) {
592- // Spread the array.
593- MethodHandle aload = MethodHandles .arrayElementGetter (spreadArgType );
594- Name array = names [argIndex ];
595- names [nameCursor ++] = new Name (getFunction (NF_checkSpreadArgument ), array , spreadArgCount );
596- for (int j = 0 ; j < spreadArgCount ; i ++, j ++) {
597- indexes [i ] = nameCursor ;
598- names [nameCursor ++] = new Name (new NamedFunction (aload , Intrinsic .ARRAY_LOAD ), array , j );
599- }
600- } else if (i < indexes .length ) {
601- indexes [i ] = argIndex ;
602- }
603- }
604- assert (nameCursor == names .length -1 ); // leave room for the final call
605-
606- // Build argument array for the call.
607- Name [] targetArgs = new Name [targetType .parameterCount ()];
608- for (int i = 0 ; i < targetType .parameterCount (); i ++) {
609- int idx = indexes [i ];
610- targetArgs [i ] = names [idx ];
611- }
612- names [names .length - 1 ] = new Name (target , (Object []) targetArgs );
613-
614- LambdaForm form = new LambdaForm (lambdaType .parameterCount (), names , Kind .SPREAD );
615- return SimpleMethodHandle .make (srcType , form );
616- }
617-
618569 static void checkSpreadArgument (Object av , int n ) {
619570 if (av == null && n == 0 ) {
620571 return ;
@@ -631,60 +582,6 @@ static void checkSpreadArgument(Object av, int n) {
631582 throw newIllegalArgumentException ("array is not of length " +n );
632583 }
633584
634- /** Factory method: Collect or filter selected argument(s). */
635- static MethodHandle makeCollectArguments (MethodHandle target ,
636- MethodHandle collector , int collectArgPos , boolean retainOriginalArgs ) {
637- MethodType targetType = target .type (); // (a..., c, [b...])=>r
638- MethodType collectorType = collector .type (); // (b...)=>c
639- int collectArgCount = collectorType .parameterCount ();
640- Class <?> collectValType = collectorType .returnType ();
641- int collectValCount = (collectValType == void .class ? 0 : 1 );
642- MethodType srcType = targetType // (a..., [b...])=>r
643- .dropParameterTypes (collectArgPos , collectArgPos +collectValCount );
644- if (!retainOriginalArgs ) { // (a..., b...)=>r
645- srcType = srcType .insertParameterTypes (collectArgPos , collectorType .parameterArray ());
646- }
647- // in arglist: [0: ...keep1 | cpos: collect... | cpos+cacount: keep2... ]
648- // out arglist: [0: ...keep1 | cpos: collectVal? | cpos+cvcount: keep2... ]
649- // out(retain): [0: ...keep1 | cpos: cV? coll... | cpos+cvc+cac: keep2... ]
650-
651- // Now build a LambdaForm.
652- MethodType lambdaType = srcType .invokerType ();
653- Name [] names = arguments (2 , lambdaType );
654- final int collectNamePos = names .length - 2 ;
655- final int targetNamePos = names .length - 1 ;
656-
657- Name [] collectorArgs = Arrays .copyOfRange (names , 1 + collectArgPos , 1 + collectArgPos + collectArgCount );
658- names [collectNamePos ] = new Name (collector , (Object []) collectorArgs );
659-
660- // Build argument array for the target.
661- // Incoming LF args to copy are: [ (mh) headArgs collectArgs tailArgs ].
662- // Output argument array is [ headArgs (collectVal)? (collectArgs)? tailArgs ].
663- Name [] targetArgs = new Name [targetType .parameterCount ()];
664- int inputArgPos = 1 ; // incoming LF args to copy to target
665- int targetArgPos = 0 ; // fill pointer for targetArgs
666- int chunk = collectArgPos ; // |headArgs|
667- System .arraycopy (names , inputArgPos , targetArgs , targetArgPos , chunk );
668- inputArgPos += chunk ;
669- targetArgPos += chunk ;
670- if (collectValType != void .class ) {
671- targetArgs [targetArgPos ++] = names [collectNamePos ];
672- }
673- chunk = collectArgCount ;
674- if (retainOriginalArgs ) {
675- System .arraycopy (names , inputArgPos , targetArgs , targetArgPos , chunk );
676- targetArgPos += chunk ; // optionally pass on the collected chunk
677- }
678- inputArgPos += chunk ;
679- chunk = targetArgs .length - targetArgPos ; // all the rest
680- System .arraycopy (names , inputArgPos , targetArgs , targetArgPos , chunk );
681- assert (inputArgPos + chunk == collectNamePos ); // use of rest of input args also
682- names [targetNamePos ] = new Name (target , (Object []) targetArgs );
683-
684- LambdaForm form = new LambdaForm (lambdaType .parameterCount (), names , Kind .COLLECT );
685- return SimpleMethodHandle .make (srcType , form );
686- }
687-
688585 @ Hidden
689586 static MethodHandle selectAlternative (boolean testResult , MethodHandle target , MethodHandle fallback ) {
690587 if (testResult ) {
0 commit comments