Skip to content

Commit

Permalink
Refactoring, added LocalsHelper class to make it easier (hopefully) for
Browse files Browse the repository at this point in the history
the reader to follow local variable accesses within the code generator.

I've renamed some variable names to be consistent with DemoProxyResult.
e.g. wOffset was used in implementProcess and getUnsafe but
usage in DemoProxyResult calls that rOffset.
  • Loading branch information
kay committed Nov 25, 2016
1 parent 0ef3df1 commit 9def529
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 79 deletions.
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.jctools.channels.proxy;

import static java.lang.System.out;

import org.objectweb.asm.Type;

public final class LocalsHelper {
private int nextLocalIndex = 0;

private LocalsHelper() {
};

public int newLocal(Class<?> cls) {
Type type = Type.getType(cls);
return newLocal(type);
}


private int newLocal(Type type) {
final int myIndex = nextLocalIndex;
nextLocalIndex += type.getSize();
return myIndex;
}

public static LocalsHelper forStaticMethod() {
return new LocalsHelper();
}

public static LocalsHelper forInstanceMethod() {
LocalsHelper helper = new LocalsHelper();
helper.newLocal(Object.class);
return helper;
}

public static void main(String[] args) throws Exception {
LocalsHelper helper =
LocalsHelper.forInstanceMethod();
out.println(helper.newLocal(int.class));
out.println(helper.newLocal(int.class));
out.println(helper.newLocal(long.class));
out.println(helper.newLocal(double.class));
out.println(helper.newLocal(boolean.class));
out.println(helper.newLocal(Object.class));
out.println(helper.newLocal(Object.class));
out.println(helper.newLocal(Object.class));
out.println();
}
}
Loading

0 comments on commit 9def529

Please sign in to comment.