Performs a benchmark of a super method invocation using Byte Buddy. This benchmark uses an annotation-based
approach which is more difficult to optimize by the JIT compiler.

@param blackHole A black hole for avoiding JIT erasure.
508558
@Benchmark
    @OperationsPerInvocation(20)
    public void benchmarkByteBuddyWithProxy(Blackhole blackHole) {
        blackHole.consume(byteBuddyWithProxyInstance.method(booleanValue));
        blackHole.consume(byteBuddyWithProxyInstance.method(byteValue));
        blackHole.consume(byteBuddyWithProxyInstance.method(shortValue));
        blackHole.consume(byteBuddyWithProxyInstance.method(intValue));
        blackHole.consume(byteBuddyWithProxyInstance.method(charValue));
        blackHole.consume(byteBuddyWithProxyInstance.method(intValue));
        blackHole.consume(byteBuddyWithProxyInstance.method(longValue));
        blackHole.consume(byteBuddyWithProxyInstance.method(floatValue));
        blackHole.consume(byteBuddyWithProxyInstance.method(doubleValue));
        blackHole.consume(byteBuddyWithProxyInstance.method(stringValue));
        blackHole.consume(byteBuddyWithProxyInstance.method(booleanValue, booleanValue, booleanValue));
        blackHole.consume(byteBuddyWithProxyInstance.method(byteValue, byteValue, byteValue));
        blackHole.consume(byteBuddyWithProxyInstance.method(shortValue, shortValue, shortValue));
        blackHole.consume(byteBuddyWithProxyInstance.method(intValue, intValue, intValue));
        blackHole.consume(byteBuddyWithProxyInstance.method(charValue, charValue, charValue));
        blackHole.consume(byteBuddyWithProxyInstance.method(intValue, intValue, intValue));
        blackHole.consume(byteBuddyWithProxyInstance.method(longValue, longValue, longValue));
        blackHole.consume(byteBuddyWithProxyInstance.method(floatValue, floatValue, floatValue));
        blackHole.consume(byteBuddyWithProxyInstance.method(doubleValue, doubleValue, doubleValue));
        blackHole.consume(byteBuddyWithProxyInstance.method(stringValue, stringValue, stringValue));
    }
878316
@Override
    public void visitMethod(Method obj) {
        firstLocalRegister = SignatureUtils.getFirstRegisterSlot(obj);
        super.visitMethod(obj);
    }
950742
@Override
	public void visitClassContext(ClassContext classContext) {
		try {
			stack = new OpcodeStack();
			localMethodCalls = new HashMap<>();
			fieldMethodCalls = new HashMap<>();
			staticMethodCalls = new HashMap<>();
			branchTargets = new BitSet();
			super.visitClassContext(classContext);
		} finally {
			stack = null;
			localMethodCalls = null;
			fieldMethodCalls = null;
			staticMethodCalls = null;
			branchTargets = null;
		}
	}
648116
public void setUpBenchmark(Object benchmarkInstance) throws UserCodeException {
    boolean setupSuccess = false;
    try {
      callSetUp(benchmarkInstance);
      setupSuccess = true;
    } finally {
      // If setUp fails, we should call tearDown. If this method throws an exception, we
      // need to call tearDown from here, because no one else has the reference to the
      // Benchmark.
      if (!setupSuccess) {
        callTearDown(benchmarkInstance);
      }
    }
  }
492073
public boolean runBenchmark() throws SocketViewException {
		final BenchmarkResult res = benchmark.run();
		new TabularSummaryOutput().visitBenchmark(res);
		view.finished();
		return true;
	}
1194978
public <X> X invokeOnInstance(Object instance, Object... parameters) throws IllegalArgumentException, SecurityException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
        final Map<Class<?>, Method> methods = this.methods;
        Method method = methods.get(instance.getClass());
        if (method == null) {
            // the same method may be written to the map twice, but that is ok
            // lookupMethod is very slow
            Method delegate = annotatedMethod.getJavaMember();
            method = SecurityActions.lookupMethod(instance.getClass(), delegate.getName(), delegate.getParameterTypes());
            SecurityActions.ensureAccessible(method);
            synchronized (this) {
                final Map<Class<?>, Method> newMethods = new HashMap<Class<?>, Method>(methods);
                newMethods.put(instance.getClass(), method);
                this.methods = WeldCollections.immutableMapView(newMethods);
            }
        }
        return cast(method.invoke(instance, parameters));
    }
392230
@Override
    public void visitMethod(Method obj) {
        Code c = obj.getCode();
        if (c != null) {
            byte[] opcodes = c.getCode();
            if (opcodes != null) {
                trPCPos = opcodes.length - 1;
                if (!obj.getSignature().endsWith(Values.SIG_VOID)) {
                    trPCPos -= 1;
                }
                trPCPos -= TAILRECURSIONFUDGE;
                possibleTailRecursion = true;
                isStatic = obj.isStatic();
                stack.resetForMethodEntry(this);
                super.visitMethod(obj);
            }
        }
    }
200660
private static Method asAccessibleMethod(ReloadableType methodDeclaringTypeReloadableType, Method method,
			Object target,
			boolean makeAccessibleCopy) throws IllegalAccessException {
		if (methodDeclaringTypeReloadableType != null && isDeleted(methodDeclaringTypeReloadableType, method)) {
			throw Exceptions.noSuchMethodError(method);
		}

		if (method.isAccessible()) {
			//More expensive check not required / copy not required
		}
		else {
			Class<?> clazz = method.getDeclaringClass();
			int mods = method.getModifiers();
			int classmods;

			//		ReloadableType rtype = getReloadableTypeIfHasBeenReloaded(clazz);
			if (methodDeclaringTypeReloadableType == null || !methodDeclaringTypeReloadableType.hasBeenReloaded()) {
				classmods = clazz.getModifiers();
			}
			else {
				//Note: the "super bit" may be set in class modifiers but we should block it out, it
				//shouldn't be shown to users of the reflection API.
				classmods = methodDeclaringTypeReloadableType.getLatestTypeDescriptor().getModifiers()
						& ~Opcodes.ACC_SUPER;
			}
			if (Modifier.isPublic(mods & classmods/*jlClassGetModifiers(clazz)*/)) {
				//More expensive check not required / copy not required
			}
			else {
				//More expensive check required
				Class<?> callerClass = getCallerClass();
				JVM.ensureMemberAccess(callerClass, clazz, target, mods);
				if (makeAccessibleCopy) {
					method = JVM.copyMethod(method); // copy: we must not change accessible flag on original method!
					method.setAccessible(true);
				}
			}
		}
		return makeAccessibleCopy ? method : null;
	}
1246565
@Override
    public void visitCode(Code obj) {
        Method m = getMethod();
        if (!Values.CONSTRUCTOR.equals(m.getName())) {
            super.visitCode(obj);
        }
    }
544812
@Override
  public int run(String[] args) throws Exception {
    parseArgs(args);
    // Create results file
    FileWriter results = new FileWriter(resultsFile, true);
    // Run all benchmarks
    int failed = 0;
    for (Method method : NNLatencyBenchmark.class.getMethods()) {
      if (method.isAnnotationPresent(Benchmark.class)) {
        results.write(method.getName() + " : ");
        try {
          setUp();
          try {
            method.invoke(this, results);
          } finally {
            tearDown();
          }
        } catch (Throwable e) {
          failed++;
          LOG.error(method.getName() + " failed with: ", e);
        }
        results.write("\n");
      }
    }
    results.close();
    return -failed;
  }
139004
protected static Invocable resolveExpectedJavaMethod(
            BshClassManager bcm, Class<?> clas, Object object,
            String name, Object[] args, boolean staticOnly )
            throws ReflectError, UtilEvalError {
        if ( object == Primitive.NULL )
            throw new UtilTargetError( new NullPointerException(
                "Attempt to invoke method " +name+" on null value" ) );

        Class<?>[] types = Types.getTypes(args);
        Invocable method = resolveJavaMethod( clas, name, types, staticOnly );
        if ( null != bcm && bcm.getStrictJava()
                && method != null && method.getDeclaringClass().isInterface()
                && method.getDeclaringClass() != clas
                && Modifier.isStatic(method.getModifiers()))
            // static interface methods are class only
            method = null;

        if ( method == null )
            throw new ReflectError(
                ( staticOnly ? "Static method " : "Method " )
                + StringUtil.methodString(name, types) +
                " not found in class'" + clas.getName() + "'");

        return method;
    }
161253
@Override
    public void visitCode(Code obj) {

        Method m = getMethod();
        if (m.isSynthetic()) {
            return;
        }

        if (isEnum && "values".equals(m.getName())) {
            return;
        }

        String sig = m.getSignature();
        int sigPos = sig.indexOf(")[");
        if (sigPos < 0) {
            return;
        }
        if (INITIAL_VALUE.equals(m.getName())) {
            try {
                if ((THREAD_LOCAL_CLASS == null) || getClassContext().getJavaClass().instanceOf(THREAD_LOCAL_CLASS)) {
                    return;
                }
            } catch (ClassNotFoundException e) {
                bugReporter.reportMissingClass(e);
                return;
            }
        }

        stack.resetForMethodEntry(this);
        returnArraySig = sig.substring(sigPos + 1);
        uninitializedRegs.clear();
        arrayAliases.clear();
        storedUVs.clear();
        super.visitCode(obj);
    }
345296
public static void runWith(
      String[] args, Function<BenchmarkSettings, AbstractBenchmarkState<?>> benchmarkStateFactory) {

    BenchmarkSettings settings = BenchmarkSettings.from(args).build();

    AbstractBenchmarkState<?> benchmarkState = benchmarkStateFactory.apply(settings);

    benchmarkState.runForAsync(
        state -> {
          LatencyHelper latencyHelper = new LatencyHelper(state);

          BenchmarkMeter clientToServiceMeter = state.meter("meter.client-to-service");
          BenchmarkMeter serviceToClientMeter = state.meter("meter.service-to-client");

          ThreadLocal<Mono<Client>> clientHolder =
              ThreadLocal.withInitial(() -> state.createClient().cache());

          return i -> {
            Mono<Client> clientMono = clientHolder.get();
            return clientMono.flatMap(
                client -> {
                  clientToServiceMeter.mark();
                  return client
                      .requestResponse(enrichRequest())
                      .map(RequestOneScenario::enrichResponse)
                      .doOnNext(
                          msg -> {
                            serviceToClientMeter.mark();
                            Optional.ofNullable(msg.data())
                                .ifPresent(ReferenceCountUtil::safestRelease);
                            latencyHelper.calculate(msg);
                          })
                      .doOnError(th -> LOGGER.warn("Exception occured on requestResponse: " + th));
                });
          };
        });
  }
612908
@Override
    @SuppressWarnings("unchecked")
    public void visitCode(final Code obj) {
        stack.resetForMethodEntry(this);
        thisClsAccessCount = 0;
        if (Values.STATIC_INITIALIZER.equals(methodName)) {
            return;
        }

        clsAccessCount = new HashMap<>();
        super.visitCode(obj);

        if (clsAccessCount.isEmpty()) {
            return;
        }
        Map.Entry<String, BitSet>[] envies = clsAccessCount.entrySet().toArray(new Map.Entry[clsAccessCount.size()]);
        Arrays.sort(envies, ACCESS_COUNT_COMPARATOR);

        Map.Entry<String, BitSet> bestEnvyEntry = envies[0];
        int bestEnvyCount = bestEnvyEntry.getValue().cardinality();
        if (bestEnvyCount < minEnvy) {
            return;
        }

        double bestPercent = ((double) bestEnvyCount) / ((double) (bestEnvyCount + thisClsAccessCount));

        if (bestPercent > envyPercent) {
            String bestEnvy = bestEnvyEntry.getKey();
            if (implementsCommonInterface(bestEnvy)) {
                return;
            }

            if (envies.length > 1) {
                int runnerUpEnvyCount = 0;
                for (int i = 1; i < envies.length; i++) {
                    runnerUpEnvyCount += envies[i].getValue().cardinality();
                }
                if ((2 * runnerUpEnvyCount) > bestEnvyCount) {
                    return;
                }
            }

            bugReporter.reportBug(new BugInstance(this, BugType.CE_CLASS_ENVY.name(), NORMAL_PRIORITY).addClass(this).addMethod(this)
                    .addSourceLineRange(this, 0, obj.getCode().length - 1).addString(bestEnvy));
        }
    }
135798
private boolean mockingObsoleteMethod(MethodTree enclosingMethod, VisitorState state, Type type) {
    // mutable boolean to return result from visitor
    boolean[] found = {false};
    enclosingMethod.accept(
        new TreeScanner<Void, Void>() {
          @Override
          public Void visitMethodInvocation(MethodInvocationTree node, Void unused) {
            if (found[0]) {
              return null;
            }
            if (MOCKITO_MATCHER.matches(node, state)) {
              Type stubber = ASTHelpers.getReturnType(node);
              if (!stubber.getTypeArguments().isEmpty()
                  && ASTHelpers.isSameType(
                      getOnlyElement(stubber.getTypeArguments()), type, state)) {
                found[0] = true;
              }
            }
            return super.visitMethodInvocation(node, null);
          }
        },
        null);
    return found[0];
  }
1300691
public BenchmarkResult run() {
		final BenchmarkResult res = new BenchmarkResult(conf.getListener());
		BenchmarkExecutor.initialize(conf, res);

		// instantiate methods
		final Map<Class<?>, Object> instantiatedObjs = instantiateObjects(res);

		// getting Benchmarkables
		try {
			final List<BenchmarkElement> elements = getBenchmarkElements(instantiatedObjs);

			// arranging them
			final AbstractMethodArrangement arrangement = AbstractMethodArrangement
					.getMethodArrangement(elements, conf.getArrangement());

			// getting the mapping and executing beforemethod
			final Map<Class<?>, Object> objectsToExecute = executeBeforeBenchClass(
					instantiatedObjs, res);

			// executing the bench for the arrangement
			for (final BenchmarkElement elem : arrangement) {
				// invoking gc if possible
				if (RAN.nextDouble() < conf.getGcProb()) {
					System.gc();
				}

				final BenchmarkExecutor exec = BenchmarkExecutor
						.getExecutor(elem);

				final Object obj = objectsToExecute.get(elem.getMeth()
						.getMethodToBench().getDeclaringClass());
				// check needed because of failed initialization of objects
				if (obj != null) {
					exec.executeBeforeMethods(obj);
					exec.executeBench(obj, elem.getParameter());
					exec.executeAfterMethods(obj);
				}
			}

			// cleaning up methods to benchmark
			tearDownObjectsToExecute(objectsToExecute, res);
		} catch (PerfidixMethodCheckException exc) {
			res.addException(exc);
		}
		return res;
	}
973432
@Override
    public void visitCode(Code obj) {
        try {
            Method m = getMethod();
            if ((!m.isPublic() && !m.isProtected()) || m.isAbstract() || m.isSynthetic()) {
                return;
            }

            CodeInfo superCode = superclassCode.remove(curMethodInfo);
            if (superCode != null) {
                if (sameAccess(getMethod().getAccessFlags(), superCode.getAccess()) && codeEquals(obj, superCode.getCode())) {
                    bugReporter.reportBug(new BugInstance(this, BugType.COM_COPIED_OVERRIDDEN_METHOD.name(), NORMAL_PRIORITY).addClass(this).addMethod(this)
                            .addSourceLine(classContext, this, getPC()));
                    return;
                }

                if ((getMethod().getAccessFlags() & Const.ACC_SYNCHRONIZED) != (superCode.getAccess() & Const.ACC_SYNCHRONIZED)) {
                    return;
                }

                parmTypes = getMethod().getArgumentTypes();
                nextParmIndex = 0;
                nextParmOffset = getMethod().isStatic() ? 0 : 1;
                sawAload0 = nextParmOffset == 0;
                sawParentCall = false;
                super.visitCode(obj);
            }
        } catch (StopOpcodeParsingException e) {
            // method is unique
        }

    }