-
Notifications
You must be signed in to change notification settings - Fork 564
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring, added LocalsHelper class to make it easier (hopefully) for
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
Showing
2 changed files
with
151 additions
and
79 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
jctools-experimental/src/main/java/org/jctools/channels/proxy/LocalsHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |||
} | |||
} |
Oops, something went wrong.