本文整理汇总了Java中org.objectweb.asm.commons.TableSwitchGenerator类的典型用法代码示例。如果您正苦于以下问题:Java TableSwitchGenerator类的具体用法?Java TableSwitchGenerator怎么用?Java TableSwitchGenerator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TableSwitchGenerator类属于org.objectweb.asm.commons包,在下文中一共展示了TableSwitchGenerator类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tableSwitch
import org.objectweb.asm.commons.TableSwitchGenerator; //导入依赖的package包/类
/** See {@link GeneratorAdapter#tableSwitch(int[], TableSwitchGenerator)} */
public void tableSwitch(int[] keys, TableSwitchGenerator generator) {
adapter.tableSwitch(keys, generator);
}
示例2: generateReattachTable
import org.objectweb.asm.commons.TableSwitchGenerator; //导入依赖的package包/类
/**
* Returns a statement that generates the reattach jump table.
*
* <p>Note: This statement should be the <em>first</em> statement in any detachable method.
*/
Statement generateReattachTable() {
final Expression readField = stateField.accessor(thisExpr);
final Statement defaultCase =
Statement.throwExpression(MethodRef.RUNTIME_UNEXPECTED_STATE_ERROR.invoke(readField));
return new Statement() {
@Override
protected void doGen(final CodeBuilder adapter) {
int[] keys = new int[reattaches.size()];
for (int i = 0; i < keys.length; i++) {
keys[i] = i;
}
readField.gen(adapter);
// Generate a switch table. Note, while it might be preferable to just 'goto state', Java
// doesn't allow computable gotos (probably because it makes verification impossible). So
// instead we emulate that with a jump table. And anyway we still need to execute 'restore'
// logic to repopulate the local variable tables, so the 'case' statements are a natural
// place for that logic to live.
adapter.tableSwitch(
keys,
new TableSwitchGenerator() {
@Override
public void generateCase(int key, Label end) {
if (key == 0) {
// State 0 is special, it means initial state, so we just jump to the very end
adapter.goTo(end);
return;
}
ReattachState reattachState = reattaches.get(key);
// restore and jump!
reattachState.restoreStatement().gen(adapter);
adapter.goTo(reattachState.reattachPoint());
}
@Override
public void generateDefault() {
defaultCase.gen(adapter);
}
},
// Use tableswitch instead of lookupswitch. TableSwitch is appropriate because our case
// labels are sequential integers in the range [0, N). This means that switch is O(1)
// and
// there are no 'holes' meaning that it is compact in the bytecode.
true);
}
};
}