Java 类org.openjdk.jmh.annotations.State 实例源码

项目:criterion    文件:BitmapIndexingBenchmark.java   
State toState(long bitmap, int doubledMask) {
  final long pattern = ((bitmap >>> doubledMask) & 0b11);

  if (pattern == 0b00L) {
    return State.EMPTY;
  } else if (pattern == 0b01L) {
    return State.PAYLOAD;
  } else if (pattern == 0b10L) {
    return State.NODE;
  } else {
    return State.PAYLOAD_RARE;
  }

  // final int pattern = (int) ((bitmap >>> doubledMask) & 0b11);
  //
  // switch (pattern) {
  // case 0b01:
  // return State.PAYLOAD;
  // case 0b10:
  // return State.NODE;
  // case 0b11:
  // return State.PAYLOAD_RARE;
  // default:
  // return State.EMPTY;
  // }
}
项目:jmh    文件:StateObjectHandler.java   
/**
 * Recursively resolve if there are any other states referenced through helper methods.
 */
private void recursiveStateResolve(MethodInfo method, ClassInfo pci, StateObject pso, Set<StateObject> seen) {

    for (MethodInfo mi : BenchmarkGeneratorUtils.getMethods(pci)) {
        if (mi.getAnnotation(Setup.class) != null || mi.getAnnotation(TearDown.class) != null) {
            for (ParameterInfo pi : mi.getParameters()) {
                ClassInfo ci = pi.getType();

                StateObject so = new StateObject(identifiers, ci, getState(ci, pi).value());

                if (!seen.add(so)) {
                    throw new GenerationException("@" + State.class.getSimpleName() + " dependency cycle is detected.", pi);
                }

                if (!stateHelperArgs.get(mi.getQualifiedName()).contains(so)) {
                    stateObjects.add(so);
                    stateObjectDeps.put(pso, so);
                    stateHelperArgs.put(mi.getQualifiedName(), so);
                    bindState(method, so, ci);
                    recursiveStateResolve(method, ci, so, seen);
                }
            }
        }
    }
}
项目:jmh    文件:StateObjectHandler.java   
private void checkHelpers(MethodInfo mi, Class<? extends Annotation> annClass) {
    // OK to have these annotation for @State objects
    if (BenchmarkGeneratorUtils.getAnnSuper(mi.getDeclaringClass(), State.class) == null) {
        if (!mi.getDeclaringClass().isAbstract()) {
            throw new GenerationException(
                    "@" + TearDown.class.getSimpleName() + " annotation is placed within " +
                            "the class not having @" + State.class.getSimpleName() + " annotation. " +
                            "This has no behavioral effect, and prohibited.",
                    mi);
        }
    }

    if (!mi.isPublic()) {
        throw new GenerationException(
                "@" + annClass.getSimpleName() + " method should be public.",
                mi);
    }

    if (!mi.getReturnType().equalsIgnoreCase("void")) {
        throw new GenerationException(
                "@" + annClass.getSimpleName() + " method should not return anything.",
                mi);
    }
}
项目:jmh    文件:StateObjectHandler.java   
public State getState(ClassInfo ci, ParameterInfo pi) {
    State ann = BenchmarkGeneratorUtils.getAnnSuper(ci, State.class);
    if (ann == null) {
        throw new GenerationException("The method parameter is not a @" + State.class.getSimpleName() + ": ", pi);
    }
    return ann;
}
项目:jmh    文件:StateObjectHandler.java   
public void bindImplicit(ClassInfo ci, String label, Scope scope) {
    State ann = BenchmarkGeneratorUtils.getAnnSuper(ci, State.class);
    StateObject so = new StateObject(identifiers, ci, (ann != null) ? ann.value() : scope);
    stateObjects.add(so);
    implicits.put(label, so);
    bindState(null, so, ci);

    Set<StateObject> seen = new HashSet<StateObject>();
    recursiveStateResolve(null, ci, so, seen);
}
项目:graylog-plugin-pipeline-processor    文件:FilterchainVsPipeline.java   
public InterpreterState() {
    final RuleService ruleService = mock(MongoDbRuleService.class);
    when(ruleService.loadAll()).thenReturn(Collections.singleton(
            RuleDao.create("abc",
                           "title",
                           "description",
                           "rule \"add\"\n" +
                                   "when tostring($message.message) == \"original message\"\n" +
                                   "then\n" +
                                   "  set_field(\"field\", \"derived message\");\n" +
                                   "end",
                           Tools.nowUTC(),
                           null)
    ));

    final PipelineService pipelineService = mock(MongoDbPipelineService.class);
    when(pipelineService.loadAll()).thenReturn(Collections.singleton(
            PipelineDao.create("cde", "title", "description",
                               "pipeline \"pipeline\"\n" +
                                       "stage 0 match all\n" +
                                       "    rule \"add\";\n" +
                                       "end\n",
                               Tools.nowUTC(),
                               null)
    ));

    final PipelineStreamConnectionsService pipelineStreamConnectionsService = mock(MongoDbPipelineStreamConnectionsService.class);
    final PipelineConnections pipelineStreamConnection = PipelineConnections.create(null,
                                                                                              "default",
                                                                                              newHashSet("cde"));
    when(pipelineStreamConnectionsService.loadAll()).thenReturn(
            newHashSet(pipelineStreamConnection)
    );

    final Map<String, Function<?>> functions = Maps.newHashMap();
    functions.put(SetField.NAME, new SetField());
    functions.put(StringConversion.NAME, new StringConversion());

    final FunctionRegistry functionRegistry = new FunctionRegistry(functions);
    final PipelineRuleParser parser = new PipelineRuleParser(functionRegistry, new CodeGenerator(JavaCompiler::new));

    final MetricRegistry metricRegistry = new MetricRegistry();
    final ConfigurationStateUpdater stateUpdater = new ConfigurationStateUpdater(ruleService,
            pipelineService,
            pipelineStreamConnectionsService,
            parser,
            new MetricRegistry(),
            functionRegistry,
            Executors.newScheduledThreadPool(1),
            mock(EventBus.class),
            (currentPipelines, streamPipelineConnections, classLoader) -> new PipelineInterpreter.State(currentPipelines, streamPipelineConnections, null, metricRegistry, 1, true),
            false);
    interpreter = new PipelineInterpreter(
            mock(Journal.class),
            metricRegistry,
            mock(EventBus.class),
            stateUpdater
    );
}
项目:jmh    文件:StateObjectHandler.java   
private void checkParam(FieldInfo fi) {
    if (fi.isStatic()) {
        throw new GenerationException(
                "@" + Param.class.getSimpleName() + " annotation is not acceptable on static fields.",
                fi);
    }

    if (BenchmarkGeneratorUtils.getAnnSyntax(fi.getDeclaringClass(), State.class) == null) {
        throw new GenerationException(
                "@" + Param.class.getSimpleName() + " annotation should be placed in @" + State.class.getSimpleName() +
                        "-annotated class.", fi);
    }

    ClassInfo type = fi.getType();

    if (!isParamTypeAcceptable(type)) {
        throw new GenerationException(
                "@" + Param.class.getSimpleName() + " can only be placed over the annotation-compatible types:" +
                        " primitives, primitive wrappers, Strings, or enums.", fi);
    }

    String[] values = fi.getAnnotation(Param.class).value();

    if (values.length == 1 && values[0].equalsIgnoreCase(Param.BLANK_ARGS)) {
        if (!fi.getType().isEnum()) {
            throw new GenerationException(
                "@" + Param.class.getSimpleName() + " should provide the default parameters.", fi);
        } else {
            // if type is enum then don't need to check conformity
        }
    } else {
        for (String val : values) {
            if (!isParamValueConforming(fi, val, type)) {
                throw new GenerationException(
                        "Some @" + Param.class.getSimpleName() + " values can not be converted to target type: " +
                                "\"" + val + "\" can not be converted to " + type,
                        fi
                );
            }
        }
    }
}
项目:logging-log4j2    文件:AnnotationVsMarkerInterface.java   
@Benchmark
@BenchmarkMode({Mode.Throughput, Mode.AverageTime, Mode.SampleTime, Mode.SingleShotTime})
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public Object annotationPresent() {
    return this.getClass().isAnnotationPresent(State.class);
}