test/hotspot/jtreg/compiler/runtime/SpreadNullArg.java
author iignatyev
Mon, 18 Feb 2019 09:31:07 -0800
changeset 53791 bec6c8739833
parent 48022 6fe6d8239e42
permissions -rw-r--r--
8219157: vm/mlvm/mixed/stress/java/findDeadlock should be problem-listed only on mac Reviewed-by: thartmann
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11638
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
     1
/*
35594
cc13089c6327 8147937: Adapt SAP copyrights to new company name.
goetz
parents: 27699
diff changeset
     2
 * Copyright (c) 2011 SAP SE. All rights reserved.
11638
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
     4
 *
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
     7
 * published by the Free Software Foundation.
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
     8
 *
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    13
 * accompanied this code).
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    14
 *
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    18
 *
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    21
 * questions.
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    22
 */
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    23
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    24
/*
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    25
 * @test SpreadNullArg
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    26
 * @bug 7141637
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35594
diff changeset
    27
 * @summary verifies that the MethodHandle spread adapter can gracefully handle null arguments.
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35594
diff changeset
    28
 *
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35594
diff changeset
    29
 * @run main compiler.runtime.SpreadNullArg
11638
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    30
 * @author volker.simonis@gmail.com
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    31
 */
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    32
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35594
diff changeset
    33
package compiler.runtime;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35594
diff changeset
    34
11638
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    35
import java.lang.invoke.MethodHandle;
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    36
import java.lang.invoke.MethodHandles;
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    37
import java.lang.invoke.MethodType;
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    38
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    39
public class SpreadNullArg {
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    40
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    41
  public static void main(String args[]) {
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    42
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    43
    MethodType mt_ref_arg = MethodType.methodType(int.class, Integer.class);
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    44
    MethodHandle mh_spreadInvoker = MethodHandles.spreadInvoker(mt_ref_arg, 0);
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    45
    MethodHandle mh_spread_target;
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    46
    int result = 42;
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    47
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    48
    try {
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    49
      mh_spread_target =
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35594
diff changeset
    50
          MethodHandles.lookup().findStatic(SpreadNullArg.class, "target_spread_arg", mt_ref_arg);
11638
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    51
      result = (int) mh_spreadInvoker.invokeExact(mh_spread_target, (Object[]) null);
48022
6fe6d8239e42 8191313: compiler/runtime/SpreadNullArg.java fails in tier1
rraghavan
parents: 47216
diff changeset
    52
      throw new Error("Expected NullPointerException was not thrown");
6fe6d8239e42 8191313: compiler/runtime/SpreadNullArg.java fails in tier1
rraghavan
parents: 47216
diff changeset
    53
    } catch (NullPointerException e) {
22226
1d8f2283eb16 8029153: [TESTBUG] test/compiler/7141637/SpreadNullArg.java fails because it expects NullPointerException
iignatyev
parents: 11638
diff changeset
    54
      System.out.println("Expected exception : " + e);
1d8f2283eb16 8029153: [TESTBUG] test/compiler/7141637/SpreadNullArg.java fails because it expects NullPointerException
iignatyev
parents: 11638
diff changeset
    55
    } catch (Throwable e) {
11638
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    56
      throw new Error(e);
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    57
    }
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    58
22226
1d8f2283eb16 8029153: [TESTBUG] test/compiler/7141637/SpreadNullArg.java fails because it expects NullPointerException
iignatyev
parents: 11638
diff changeset
    59
    if (result != 42) {
1d8f2283eb16 8029153: [TESTBUG] test/compiler/7141637/SpreadNullArg.java fails because it expects NullPointerException
iignatyev
parents: 11638
diff changeset
    60
      throw new Error("result [" + result
48022
6fe6d8239e42 8191313: compiler/runtime/SpreadNullArg.java fails in tier1
rraghavan
parents: 47216
diff changeset
    61
          + "] != 42 : Expected NullPointerException was not thrown?");
22226
1d8f2283eb16 8029153: [TESTBUG] test/compiler/7141637/SpreadNullArg.java fails because it expects NullPointerException
iignatyev
parents: 11638
diff changeset
    62
    }
11638
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    63
  }
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    64
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    65
  public static int target_spread_arg(Integer i1) {
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    66
    return i1.intValue();
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    67
  }
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    68
68657fd5d7b4 7141637: JSR 292: MH spread invoker crashes with NULL argument on x86_32
twisti
parents:
diff changeset
    69
}