diff options
author | Mathieu Chartier <mathieuc@google.com> | 2015-04-24 17:05:16 -0700 |
---|---|---|
committer | Mathieu Chartier <mathieuc@google.com> | 2015-04-24 19:43:15 -0700 |
commit | 2abeaa62bbba16960e3d824745b77705478f8450 (patch) | |
tree | 65aa92fe83118ea1482d69bcbf5cdac7d2054bbe /libart | |
parent | dce989e53c440c7bb0eec93abf20a71bf1f49b1c (diff) | |
download | libcore-2abeaa62bbba16960e3d824745b77705478f8450.zip libcore-2abeaa62bbba16960e3d824745b77705478f8450.tar.gz libcore-2abeaa62bbba16960e3d824745b77705478f8450.tar.bz2 |
Move Class.newInstance to native
Also add benchmark for Class.newInstance.
Bug: 20269715
Change-Id: Icd52155ce79a978a4d869855bfdfd7735abd8187
Diffstat (limited to 'libart')
-rw-r--r-- | libart/src/main/java/java/lang/Class.java | 28 | ||||
-rw-r--r-- | libart/src/main/java/java/lang/reflect/Constructor.java | 7 |
2 files changed, 1 insertions, 34 deletions
diff --git a/libart/src/main/java/java/lang/Class.java b/libart/src/main/java/java/lang/Class.java index 1072ce8..99c562f 100644 --- a/libart/src/main/java/java/lang/Class.java +++ b/libart/src/main/java/java/lang/Class.java @@ -1379,33 +1379,7 @@ public final class Class<T> implements Serializable, AnnotatedElement, GenericDe * @throws InstantiationException * if the instance cannot be created. */ - public T newInstance() throws InstantiationException, IllegalAccessException { - if (isPrimitive() || isInterface() || isArray() || Modifier.isAbstract(accessFlags)) { - throw new InstantiationException(this + " cannot be instantiated"); - } - Class<?> caller = VMStack.getStackClass1(); - if (!caller.canAccess(this)) { - throw new IllegalAccessException(this + " is not accessible from " + caller); - } - Constructor<T> init; - try { - init = getDeclaredConstructor(); - } catch (NoSuchMethodException e) { - InstantiationException t = - new InstantiationException(this + " has no zero argument constructor"); - t.initCause(e); - throw t; - } - if (!caller.canAccessMember(this, init.getAccessFlags())) { - throw new IllegalAccessException(init + " is not accessible from " + caller); - } - try { - return init.newInstanceTwoFrames(); - } catch (InvocationTargetException e) { - SneakyThrow.sneakyThrow(e.getCause()); - return null; // Unreachable. - } - } + public native T newInstance() throws InstantiationException, IllegalAccessException; private boolean canAccess(Class<?> c) { if(Modifier.isPublic(c.accessFlags)) { diff --git a/libart/src/main/java/java/lang/reflect/Constructor.java b/libart/src/main/java/java/lang/reflect/Constructor.java index 9701147..9711ef4 100644 --- a/libart/src/main/java/java/lang/reflect/Constructor.java +++ b/libart/src/main/java/java/lang/reflect/Constructor.java @@ -284,13 +284,6 @@ public final class Constructor<T> extends AbstractMethod implements GenericDecla IllegalAccessException, IllegalArgumentException, InvocationTargetException; /** - * Special version that looks up two frames for access check. Used by Class.newInstance. - * @hide - */ - public native T newInstanceTwoFrames(Object... args) throws InstantiationException, - IllegalAccessException, IllegalArgumentException, InvocationTargetException; - - /** * Returns a string containing a concise, human-readable description of this * constructor. The format of the string is: * |