From 109d5599794e73a7e7c88d834c4708fcddb367ad Mon Sep 17 00:00:00 2001
From: log2 <logtwo2@gmail.com>
Date: Mon, 10 Nov 2014 19:02:51 +0100
Subject: [PATCH] Reduced computational weight of bytecode generation by moving
reflection upon constructor in ByteCode's constructor (was in
newInstruction() method)
---
.../internal/instruction/InstructionSet.java | 24 ++++++++++++++-----
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/com.amd.aparapi/src/java/com/amd/aparapi/internal/instruction/InstructionSet.java b/com.amd.aparapi/src/java/com/amd/aparapi/internal/instruction/InstructionSet.java
index 4faf88df..976ef32d 100644
--- a/com.amd.aparapi/src/java/com/amd/aparapi/internal/instruction/InstructionSet.java
+++ b/com.amd.aparapi/src/java/com/amd/aparapi/internal/instruction/InstructionSet.java
@@ -629,6 +629,8 @@ public class InstructionSet{
private StoreSpec storeSpec;
+ private Constructor<?> constructor;
+
private ByteCode(Class<?> _class, LoadSpec _loadSpec, StoreSpec _storeSpec, ImmediateSpec _immediate, PopSpec _pop,
PushSpec _push, Operator _operator) {
clazz = _class;
@@ -639,6 +641,21 @@ public class InstructionSet{
loadSpec = _loadSpec;
storeSpec = _storeSpec;
+ if (clazz != null) {
+
+ try {
+ constructor = clazz.getDeclaredConstructor(MethodModel.class, ByteReader.class, boolean.class);
+ } catch (final SecurityException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (final NoSuchMethodException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (final IllegalArgumentException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
}
private ByteCode(Class<?> _class, ImmediateSpec _immediate) {
@@ -731,18 +748,13 @@ public class InstructionSet{
public Instruction newInstruction(MethodModel _methodModel, ByteReader byteReader, boolean _isWide) {
Instruction newInstruction = null;
- if (clazz != null) {
-
+ if (constructor != null) {
try {
- final Constructor<?> constructor = clazz.getDeclaredConstructor(MethodModel.class, ByteReader.class, boolean.class);
newInstruction = (Instruction) constructor.newInstance(_methodModel, byteReader, _isWide);
newInstruction.setLength(byteReader.getOffset() - newInstruction.getThisPC());
} catch (final SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
- } catch (final NoSuchMethodException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
} catch (final IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
--
GitLab