Mercurial > hg > truffle
annotate graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ArraySubstitutions.java @ 19791:14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 11 Mar 2015 20:43:12 +0100 |
parents | 67500ef4d102 |
children | 91a25b017111 |
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 |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
16382
diff
changeset
|
27 import com.oracle.graal.api.meta.*; |
10027 | 28 import com.oracle.graal.api.replacements.*; |
29 import com.oracle.graal.nodes.*; | |
30 import com.oracle.graal.nodes.java.*; | |
31 | |
32 /** | |
33 * Substitutions for {@link java.lang.reflect.Array} methods. | |
34 */ | |
35 @ClassSubstitution(java.lang.reflect.Array.class) | |
36 public class ArraySubstitutions { | |
37 | |
38 @MethodSubstitution | |
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 } |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
16382
diff
changeset
|
48 return DynamicNewArrayNode.newArray(GuardingPiNode.asNonNullClass(componentType), length); |
10027 | 49 } |
13971 | 50 |
51 @MethodSubstitution | |
52 public static int getLength(Object array) { | |
53 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
|
54 DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint); |
13971 | 55 } |
56 return ArrayLengthNode.arrayLength(array); | |
57 } | |
58 | |
10027 | 59 } |