1 /*
   2  * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 
  25 /*
  26  * @test
  27  *
  28  * @summary converted from VM Testbase vm/mlvm/meth/stress/compiler/sequences.
  29  * VM Testbase keywords: [feature_mlvm, nonconcurrent, quarantine]
  30  * VM Testbase comments: 8079714
  31  * VM Testbase readme:
  32  * DESCRIPTION
  33  *     Create various long sequences of method handles, adding/removing/joining/splitting arguments.
  34  *     Don't verify correctness of results. Just try to stress compiler.
  35  *     See vm.mlvm.meth.stress.java.sequences.Test for details on MH sequences.
  36  *
  37  * @library /vmTestbase
  38  *          /test/lib
  39  * @run driver jdk.test.lib.FileInstaller . .
  40  *
  41  * @comment build test class and indify classes
  42  * @build vm.mlvm.meth.stress.compiler.sequences.Test
  43  * @run driver vm.mlvm.share.IndifiedClassesBuilder
  44  *
  45  * @run main/othervm
  46  *      vm.mlvm.meth.stress.compiler.sequences.Test
  47  *      -threadsPerCpu 1
  48  *      -threadsExtra 2
  49  *      -stressIterationsFactor 1000
  50  */
  51 
  52 package vm.mlvm.meth.stress.compiler.sequences;
  53 
  54 import java.lang.invoke.MethodHandle;
  55 import java.lang.invoke.MethodHandles;
  56 import java.lang.invoke.MethodType;
  57 
  58 import nsk.share.test.Stresser;
  59 import vm.mlvm.meth.share.Argument;
  60 import vm.mlvm.meth.share.MHTransformationGen;
  61 import vm.mlvm.meth.share.RandomArgumentsGen;
  62 import vm.mlvm.share.MlvmTest;
  63 import vm.mlvm.share.MultiThreadedTest;
  64 
  65 //TODO: check deoptimization using vm.mlvm.share.comp framework
  66 public class Test extends MultiThreadedTest {
  67 
  68     Object target(int i, String s, Float f) {
  69         return i + s + f;
  70     }
  71 
  72     final MethodHandle _mh;
  73     final Argument[] _finalArgs;
  74     final Argument _retVal;
  75 
  76     public Test() throws Throwable {
  77         super();
  78 
  79         _mh = MethodHandles.lookup().findVirtual(
  80                 Test.class,
  81                 "target",
  82                 MethodType.methodType(Object.class, int.class, String.class, Float.class));
  83 
  84         _finalArgs = RandomArgumentsGen.createRandomArgs(true, _mh.type());
  85         _retVal = Argument.fromValue(target(
  86                        (Integer) _finalArgs[0].getValue(),
  87                        (String) _finalArgs[1].getValue(),
  88                        (Float) _finalArgs[2].getValue()));
  89         _retVal.setPreserved(true);
  90     }
  91 
  92     @Override
  93     public boolean runThread(int threadNum) throws Throwable {
  94 
  95         Stresser stresser = createStresser();
  96         stresser.start(1);
  97         try {
  98             while ( stresser.continueExecution() ) {
  99                 stresser.iteration();
 100                 MHTransformationGen.callSequence(MHTransformationGen.createSequence(_retVal, Test.this, _mh, _finalArgs), true);
 101             }
 102         } finally {
 103             stresser.finish();
 104         }
 105 
 106         return true;
 107     }
 108 
 109     public static void main(String[] args) { MlvmTest.launch(args); }
 110 }