org.checkerframework.checker.nullness.qual.RequiresNonNull Java Examples

The following examples show how to use org.checkerframework.checker.nullness.qual.RequiresNonNull. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ThreadContextImpl.java    From glowroot with Apache License 2.0 6 votes vote down vote up
@RequiresNonNull("asyncTimer")
private void extendAsync() {
    ThreadContextThreadLocal.Holder holder =
            BytecodeServiceHolder.get().getCurrentThreadContextHolder();
    ThreadContextPlus currThreadContext = holder.get();
    long currTick = ticker.read();
    if (currThreadContext == ThreadContextImpl.this) {
        // this thread context was found in ThreadContextThreadLocal.Holder, so it is still
        // active, and so current timer must be non-null
        extendSync(currTick, checkNotNull(getCurrentTimer()));
    } else {
        // set to null since its value is checked in stopAsync()
        extendedTimer = null;
        extendQueryData(currTick);
    }
    asyncTimer.extend(currTick);
}
 
Example #2
Source File: WeavingClassVisitor.java    From glowroot with Apache License 2.0 6 votes vote down vote up
@RequiresNonNull("type")
private void addMixin(ClassNode mixinClassNode) {
    List<FieldNode> fieldNodes = mixinClassNode.fields;
    for (FieldNode fieldNode : fieldNodes) {
        if (!Modifier.isTransient(fieldNode.access)) {
            // this is needed to avoid serialization issues (even if the new field is
            // serializable, this can still cause issues in a cluster if glowroot is not
            // deployed on all nodes)
            throw new IllegalStateException(
                    "@Mixin fields must be marked transient: " + mixinClassNode.name);
        }
        fieldNode.accept(this);
    }
    List<MethodNode> methodNodes = mixinClassNode.methods;
    for (MethodNode mn : methodNodes) {
        if (mn.name.equals("<init>")) {
            continue;
        }
        String[] exceptions = Iterables.toArray(mn.exceptions, String.class);
        MethodVisitor mv =
                cw.visitMethod(mn.access, mn.name, mn.desc, mn.signature, exceptions);
        mn.accept(new MethodRemapper(mv,
                new SimpleRemapper(mixinClassNode.name, type.getInternalName())));
    }
}
 
Example #3
Source File: WeavingClassVisitor.java    From glowroot with Apache License 2.0 6 votes vote down vote up
@RequiresNonNull("type")
private void addShim(ShimType shimType) {
    for (java.lang.reflect.Method reflectMethod : shimType.shimMethods()) {
        Method method = Method.getMethod(reflectMethod);
        Shim shim = reflectMethod.getAnnotation(Shim.class);
        checkNotNull(shim);
        if (shim.value().length != 1) {
            throw new IllegalStateException(
                    "@Shim annotation must have exactly one value when used on methods");
        }
        Method targetMethod = Method.getMethod(shim.value()[0]);
        MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, method.getName(), method.getDescriptor(),
                null, null);
        mv.visitCode();
        int i = 0;
        mv.visitVarInsn(ALOAD, i++);
        for (Type argumentType : method.getArgumentTypes()) {
            mv.visitVarInsn(argumentType.getOpcode(ILOAD), i++);
        }
        mv.visitMethodInsn(INVOKEVIRTUAL, type.getInternalName(), targetMethod.getName(),
                targetMethod.getDescriptor(), false);
        mv.visitInsn(method.getReturnType().getOpcode(IRETURN));
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
}
 
Example #4
Source File: CollectorServiceImpl.java    From glowroot with Apache License 2.0 6 votes vote down vote up
@RequiresNonNull({"streamHeader", "streamCounts"})
private boolean isEverythingReceived() {
    // validate that all data was received, may not receive everything due to gRPC
    // maxMessageSize limit exceeded: "Compressed frame exceeds maximum frame size"
    if (header == null) {
        logger.error("{} - did not receive header, likely due to gRPC maxMessageSize limit"
                + " exceeded", getAgentIdForLogging());
        return false;
    }
    if (sharedQueryTexts.size() < streamCounts.getSharedQueryTextCount()) {
        logger.error("{} - expected {} shared query texts, but only received {}, likely due"
                + " to gRPC maxMessageSize limit exceeded for some of them",
                getAgentIdForLogging(), streamCounts.getSharedQueryTextCount(),
                sharedQueryTexts.size());
        return false;
    }
    if (entries.size() < streamCounts.getEntryCount()) {
        logger.error("{} - expected {} entries, but only received {}, likely due to gRPC"
                + " maxMessageSize limit exceeded for some of them", getAgentIdForLogging(),
                streamCounts.getEntryCount(), entries.size());
        return false;
    }
    checkState(sharedQueryTexts.size() == streamCounts.getSharedQueryTextCount());
    checkState(entries.size() == streamCounts.getEntryCount());
    return true;
}
 
Example #5
Source File: WeavingClassVisitor.java    From glowroot with Apache License 2.0 6 votes vote down vote up
@RequiresNonNull({"type", "metaHolderInternalName"})
private void initializeBoostrapMetaHolders() {
    for (Type classMetaType : classMetaTypes) {
        String classMetaInternalName = classMetaType.getInternalName();
        String classMetaFieldName =
                "glowroot$class$meta$" + classMetaInternalName.replace('/', '$');
        BootstrapMetaHolders.createClassMetaHolder(metaHolderInternalName, classMetaFieldName,
                classMetaType, type);
    }
    for (MethodMetaGroup methodMetaGroup : methodMetaGroups) {
        for (Type methodMetaType : methodMetaGroup.methodMetaTypes()) {
            String methodMetaInternalName = methodMetaType.getInternalName();
            String methodMetaFieldName = "glowroot$method$meta$" + methodMetaGroup.uniqueNum()
                    + '$' + methodMetaInternalName.replace('/', '$');
            BootstrapMetaHolders.createMethodMetaHolder(metaHolderInternalName,
                    methodMetaFieldName, methodMetaType, type, methodMetaGroup.methodName(),
                    methodMetaGroup.methodReturnType(), methodMetaGroup.methodParameterTypes());
        }
    }
}
 
Example #6
Source File: HlsSampleStreamWrapper.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@RequiresNonNull("trackGroups")
@EnsuresNonNull("trackGroupToSampleQueueIndex")
private void mapSampleQueuesToMatchTrackGroups() {
  int trackGroupCount = trackGroups.length;
  trackGroupToSampleQueueIndex = new int[trackGroupCount];
  Arrays.fill(trackGroupToSampleQueueIndex, C.INDEX_UNSET);
  for (int i = 0; i < trackGroupCount; i++) {
    for (int queueIndex = 0; queueIndex < sampleQueues.length; queueIndex++) {
      SampleQueue sampleQueue = sampleQueues[queueIndex];
      if (formatsMatch(sampleQueue.getUpstreamFormat(), trackGroups.get(i).getFormat(0))) {
        trackGroupToSampleQueueIndex[i] = queueIndex;
        break;
      }
    }
  }
  for (HlsSampleStream sampleStream : hlsSampleStreams) {
    sampleStream.bindSampleQueue();
  }
}
 
Example #7
Source File: Transaction.java    From glowroot with Apache License 2.0 6 votes vote down vote up
@GuardedBy("mainThreadContext")
@RequiresNonNull("auxThreadContexts")
private Iterable<ThreadContextImpl> getUnmergedAuxThreadContext() {
    if (unmergeableAuxThreadContexts == null) {
        if (unmergedLimitExceededAuxThreadContexts == null) {
            return auxThreadContexts;
        } else {
            return Iterables.concat(auxThreadContexts, unmergedLimitExceededAuxThreadContexts);
        }
    } else if (unmergedLimitExceededAuxThreadContexts == null) {
        return Iterables.concat(unmergeableAuxThreadContexts, auxThreadContexts);
    } else {
        return Iterables.concat(unmergeableAuxThreadContexts, auxThreadContexts,
                unmergedLimitExceededAuxThreadContexts);
    }
}
 
Example #8
Source File: TraceEntryImpl.java    From glowroot with Apache License 2.0 6 votes vote down vote up
@RequiresNonNull("asyncTimer")
private void extendAsync() {
    ThreadContextThreadLocal.Holder holder =
            BytecodeServiceHolder.get().getCurrentThreadContextHolder();
    ThreadContextPlus currThreadContext = holder.get();
    long currTick = ticker.read();
    if (currThreadContext == threadContext) {
        // thread context was found in ThreadContextThreadLocal.Holder, so it is still
        // active, and so current timer must be non-null
        extendSync(currTick, checkNotNull(threadContext.getCurrentTimer()));
    } else {
        // set to null since its value is checked in stopAsync()
        extendedTimer = null;
        extendQueryData(currTick);
    }
    asyncTimer.extend(currTick);
}
 
Example #9
Source File: WeavingMethodVisitor.java    From glowroot with Apache License 2.0 6 votes vote down vote up
@RequiresNonNull({"threadContextHolderLocal", "threadContextLocal"})
private void loadMaybeNullThreadContext(Object... stack) {
    loadLocal(threadContextHolderLocal);
    Label label = new Label();
    visitJumpInsn(IFNONNULL, label);
    visitMethodInsn(INVOKESTATIC, bytecodeType.getInternalName(),
            "getCurrentThreadContextHolder",
            "()" + fastThreadContextThreadLocalHolderType.getDescriptor(), false);
    storeLocal(threadContextHolderLocal);
    visitLabel(label);
    visitImplicitFrame(stack);
    loadLocal(threadContextHolderLocal);
    visitMethodInsn(INVOKEVIRTUAL, fastThreadContextThreadLocalHolderType.getInternalName(),
            "get", "()" + threadContextPlusType.getDescriptor(), false);
    dup();
    storeLocal(threadContextLocal);
}
 
Example #10
Source File: WeavingMethodVisitor.java    From glowroot with Apache License 2.0 6 votes vote down vote up
@RequiresNonNull({"threadContextHolderLocal", "threadContextLocal"})
private void loadOptionalThreadContext(String nestingGroup, String suppressionKey,
        Object... stack) {
    loadMaybeNullThreadContext(stack);
    Label label = new Label();
    visitJumpInsn(IFNONNULL, label);
    loadLocal(threadContextHolderLocal);
    if (nestingGroup.isEmpty()) {
        mv.visitLdcInsn(0);
    } else {
        mv.visitLdcInsn(getNestingGroupId(nestingGroup));
    }
    if (suppressionKey.isEmpty()) {
        mv.visitLdcInsn(0);
    } else {
        mv.visitLdcInsn(getSuppressionKeyId(suppressionKey));
    }
    visitMethodInsn(INVOKESTATIC, bytecodeType.getInternalName(), "createOptionalThreadContext",
            "(" + fastThreadContextThreadLocalHolderType.getDescriptor() + "II)"
                    + threadContextPlusType.getDescriptor(),
            false);
    storeLocal(threadContextLocal);
    visitLabel(label);
    visitImplicitFrame(stack);
    loadLocal(threadContextLocal);
}
 
Example #11
Source File: WeavingMethodVisitor.java    From glowroot with Apache License 2.0 6 votes vote down vote up
@RequiresNonNull("threadContextLocal")
private void checkAndUpdateNestingGroupId(int prevNestingGroupIdLocal, String nestingGroup,
        Label otherEnabledFactorsDisabledEnd) {
    loadLocal(threadContextLocal);
    visitMethodInsn(INVOKEINTERFACE, threadContextPlusType.getInternalName(),
            "getCurrentNestingGroupId", "()I", true);
    dup();
    storeLocal(prevNestingGroupIdLocal);
    int nestingGroupId = getNestingGroupId(nestingGroup);
    mv.visitLdcInsn(nestingGroupId);
    visitJumpInsn(IF_ICMPEQ, otherEnabledFactorsDisabledEnd);
    loadLocal(threadContextLocal);
    mv.visitLdcInsn(nestingGroupId);
    visitMethodInsn(INVOKEINTERFACE, threadContextPlusType.getInternalName(),
            "setCurrentNestingGroupId", "(I)V", true);
}
 
Example #12
Source File: WeavingMethodVisitor.java    From glowroot with Apache License 2.0 6 votes vote down vote up
@RequiresNonNull({"metaHolderInternalName", "methodMetaGroupUniqueNum"})
private void loadMethodMeta(AdviceParameter parameter) {
    Type methodMetaFieldType = parameter.type();
    String methodMetaFieldName = "glowroot$method$meta$" + methodMetaGroupUniqueNum + '$'
            + methodMetaFieldType.getInternalName().replace('/', '$');
    if (bootstrapClassLoader) {
        int index = BootstrapMetaHolders.reserveMethodMetaHolderIndex(metaHolderInternalName,
                methodMetaFieldName);
        push(index);
        visitMethodInsn(INVOKESTATIC, bytecodeType.getInternalName(), "getMethodMeta",
                "(I)Ljava/lang/Object;", false);
        mv.visitTypeInsn(CHECKCAST, methodMetaFieldType.getInternalName());
    } else {
        visitFieldInsn(GETSTATIC, metaHolderInternalName, methodMetaFieldName,
                methodMetaFieldType.getDescriptor());
    }
}
 
Example #13
Source File: WeavingMethodVisitor.java    From glowroot with Apache License 2.0 6 votes vote down vote up
@RequiresNonNull("metaHolderInternalName")
private void loadClassMeta(AdviceParameter parameter) {
    Type classMetaFieldType = parameter.type();
    String classMetaFieldName =
            "glowroot$class$meta$" + classMetaFieldType.getInternalName().replace('/', '$');
    if (bootstrapClassLoader) {
        int index = BootstrapMetaHolders.reserveClassMetaHolderIndex(metaHolderInternalName,
                classMetaFieldName);
        push(index);
        visitMethodInsn(INVOKESTATIC, bytecodeType.getInternalName(), "getClassMeta",
                "(I)Ljava/lang/Object;", false);
        mv.visitTypeInsn(CHECKCAST, classMetaFieldType.getInternalName());
    } else {
        visitFieldInsn(GETSTATIC, metaHolderInternalName, classMetaFieldName,
                classMetaFieldType.getDescriptor());
    }
}
 
Example #14
Source File: InstrumentationSeekerClassVisitor.java    From glowroot with Apache License 2.0 5 votes vote down vote up
@RequiresNonNull("owner")
private ImmutableInstrumentationConfig.Builder startBuilder() {
    Type type = Type.getObjectType(owner);
    Type[] argumentTypes = Type.getArgumentTypes(descriptor);
    ImmutableInstrumentationConfig.Builder builder =
            ImmutableInstrumentationConfig.builder()
                    .className(type.getClassName())
                    .methodName(methodName);
    for (Type argumentType : argumentTypes) {
        builder.addMethodParameterTypes(argumentType.getClassName());
    }
    return builder;
}
 
Example #15
Source File: AnalyticsCollector.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/** Returns a new {@link EventTime} for the specified timeline, window and media period id. */
@RequiresNonNull("player")
protected EventTime generateEventTime(
    Timeline timeline, int windowIndex, @Nullable MediaPeriodId mediaPeriodId) {
  if (timeline.isEmpty()) {
    // Ensure media period id is only reported together with a valid timeline.
    mediaPeriodId = null;
  }
  long realtimeMs = clock.elapsedRealtime();
  long eventPositionMs;
  boolean isInCurrentWindow =
      timeline == player.getCurrentTimeline() && windowIndex == player.getCurrentWindowIndex();
  if (mediaPeriodId != null && mediaPeriodId.isAd()) {
    boolean isCurrentAd =
        isInCurrentWindow
            && player.getCurrentAdGroupIndex() == mediaPeriodId.adGroupIndex
            && player.getCurrentAdIndexInAdGroup() == mediaPeriodId.adIndexInAdGroup;
    // Assume start position of 0 for future ads.
    eventPositionMs = isCurrentAd ? player.getCurrentPosition() : 0;
  } else if (isInCurrentWindow) {
    eventPositionMs = player.getContentPosition();
  } else {
    // Assume default start position for future content windows. If timeline is not available yet,
    // assume start position of 0.
    eventPositionMs =
        timeline.isEmpty() ? 0 : timeline.getWindow(windowIndex, window).getDefaultPositionMs();
  }
  return new EventTime(
      realtimeMs,
      timeline,
      windowIndex,
      mediaPeriodId,
      eventPositionMs,
      player.getCurrentPosition(),
      player.getTotalBufferedDuration());
}
 
Example #16
Source File: DefaultDrmSession.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@RequiresNonNull({"sessionId", "offlineLicenseKeySetId"})
private boolean restoreKeys() {
  try {
    mediaDrm.restoreKeys(sessionId, offlineLicenseKeySetId);
    return true;
  } catch (Exception e) {
    Log.e(TAG, "Error trying to restore Widevine keys.", e);
    onError(e);
  }
  return false;
}
 
Example #17
Source File: FlacExtractor.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@RequiresNonNull("binarySearchSeeker")
private int handlePendingSeek(
    ExtractorInput input,
    PositionHolder seekPosition,
    ParsableByteArray outputBuffer,
    OutputFrameHolder outputFrameHolder,
    TrackOutput trackOutput)
    throws InterruptedException, IOException {
  int seekResult = binarySearchSeeker.handlePendingSeek(input, seekPosition, outputFrameHolder);
  ByteBuffer outputByteBuffer = outputFrameHolder.byteBuffer;
  if (seekResult == RESULT_CONTINUE && outputByteBuffer.limit() > 0) {
    outputSample(outputBuffer, outputByteBuffer.limit(), outputFrameHolder.timeUs, trackOutput);
  }
  return seekResult;
}
 
Example #18
Source File: FlacExtractor.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@RequiresNonNull({"decoderJni", "extractorOutput", "trackOutput"}) // Requires initialized.
@EnsuresNonNull({"streamMetadata", "outputFrameHolder"}) // Ensures stream metadata decoded.
@SuppressWarnings({"contracts.postcondition.not.satisfied"})
private void decodeStreamMetadata(ExtractorInput input) throws InterruptedException, IOException {
  if (streamMetadataDecoded) {
    return;
  }

  FlacStreamMetadata streamMetadata;
  try {
    streamMetadata = decoderJni.decodeStreamMetadata();
  } catch (IOException e) {
    decoderJni.reset(/* newPosition= */ 0);
    input.setRetryPosition(/* position= */ 0, e);
    throw e;
  }

  streamMetadataDecoded = true;
  if (this.streamMetadata == null) {
    this.streamMetadata = streamMetadata;
    binarySearchSeeker =
        outputSeekMap(decoderJni, streamMetadata, input.getLength(), extractorOutput);
    Metadata metadata = id3MetadataDisabled ? null : id3Metadata;
    if (streamMetadata.metadata != null) {
      metadata = streamMetadata.metadata.copyWithAppendedEntriesFrom(metadata);
    }
    outputFormat(streamMetadata, metadata, trackOutput);
    outputBuffer.reset(streamMetadata.maxDecodedFrameSize());
    outputFrameHolder = new OutputFrameHolder(ByteBuffer.wrap(outputBuffer.data));
  }
}
 
Example #19
Source File: ClassAnalyzer.java    From glowroot with Apache License 2.0 5 votes vote down vote up
@RequiresNonNull("bridgeTargetAdvisors")
private List<Advice> getMatchingAdvisors(ThinMethod thinMethod, List<String> methodAnnotations,
        List<Type> parameterTypes, Type returnType) {
    Set<Advice> matchingAdvisors = Sets.newHashSet();
    for (AdviceMatcher adviceMatcher : adviceMatchers) {
        if (adviceMatcher.isMethodLevelMatch(thinMethod.name(), methodAnnotations,
                parameterTypes, returnType, thinMethod.access())) {
            matchingAdvisors.add(adviceMatcher.advice());
        }
    }
    if (!thinMethod.name().equals("<init>")) {
        // look at super types
        for (AnalyzedClass superAnalyzedClass : superAnalyzedClasses) {
            for (AnalyzedMethod analyzedMethod : superAnalyzedClass.analyzedMethods()) {
                if (analyzedMethod.isOverriddenBy(thinMethod.name(), parameterTypes)) {
                    matchingAdvisors.addAll(analyzedMethod.advisors());
                    for (Advice subTypeRestrictedAdvice : analyzedMethod
                            .subTypeRestrictedAdvisors()) {
                        if (isSubTypeRestrictionMatch(subTypeRestrictedAdvice,
                                superClassNames)) {
                            matchingAdvisors.add(subTypeRestrictedAdvice);
                        }
                    }
                }
            }
        }
    }
    List<Advice> extraAdvisors = bridgeTargetAdvisors.get(thinMethod);
    if (extraAdvisors != null) {
        matchingAdvisors.addAll(extraAdvisors);
    }
    // sort since the order affects advice nesting
    return sortAdvisors(matchingAdvisors);
}
 
Example #20
Source File: AdminJsonService.java    From glowroot with Apache License 2.0 5 votes vote down vote up
@RequiresNonNull("httpServer")
private CommonResponse onSuccessfulEmbeddedWebUpdate(EmbeddedWebConfig config)
        throws Exception {
    boolean closeCurrentChannelAfterPortChange = false;
    boolean portChangeFailed = false;
    if (config.port() != checkNotNull(httpServer.getPort())) {
        try {
            httpServer.changePort(config.port());
            closeCurrentChannelAfterPortChange = true;
        } catch (PortChangeFailedException e) {
            logger.error(e.getMessage(), e);
            portChangeFailed = true;
        }
    }
    if (config.https() != httpServer.getHttps() && !portChangeFailed) {
        // only change protocol if port change did not fail, otherwise confusing to display
        // message that port change failed while at the same time redirecting user to HTTP/S
        httpServer.changeProtocol(config.https());
        closeCurrentChannelAfterPortChange = true;
    }
    String responseText = getEmbeddedWebConfig(portChangeFailed);
    CommonResponse response = new CommonResponse(OK, MediaType.JSON_UTF_8, responseText);
    if (closeCurrentChannelAfterPortChange) {
        response.setCloseConnectionAfterPortChange();
    }
    return response;
}
 
Example #21
Source File: HttpServer.java    From glowroot with Apache License 2.0 5 votes vote down vote up
@RequiresNonNull("serverChannel")
private void onBindSuccess() {
    port = ((InetSocketAddress) serverChannel.localAddress()).getPort();
    String listener = offlineViewer ? "Offline viewer" : "UI";
    String optionalHttps = sslContext == null ? "" : " (HTTPS)";
    if (bindAddress.equals("127.0.0.1")) {
        startupLogger.info("{} listening on {}:{}{} (to access the UI from remote machines,"
                + " change the bind address to 0.0.0.0, either in the Glowroot UI under"
                + " Configuration > Web or directly in the admin.json file, and then restart"
                + " JVM to take effect)", listener, bindAddress, port, optionalHttps);
    } else {
        startupLogger.info("{} listening on {}:{}{}", listener, bindAddress, port,
                optionalHttps);
    }
}
 
Example #22
Source File: WeavingClassVisitor.java    From glowroot with Apache License 2.0 5 votes vote down vote up
@RequiresNonNull("type")
private void overrideAndWeaveInheritedMethod(AnalyzedMethod inheritedMethod) {
    String superName = analyzedClass.superName();
    // superName is null only for java.lang.Object which doesn't inherit anything
    // so safe to assume superName not null here
    checkNotNull(superName);
    String[] exceptions = new String[inheritedMethod.exceptions().size()];
    for (int i = 0; i < inheritedMethod.exceptions().size(); i++) {
        exceptions[i] = ClassNames.toInternalName(inheritedMethod.exceptions().get(i));
    }
    List<Advice> advisors = removeSuperseded(inheritedMethod.advisors());
    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, inheritedMethod.name(),
            inheritedMethod.getDesc(), inheritedMethod.signature(), exceptions);
    mv = visitMethodWithAdvice(mv, ACC_PUBLIC, inheritedMethod.name(),
            inheritedMethod.getDesc(), advisors);
    checkNotNull(mv);
    GeneratorAdapter mg = new GeneratorAdapter(mv, ACC_PUBLIC, inheritedMethod.name(),
            inheritedMethod.getDesc());
    mg.visitCode();
    mg.loadThis();
    mg.loadArgs();
    Type superType = Type.getObjectType(ClassNames.toInternalName(superName));
    // method is called invokeConstructor, but should really be called invokeSpecial
    Method method = new Method(inheritedMethod.name(), inheritedMethod.getDesc());
    mg.invokeConstructor(superType, method);
    mg.returnValue();
    mg.endMethod();
}
 
Example #23
Source File: DownloadHelper.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@RequiresNonNull({
  "trackGroupArrays",
  "mappedTrackInfos",
  "trackSelectionsByPeriodAndRenderer",
  "immutableTrackSelectionsByPeriodAndRenderer",
  "mediaPreparer",
  "mediaPreparer.timeline",
  "mediaPreparer.mediaPeriods"
})
private void setPreparedWithMedia() {
  isPreparedWithMedia = true;
}
 
Example #24
Source File: FlacExtractor.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@RequiresNonNull({"decoderJni", "extractorOutput", "trackOutput"}) // Requires initialized.
@EnsuresNonNull({"streamMetadata", "outputFrameHolder"}) // Ensures stream metadata decoded.
@SuppressWarnings({"contracts.postcondition.not.satisfied"})
private void decodeStreamMetadata(ExtractorInput input) throws InterruptedException, IOException {
  if (streamMetadataDecoded) {
    return;
  }

  FlacStreamMetadata streamMetadata;
  try {
    streamMetadata = decoderJni.decodeStreamMetadata();
  } catch (IOException e) {
    decoderJni.reset(/* newPosition= */ 0);
    input.setRetryPosition(/* position= */ 0, e);
    throw e;
  }

  streamMetadataDecoded = true;
  if (this.streamMetadata == null) {
    this.streamMetadata = streamMetadata;
    binarySearchSeeker =
        outputSeekMap(decoderJni, streamMetadata, input.getLength(), extractorOutput);
    Metadata metadata = id3MetadataDisabled ? null : id3Metadata;
    if (streamMetadata.metadata != null) {
      metadata = streamMetadata.metadata.copyWithAppendedEntriesFrom(metadata);
    }
    outputFormat(streamMetadata, metadata, trackOutput);
    outputBuffer.reset(streamMetadata.maxDecodedFrameSize());
    outputFrameHolder = new OutputFrameHolder(ByteBuffer.wrap(outputBuffer.data));
  }
}
 
Example #25
Source File: DownloadHelper.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@RequiresNonNull({
  "trackGroupArrays",
  "mappedTrackInfos",
  "trackSelectionsByPeriodAndRenderer",
  "immutableTrackSelectionsByPeriodAndRenderer",
  "mediaPreparer",
  "mediaPreparer.timeline",
  "mediaPreparer.mediaPeriods"
})
private void setPreparedWithMedia() {
  isPreparedWithMedia = true;
}
 
Example #26
Source File: WeavingClassVisitor.java    From glowroot with Apache License 2.0 5 votes vote down vote up
@RequiresNonNull("type")
private WeavingMethodVisitor newWeavingMethodVisitor(int access, String name, String descriptor,
        List<Advice> matchingAdvisors, MethodVisitor mv) {
    Integer methodMetaUniqueNum = collectMetasAtMethod(matchingAdvisors, name, descriptor);
    usedAdvisors.addAll(matchingAdvisors);
    return new WeavingMethodVisitor(mv, frames, access, name, descriptor, type,
            matchingAdvisors, metaHolderInternalName, methodMetaUniqueNum, loader == null);
}
 
Example #27
Source File: WeavingClassVisitor.java    From glowroot with Apache License 2.0 5 votes vote down vote up
@RequiresNonNull("type")
private MethodVisitor visitInitWithMixins(int access, String name, String descriptor,
        @Nullable String signature, String /*@Nullable*/ [] exceptions,
        List<Advice> matchingAdvisors) {
    MethodVisitor mv = cw.visitMethod(access, name, descriptor, signature, exceptions);
    mv = new InitMixins(mv, access, name, descriptor, mixinTypes, type);
    for (Advice advice : matchingAdvisors) {
        if (!advice.pointcut().timerName().isEmpty()) {
            logger.warn("cannot add timer to <clinit> or <init> methods at this time");
            break;
        }
    }
    return newWeavingMethodVisitor(access, name, descriptor, matchingAdvisors, mv);
}
 
Example #28
Source File: WeavingClassVisitor.java    From glowroot with Apache License 2.0 5 votes vote down vote up
@RequiresNonNull({"type", "metaHolderInternalName"})
private void handleMetaHolders() {
    if (loader == null) {
        initializeBoostrapMetaHolders();
    } else {
        try {
            generateMetaHolder();
        } catch (Exception e) {
            // this will terminate weaving and get logged by WeavingClassFileTransformer
            throw new RuntimeException(e);
        }
    }
}
 
Example #29
Source File: AdviceGenerator.java    From glowroot with Apache License 2.0 5 votes vote down vote up
@RequiresNonNull("methodMetaInternalName")
private void generateMethodMetaGetter(ClassWriter cw, String fieldName, String methodName) {
    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, methodName,
            "()Lorg/glowroot/agent/bytecode/api/MessageTemplate;", null, null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, methodMetaInternalName, fieldName,
            "Lorg/glowroot/agent/bytecode/api/MessageTemplate;");
    mv.visitInsn(ARETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}
 
Example #30
Source File: AdviceGenerator.java    From glowroot with Apache License 2.0 5 votes vote down vote up
@RequiresNonNull("methodMetaInternalName")
private LazyDefinedClass generateMethodMetaClass(InstrumentationConfig config) {
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
    cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, methodMetaInternalName, null, "java/lang/Object",
            null);
    cw.visitField(ACC_PRIVATE + ACC_FINAL, "messageTemplate",
            "Lorg/glowroot/agent/bytecode/api/MessageTemplate;", null, null).visitEnd();
    if (!config.transactionNameTemplate().isEmpty()) {
        cw.visitField(ACC_PRIVATE + ACC_FINAL, "transactionNameTemplate",
                "Lorg/glowroot/agent/bytecode/api/MessageTemplate;", null, null).visitEnd();
    }
    if (!config.transactionUserTemplate().isEmpty()) {
        cw.visitField(ACC_PRIVATE + ACC_FINAL, "transactionUserTemplate",
                "Lorg/glowroot/agent/bytecode/api/MessageTemplate;", null, null).visitEnd();
    }
    for (int i = 0; i < config.transactionAttributeTemplates().size(); i++) {
        cw.visitField(ACC_PRIVATE + ACC_FINAL, "transactionAttributeTemplate" + i,
                "Lorg/glowroot/agent/bytecode/api/MessageTemplate;", null, null).visitEnd();
    }
    generateMethodMetaConstructor(cw);
    generateMethodMetaGetter(cw, "messageTemplate", "getMessageTemplate");
    if (!config.transactionNameTemplate().isEmpty()) {
        generateMethodMetaGetter(cw, "transactionNameTemplate", "getTransactionNameTemplate");
    }
    if (!config.transactionUserTemplate().isEmpty()) {
        generateMethodMetaGetter(cw, "transactionUserTemplate", "getTransactionUserTemplate");
    }
    for (int i = 0; i < config.transactionAttributeTemplates().size(); i++) {
        generateMethodMetaGetter(cw, "transactionAttributeTemplate" + i,
                "getTransactionAttributeTemplate" + i);
    }
    cw.visitEnd();
    return ImmutableLazyDefinedClass.builder()
            .type(Type.getObjectType(methodMetaInternalName))
            .bytes(cw.toByteArray())
            .build();
}