本文整理汇总了Java中net.bytebuddy.implementation.Implementation类的典型用法代码示例。如果您正苦于以下问题:Java Implementation类的具体用法?Java Implementation怎么用?Java Implementation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Implementation类属于net.bytebuddy.implementation包,在下文中一共展示了Implementation类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: check
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
@Override
public final void check() throws Exception {
Implementation.Context implementationContext = EasyMock.createMock(
Implementation.Context.class
);
final MethodVisitorRecorder patternMvr = new MethodVisitorRecorder();
final MethodVisitorRecorder actualMvr = new MethodVisitorRecorder();
pattern.accept(patternMvr);
System.out.println("Expectation:");
patternMvr.trace();
sm.apply(actualMvr, implementationContext);
System.out.println("Reality:");
actualMvr.trace();
assertThat(actualMvr).isEqualTo(patternMvr);
}
开发者ID:project-avral,项目名称:oo-atom,代码行数:20,代码来源:AssertStackManipulationProducesExpectedBytecode.java
示例2: createAgentBuilder
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
/**
* Creates the AgentBuilder that will redefine the System class.
* @param inst instrumentation instance.
* @return an agent builder.
*/
private static AgentBuilder createAgentBuilder(Instrumentation inst) {
// Find me a class called "java.lang.System"
final ElementMatcher.Junction<NamedElement> systemType = ElementMatchers.named("java.lang.System");
// And then find a method called setSecurityManager and tell MySystemInterceptor to
// intercept it (the method binding is smart enough to take it from there)
final AgentBuilder.Transformer transformer =
(b, typeDescription) -> b.method(ElementMatchers.named("setSecurityManager"))
.intercept(MethodDelegation.to(MySystemInterceptor.class));
// Disable a bunch of stuff and turn on redefine as the only option
final ByteBuddy byteBuddy = new ByteBuddy().with(Implementation.Context.Disabled.Factory.INSTANCE);
final AgentBuilder agentBuilder = new AgentBuilder.Default()
.withByteBuddy(byteBuddy)
.withInitializationStrategy(AgentBuilder.InitializationStrategy.NoOp.INSTANCE)
.withRedefinitionStrategy(AgentBuilder.RedefinitionStrategy.REDEFINITION)
.withTypeStrategy(AgentBuilder.TypeStrategy.Default.REDEFINE)
.type(systemType)
.transform(transformer);
return agentBuilder;
}
开发者ID:wsargent,项目名称:securityfixer,代码行数:29,代码来源:SecurityFixerAgent.java
示例3: apply
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) {
switch (variableIndex) {
case 0:
methodVisitor.visitInsn(storeOpcode + storeOpcodeShortcutOffset);
break;
case 1:
methodVisitor.visitInsn(storeOpcode + storeOpcodeShortcutOffset + 1);
break;
case 2:
methodVisitor.visitInsn(storeOpcode + storeOpcodeShortcutOffset + 2);
break;
case 3:
methodVisitor.visitInsn(storeOpcode + storeOpcodeShortcutOffset + 3);
break;
default:
methodVisitor.visitVarInsn(storeOpcode, variableIndex);
break;
}
return size;
}
开发者ID:bramp,项目名称:unsafe,代码行数:21,代码来源:MethodVariableStore.java
示例4: apply
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext,
MethodDescription instrumentedMethod) {
checkMethodSignature(instrumentedMethod);
try {
StackManipulation stack = buildStack();
StackManipulation.Size finalStackSize = stack.apply(methodVisitor, implementationContext);
return new Size(finalStackSize.getMaximalSize(),
instrumentedMethod.getStackSize() + 2); // 2 stack slots for a single local variable
} catch (NoSuchMethodException | NoSuchFieldException e) {
throw new RuntimeException(e);
}
}
开发者ID:bramp,项目名称:unsafe,代码行数:17,代码来源:CopierImplementation.java
示例5: apply
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
@Override
public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext,
MethodDescription instrumentedMethod) {
switch (returnType) {
case REFERENCE:
return new Size(MethodReturn.REFERENCE.apply(methodVisitor, implementationContext).getMaximalSize(),
instrumentedMethod.getStackSize());
case VOID:
return new Size(MethodReturn.VOID.apply(methodVisitor, implementationContext).getMaximalSize(),
instrumentedMethod.getStackSize());
case INT:
return new Size(MethodReturn.INTEGER.apply(methodVisitor, implementationContext).getMaximalSize(),
instrumentedMethod.getStackSize());
default:
throw new IllegalStateException("Illegal opType");
}
}
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:19,代码来源:ReturnAppender.java
示例6: apply
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
@Override
public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext,
MethodDescription instrumentedMethod) {
int numArgs = instrumentedMethod.getParameters().asTypeList().getStackSize();
/**
* Load the desired id
* relative to the method arguments.
* The idea here would be to load references
* to declared variables
*/
//references start with zero if its an instance or zero if its static
//think of it like an implicit self in python without actually being defined
int start = instrumentedMethod.isStatic() ? 1 : 0;
StackManipulation arg0 = MethodVariableAccess.REFERENCE
.loadOffset(numArgs + start + OpCodeUtil.getAloadInstructionForReference(refId));
StackManipulation.Size size = arg0.apply(methodVisitor, implementationContext);
return new Size(size.getMaximalSize(), instrumentedMethod.getStackSize());
}
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:19,代码来源:LoadDeclaredInternalReference.java
示例7: testRetrieveFromArray
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
@Test
public void testRetrieveFromArray() throws Exception {
DynamicType.Unloaded<RetrieveFromArray> arr = new ByteBuddy().subclass(RetrieveFromArray.class)
.method(ElementMatchers.isDeclaredBy(RetrieveFromArray.class))
.intercept(new Implementation.Compound(new LoadReferenceParamImplementation(1),
new RelativeRetrieveArrayImplementation(1),
new ReturnAppenderImplementation(ReturnAppender.ReturnType.INT)))
.make();
Class<?> dynamicType = arr.load(RetrieveFromArray.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
.getLoaded();
RetrieveFromArray test = (RetrieveFromArray) dynamicType.newInstance();
int result = test.returnVal(0, 1);
assertEquals(1, result);
}
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:19,代码来源:RelativeRetrieveTest.java
示例8: testCreateAndAssign
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
@Test
public void testCreateAndAssign() throws Exception {
DynamicType.Unloaded<CreateAndAssignArray> arr = new ByteBuddy().subclass(CreateAndAssignArray.class)
.method(ElementMatchers.isDeclaredBy(CreateAndAssignArray.class))
.intercept(new Implementation.Compound(new IntArrayCreation(5), new DuplicateImplementation(),
new RelativeArrayAssignWithValueImplementation(0, 5),
new ReturnAppenderImplementation(ReturnAppender.ReturnType.REFERENCE)))
.make();
Class<?> dynamicType =
arr.load(CreateAndAssignArray.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
.getLoaded();
CreateAndAssignArray test = (CreateAndAssignArray) dynamicType.newInstance();
int[] result = test.create();
assertEquals(5, result[0]);
}
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:19,代码来源:TestAggregateByteCodeAppender.java
示例9: testCreateInt
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
@Test
public void testCreateInt() throws Exception {
DynamicType.Unloaded<CreateAndAssignIntArray> arr = new ByteBuddy().subclass(CreateAndAssignIntArray.class)
.method(ElementMatchers.isDeclaredBy(CreateAndAssignIntArray.class))
.intercept(new Implementation.Compound(new ConstantIntImplementation(1),
new StoreIntImplementation(0), new LoadIntegerImplementation(0),
new ReturnAppenderImplementation(ReturnAppender.ReturnType.INT)))
.make();
Class<?> dynamicType =
arr.load(CreateAndAssignIntArray.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
.getLoaded();
CreateAndAssignIntArray test = (CreateAndAssignIntArray) dynamicType.newInstance();
int result = test.returnVal();
assertEquals(1, result);
}
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:20,代码来源:CreateIntTests.java
示例10: disableClassFormatChanges
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
@Override
public AgentBuilder disableClassFormatChanges() {
return new Default(byteBuddy.with(Implementation.Context.Disabled.Factory.INSTANCE),
listener,
circularityLock,
poolStrategy,
TypeStrategy.Default.REDEFINE_FROZEN,
locationStrategy,
NativeMethodStrategy.Disabled.INSTANCE,
InitializationStrategy.NoOp.INSTANCE,
redefinitionStrategy,
redefinitionDiscoveryStrategy,
redefinitionBatchAllocator,
redefinitionListener,
redefinitionResubmissionStrategy,
bootstrapInjectionStrategy,
lambdaInstrumentationStrategy,
descriptionStrategy,
fallbackStrategy,
installationListener,
ignoredTypeMatcher,
transformation);
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:24,代码来源:AgentBuilder.java
示例11: bind
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
@Override
public Bound.ForMethodEnter bind(TypeDescription instrumentedType,
MethodDescription instrumentedMethod,
MethodVisitor methodVisitor,
Implementation.Context implementationContext,
Assigner assigner,
MethodSizeHandler.ForInstrumentedMethod methodSizeHandler,
StackMapFrameHandler.ForInstrumentedMethod stackMapFrameHandler,
StackManipulation exceptionHandler) {
return new AdviceMethodInliner(instrumentedType,
instrumentedMethod,
methodVisitor,
implementationContext,
assigner,
methodSizeHandler,
stackMapFrameHandler,
suppressionHandler.bind(exceptionHandler),
classReader,
skipDispatcher);
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:21,代码来源:Advice.java
示例12: AdviceMethodInliner
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
/**
* Creates a new advice method inliner for a method enter.
*
* @param instrumentedType A description of the instrumented type.
* @param instrumentedMethod A description of the instrumented method.
* @param methodVisitor The method visitor for writing the instrumented method.
* @param implementationContext The implementation context to use.
* @param assigner The assigner to use.
* @param methodSizeHandler A handler for computing the method size requirements.
* @param stackMapFrameHandler A handler for translating and injecting stack map frames.
* @param suppressionHandler A bound suppression handler that is used for suppressing exceptions of this advice method.
* @param classReader A class reader for parsing the class file containing the represented advice method.
* @param skipDispatcher The skip dispatcher to use.
*/
protected AdviceMethodInliner(TypeDescription instrumentedType,
MethodDescription instrumentedMethod,
MethodVisitor methodVisitor,
Implementation.Context implementationContext,
Assigner assigner,
MethodSizeHandler.ForInstrumentedMethod methodSizeHandler,
StackMapFrameHandler.ForInstrumentedMethod stackMapFrameHandler,
SuppressionHandler.Bound suppressionHandler,
ClassReader classReader,
SkipDispatcher skipDispatcher) {
super(instrumentedType,
instrumentedMethod,
methodVisitor,
implementationContext,
assigner,
methodSizeHandler,
stackMapFrameHandler,
suppressionHandler,
classReader);
this.skipDispatcher = skipDispatcher;
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:36,代码来源:Advice.java
示例13: ForMethodEnter
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
/**
* Creates a new advice method writer.
*
* @param adviceMethod The advice method.
* @param instrumentedMethod The instrumented method.
* @param offsetMappings The offset mappings available to this advice.
* @param methodVisitor The method visitor for writing the instrumented method.
* @param implementationContext The implementation context to use.
* @param methodSizeHandler A handler for computing the method size requirements.
* @param stackMapFrameHandler A handler for translating and injecting stack map frames.
* @param suppressionHandler A bound suppression handler that is used for suppressing exceptions of this advice method.
* @param skipDispatcher The skip dispatcher to use.
*/
protected ForMethodEnter(MethodDescription.InDefinedShape adviceMethod,
MethodDescription instrumentedMethod,
List<OffsetMapping.Target> offsetMappings,
MethodVisitor methodVisitor,
Implementation.Context implementationContext,
MethodSizeHandler.ForAdvice methodSizeHandler,
StackMapFrameHandler.ForAdvice stackMapFrameHandler,
SuppressionHandler.Bound suppressionHandler,
Resolved.ForMethodEnter.SkipDispatcher skipDispatcher) {
super(adviceMethod,
instrumentedMethod,
offsetMappings,
methodVisitor,
implementationContext,
methodSizeHandler,
stackMapFrameHandler,
suppressionHandler);
this.skipDispatcher = skipDispatcher;
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:33,代码来源:Advice.java
示例14: resolve
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
@Override
protected Bound.ForMethodEnter resolve(TypeDescription instrumentedType,
MethodDescription instrumentedMethod,
MethodVisitor methodVisitor,
Implementation.Context implementationContext,
Assigner assigner,
MethodSizeHandler.ForInstrumentedMethod methodSizeHandler,
StackMapFrameHandler.ForInstrumentedMethod stackMapFrameHandler,
StackManipulation exceptionHandler) {
List<OffsetMapping.Target> offsetMappings = new ArrayList<OffsetMapping.Target>(this.offsetMappings.size());
for (OffsetMapping offsetMapping : this.offsetMappings) {
offsetMappings.add(offsetMapping.resolve(instrumentedType,
instrumentedMethod,
assigner,
OffsetMapping.Context.ForMethodEntry.of(instrumentedMethod)));
}
return new AdviceMethodWriter.ForMethodEnter(adviceMethod,
instrumentedMethod,
offsetMappings,
methodVisitor,
implementationContext,
methodSizeHandler.bindEntry(adviceMethod),
stackMapFrameHandler.bindEntry(adviceMethod),
suppressionHandler.bind(exceptionHandler),
skipDispatcher);
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:27,代码来源:Advice.java
示例15: wrap
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
@Override
public ModifierAdjustingClassVisitor wrap(TypeDescription instrumentedType,
ClassVisitor classVisitor,
Implementation.Context implementationContext,
TypePool typePool,
FieldList<FieldDescription.InDefinedShape> fields,
MethodList<?> methods,
int writerFlags,
int readerFlags) {
Map<String, FieldDescription.InDefinedShape> mappedFields = new HashMap<String, FieldDescription.InDefinedShape>();
for (FieldDescription.InDefinedShape fieldDescription : fields) {
mappedFields.put(fieldDescription.getInternalName() + fieldDescription.getDescriptor(), fieldDescription);
}
Map<String, MethodDescription> mappedMethods = new HashMap<String, MethodDescription>();
for (MethodDescription methodDescription : CompoundList.<MethodDescription>of(methods, new MethodDescription.Latent.TypeInitializer(instrumentedType))) {
mappedMethods.put(methodDescription.getInternalName() + methodDescription.getDescriptor(), methodDescription);
}
return new ModifierAdjustingClassVisitor(classVisitor,
typeAdjustments,
fieldAdjustments,
methodAdjustments,
instrumentedType,
mappedFields,
mappedMethods);
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:26,代码来源:ModifierAdjustment.java
示例16: wrap
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
@Override
public MethodVisitor wrap(TypeDescription instrumentedType,
MethodDescription instrumentedMethod,
MethodVisitor methodVisitor,
Implementation.Context implementationContext,
TypePool typePool,
int writerFlags,
int readerFlags) {
for (MethodVisitorWrapper methodVisitorWrapper : methodVisitorWrappers) {
methodVisitor = methodVisitorWrapper.wrap(instrumentedType,
instrumentedMethod,
methodVisitor,
implementationContext,
typePool,
writerFlags,
readerFlags);
}
return methodVisitor;
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:20,代码来源:AsmVisitorWrapper.java
示例17: wrap
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
@Override
public MethodVisitor wrap(TypeDescription instrumentedType,
MethodDescription instrumentedMethod,
MethodVisitor methodVisitor,
Implementation.Context implementationContext,
TypePool typePool,
int writerFlags,
int readerFlags) {
return new SubstitutingMethodVisitor(methodVisitor,
methodGraphCompiler,
strict,
substitution,
instrumentedType,
implementationContext,
typePoolResolver.resolve(instrumentedType, instrumentedMethod, typePool));
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:17,代码来源:MemberSubstitution.java
示例18: prepareArgumentBinder
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static MethodDelegationBinder.ParameterBinding<?> prepareArgumentBinder(TargetMethodAnnotationDrivenBinder.ParameterBinder<?> parameterBinder,
Class<? extends Annotation> annotationType,
Object identificationToken) {
doReturn(annotationType).when(parameterBinder).getHandledType();
MethodDelegationBinder.ParameterBinding<?> parameterBinding = mock(MethodDelegationBinder.ParameterBinding.class);
when(parameterBinding.isValid()).thenReturn(true);
when(parameterBinding.apply(any(MethodVisitor.class), any(Implementation.Context.class))).thenReturn(new StackManipulation.Size(0, 0));
when(parameterBinding.getIdentificationToken()).thenReturn(identificationToken);
when(((TargetMethodAnnotationDrivenBinder.ParameterBinder) parameterBinder).bind(any(AnnotationDescription.Loadable.class),
any(MethodDescription.class),
any(ParameterDescription.class),
any(Implementation.Target.class),
any(Assigner.class),
any(Assigner.Typing.class)))
.thenReturn(parameterBinding);
return parameterBinding;
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:19,代码来源:TargetMethodAnnotationDrivenBinderTest.java
示例19: apply
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
@Override
public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) {
try {
return new StackManipulation.Compound(
TypeCreation.of(new TypeDescription.ForLoadedType(ObjectInputStream.class)),
Duplication.SINGLE,
TypeCreation.of(new TypeDescription.ForLoadedType(ByteArrayInputStream.class)),
Duplication.SINGLE,
new TextConstant(serialization),
new TextConstant(CHARSET),
MethodInvocation.invoke(new MethodDescription.ForLoadedMethod(String.class.getMethod("getBytes", String.class))),
MethodInvocation.invoke(new MethodDescription.ForLoadedConstructor(ByteArrayInputStream.class.getConstructor(byte[].class))),
MethodInvocation.invoke(new MethodDescription.ForLoadedConstructor(ObjectInputStream.class.getConstructor(InputStream.class))),
MethodInvocation.invoke(new MethodDescription.ForLoadedMethod(ObjectInputStream.class.getMethod("readObject")))
).apply(methodVisitor, implementationContext);
} catch (NoSuchMethodException exception) {
throw new IllegalStateException("Could not locate Java API method", exception);
}
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:20,代码来源:SerializedConstant.java
示例20: testRebasedConstructorIsInvokable
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
@Test
public void testRebasedConstructorIsInvokable() throws Exception {
when(rebasedMethod.isConstructor()).thenReturn(true);
when(invokableMethod.getDeclaringType()).thenReturn(instrumentedType);
when(resolution.isRebased()).thenReturn(true);
when(resolution.getResolvedMethod()).thenReturn(rebasedMethod);
when(resolution.getAdditionalArguments()).thenReturn(NullConstant.INSTANCE);
when(rebasedMethod.isSpecializableFor(instrumentedType)).thenReturn(true);
Implementation.SpecialMethodInvocation specialMethodInvocation = makeImplementationTarget().invokeSuper(rebasedSignatureToken);
assertThat(specialMethodInvocation.isValid(), is(true));
assertThat(specialMethodInvocation.getMethodDescription(), is((MethodDescription) rebasedMethod));
assertThat(specialMethodInvocation.getTypeDescription(), is(instrumentedType));
MethodVisitor methodVisitor = mock(MethodVisitor.class);
Implementation.Context implementationContext = mock(Implementation.Context.class);
StackManipulation.Size size = specialMethodInvocation.apply(methodVisitor, implementationContext);
verify(methodVisitor).visitInsn(Opcodes.ACONST_NULL);
verify(methodVisitor).visitMethodInsn(Opcodes.INVOKESPECIAL, BAZ, QUX, FOO, false);
verifyNoMoreInteractions(methodVisitor);
verifyZeroInteractions(implementationContext);
assertThat(size.getSizeImpact(), is(1));
assertThat(size.getMaximalSize(), is(1));
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:23,代码来源:RebaseImplementationTargetTest.java
注:本文中的net.bytebuddy.implementation.Implementation类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论