Mercurial > hg > truffle
annotate graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ArraySubstitutions.java @ 21644:2c6802ac343c
Use graph builder plugin instead of node intrinsic for guarding non-null in snippets.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Mon, 01 Jun 2015 22:12:57 +0200 |
parents | 48c1ebd24120 |
children | 64475dbf6aec |
rev | line source |
---|---|
10027 | 1 /* |
13971 | 2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. |
10027 | 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 package com.oracle.graal.replacements; | |
24 | |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
16382
diff
changeset
|
25 import static com.oracle.graal.nodes.extended.BranchProbabilityNode.*; |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
16382
diff
changeset
|
26 |
21644
2c6802ac343c
Use graph builder plugin instead of node intrinsic for guarding non-null in snippets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
21556
diff
changeset
|
27 import com.oracle.graal.api.directives.*; |
10027 | 28 import com.oracle.graal.nodes.*; |
29 import com.oracle.graal.nodes.java.*; | |
21556
48c1ebd24120
renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21017
diff
changeset
|
30 import com.oracle.jvmci.meta.*; |
10027 | 31 |
21017
66d45b977e44
Add missing //JaCoCo Exclude directives.
Roland Schatz <roland.schatz@oracle.com>
parents:
20851
diff
changeset
|
32 // JaCoCo Exclude |
66d45b977e44
Add missing //JaCoCo Exclude directives.
Roland Schatz <roland.schatz@oracle.com>
parents:
20851
diff
changeset
|
33 |
10027 | 34 /** |
35 * Substitutions for {@link java.lang.reflect.Array} methods. | |
36 */ | |
37 public class ArraySubstitutions { | |
38 | |
10542
554f67e4ff3f
Use slow-path stub call instead of deopt in lowering of DynamicNewArrayNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
10027
diff
changeset
|
39 public static Object newInstance(Class<?> componentType, int length) throws NegativeArraySizeException { |
16125
cc76575f485c
handle error case in Array.newInstance
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
13971
diff
changeset
|
40 // The error cases must be handled here since DynamicNewArrayNode can only deoptimize the |
cc76575f485c
handle error case in Array.newInstance
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
13971
diff
changeset
|
41 // caller in response to exceptions. |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
16382
diff
changeset
|
42 if (probability(SLOW_PATH_PROBABILITY, length < 0)) { |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
16382
diff
changeset
|
43 DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint); |
16382
67500ef4d102
Check for negative array size in Array.newInstance
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16125
diff
changeset
|
44 } |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
16382
diff
changeset
|
45 if (probability(SLOW_PATH_PROBABILITY, componentType == void.class)) { |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
16382
diff
changeset
|
46 DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint); |
16125
cc76575f485c
handle error case in Array.newInstance
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
13971
diff
changeset
|
47 } |
21644
2c6802ac343c
Use graph builder plugin instead of node intrinsic for guarding non-null in snippets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
21556
diff
changeset
|
48 return DynamicNewArrayNode.newArray(GraalDirectives.guardingNonNull(componentType), length); |
10027 | 49 } |
13971 | 50 |
51 public static int getLength(Object array) { | |
52 if (!array.getClass().isArray()) { | |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
16382
diff
changeset
|
53 DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint); |
13971 | 54 } |
55 return ArrayLengthNode.arrayLength(array); | |
56 } | |
57 | |
10027 | 58 } |