/** * Matches any type description that is a subtype of the given type. * * @param type The type to be checked for being a subtype of the matched type. * @param <T> The type of the matched object. * @return A matcher that matches any type description that represents a sub type of the given type. */ public static <T extends TypeDescription> ElementMatcher.Junction<T> isSubTypeOf(Class<?> type) { return isSubTypeOf(TypeDescription.ForLoadedType.of(type)); }
@Override public ElementMatcher.Junction<TypeDescription> getExtraIncludeTypeMatcher() { return nameEndsWith("Filter").and(isSubTypeOf(Filter.class)); }
@Override public ElementMatcher.Junction<TypeDescription> getExtraIncludeTypeMatcher() { return nameEndsWith("Servlet").and(isSubTypeOf(Servlet.class)); }
public static ElementMatcher.Junction<TypeDescription> isInsideMonitoredProject() { return INSTANCE.and(not(isSubTypeOf(StagemonitorByteBuddyTransformer.class))); }
@Override public ElementMatcher.Junction<TypeDescription> getTypeMatcher() { // It's important to pre-select potential matches first with the nameContains matcher // otherwise, the type hierarchy of each and every class has to be determined whether it derives from Binding return nameContains("Binding") .and(not(isInterface())) .and(isSubTypeOf(Binding.class)); }
public static synchronized void removeTransformer() { if (alignmentTransformer != null) { instrumentation.removeTransformer(alignmentTransformer); instrumentation.removeTransformer(new AgentBuilder.Default() .type(isSubTypeOf(DirectBuffer.class).and(not(isInterface()))) .transform(AgentBuilder.Transformer.NoOp.INSTANCE).installOn(instrumentation)); alignmentTransformer = null; instrumentation = null; } } }
/** * Creates a record for a visibility bridge. * * @param instrumentedType The instrumented type. * @param bridgeTarget The target method of the visibility bridge. * @param attributeAppender The attribute appender to apply to the visibility bridge. * @return A record describing the visibility bridge. */ public static Record of(TypeDescription instrumentedType, MethodDescription bridgeTarget, MethodAttributeAppender attributeAppender) { // Default method bridges must be dispatched on an implemented interface type, not considering the declaring type. TypeDefinition bridgeType = null; if (bridgeTarget.isDefaultMethod()) { TypeDescription declaringType = bridgeTarget.getDeclaringType().asErasure(); for (TypeDescription interfaceType : instrumentedType.getInterfaces().asErasures().filter(isSubTypeOf(declaringType))) { if (bridgeType == null || declaringType.isAssignableTo(bridgeType.asErasure())) { bridgeType = interfaceType; } } } // Non-default method or default method that is inherited by a super class. if (bridgeType == null) { bridgeType = instrumentedType.getSuperClass(); } return new OfVisibilityBridge(new VisibilityBridge(instrumentedType, bridgeTarget), bridgeTarget, bridgeType.asErasure(), attributeAppender); }
private static synchronized void agent(final boolean shouldRedefine, final Instrumentation instrumentation) { BufferAlignmentAgent.instrumentation = instrumentation; // all Int methods, and all String method other than // XXXStringWithoutLengthXXX or getStringXXX(int, int) final Junction<MethodDescription> intVerifierMatcher = nameContains("Int") .or(nameMatches(".*String[^W].*").and(not(ElementMatchers.takesArguments(int.class, int.class)))); alignmentTransformer = new AgentBuilder.Default(new ByteBuddy().with(TypeValidation.DISABLED)) .with(LISTENER) .disableClassFormatChanges() .with(shouldRedefine ? AgentBuilder.RedefinitionStrategy.RETRANSFORMATION : AgentBuilder.RedefinitionStrategy.DISABLED) .type(isSubTypeOf(DirectBuffer.class).and(not(isInterface()))) .transform((builder, typeDescription, classLoader, module) -> builder .visit(to(LongVerifier.class).on(nameContains("Long"))) .visit(to(DoubleVerifier.class).on(nameContains("Double"))) .visit(to(IntVerifier.class).on(intVerifierMatcher)) .visit(to(FloatVerifier.class).on(nameContains("Float"))) .visit(to(ShortVerifier.class).on(nameContains("Short"))) .visit(to(CharVerifier.class).on(nameContains("Char")))) .installOn(instrumentation); }
@Override public ElementMatcher.Junction<TypeDescription> getExtraIncludeTypeMatcher() { return nameEndsWith("Servlet").and(isSubTypeOf(Servlet.class)); }
@Override public ElementMatcher.Junction<TypeDescription> getExtraIncludeTypeMatcher() { return nameEndsWith("Filter").and(isSubTypeOf(Filter.class)); }
/** * @return */ public ClassFileTransformer getTransformer() { logger.info("Creating a class file transformer"); AgentBuilder builder = new AgentBuilder.Default() .with(AgentBuilder.PoolStrategy.Default.FAST) .type(ElementMatchers.isSubTypeOf(Model.class).and(ElementMatchers.isAnnotatedWith(Entity.class))) .transform(this); return instrumentation != null ? builder.installOn(instrumentation) : builder.installOnByteBuddyAgent(); }