Mercurial > hg > truffle
annotate graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ArraySubstitutions.java @ 16125:cc76575f485c
handle error case in Array.newInstance
author | Tom Rodriguez <tom.rodriguez@oracle.com> |
---|---|
date | Tue, 17 Jun 2014 12:47:45 -0700 |
parents | 3e5b9a4d5986 |
children | 67500ef4d102 |
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 | |
25 import com.oracle.graal.api.replacements.*; | |
26 import com.oracle.graal.nodes.*; | |
27 import com.oracle.graal.nodes.java.*; | |
28 | |
29 /** | |
30 * Substitutions for {@link java.lang.reflect.Array} methods. | |
31 */ | |
32 @ClassSubstitution(java.lang.reflect.Array.class) | |
33 public class ArraySubstitutions { | |
34 | |
35 @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
|
36 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
|
37 // 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
|
38 // caller in response to exceptions. |
cc76575f485c
handle error case in Array.newInstance
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
13971
diff
changeset
|
39 if (componentType == void.class) { |
cc76575f485c
handle error case in Array.newInstance
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
13971
diff
changeset
|
40 throw new IllegalArgumentException(); |
cc76575f485c
handle error case in Array.newInstance
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
13971
diff
changeset
|
41 } |
10652
aca7481e71d1
Create new intrinsic for GuardingPiNode for null check guarding. Fix ArraySubstitutions.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10542
diff
changeset
|
42 return DynamicNewArrayNode.newArray(GuardingPiNode.guardingNonNull(componentType), length); |
10027 | 43 } |
13971 | 44 |
45 @MethodSubstitution | |
46 public static int getLength(Object array) { | |
47 if (!array.getClass().isArray()) { | |
48 throw new IllegalArgumentException("Argument is not an array"); | |
49 } | |
50 return ArrayLengthNode.arrayLength(array); | |
51 } | |
52 | |
10027 | 53 } |