Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package datadog.communication.serialization;

import datadog.trace.api.function.BackgroundOnly;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.nio.charset.StandardCharsets;
import javax.annotation.concurrent.ThreadSafe;
Expand All @@ -15,6 +16,11 @@
* String#getBytes(java.nio.charset.Charset)}.
*
* <p>The cache is thread safe.
*
* <p>{@link BackgroundOnly}: the eden/tenured promotion and recalibration bookkeeping costs more
* than the {@code getBytes} call it replaces, so the saving only shows up as reduced allocation/GC
* pressure on the thread that pays it -- confine it to the background serializer thread, not an
* application thread.
*/
/*
* Cache works by using a 2-level promotion based scheme.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package datadog.communication.serialization;

import datadog.trace.api.function.BackgroundOnly;
import java.nio.charset.StandardCharsets;
import javax.annotation.concurrent.ThreadSafe;

Expand All @@ -13,6 +14,11 @@
* String#getBytes(java.nio.charset.Charset)}.
*
* <p>The cache is thread safe.
*
* <p>{@link BackgroundOnly}: the bookkeeping (hit counting, LFU eviction scan) costs more than the
* {@code getBytes} call it replaces, so the saving only shows up as reduced allocation/GC pressure
* on the thread that pays it -- confine it to the background serializer thread, not an application
* thread.
*/
/*
* Thread safety is achieved through using CacheEntry objects where the key data
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package datadog.trace.api.cache;

import datadog.trace.api.function.ForegroundSafe;
import java.util.function.BiConsumer;
import java.util.function.Function;

/**
* {@link ForegroundSafe}: every implementation looks up a key via a small, bounded number of probes
* (no growth, no eviction bookkeeping beyond overwriting a slot) -- cheap enough to call from an
* application thread.
*/
@ForegroundSafe
public interface DDCache<K, V> {
/**
* Look up or create and store a value in the cache.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package datadog.trace.api.function;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Marks code that must be confined to a background thread the tracer owns and paces itself -- e.g.
* serialization, stats aggregation, or eviction -- and must never be reached from an application
* thread (the foreground; see {@link ForegroundSafe}), where its cost would become customer-visible
* latency instead.
*
* <p>This is a documentation-and-tooling marker; it changes no behavior. It exists to telegraph the
* constraint to readers and to give a future checker (see {@code APMLP-1645}) something to verify
* -- that no {@code @BackgroundOnly} code is reachable from a foreground call site. The discipline
* it names is <b>not yet enforced</b>; hold to it by hand until the checker lands.
*
* <p>The two markers are <b>not symmetric</b> -- see {@link ForegroundSafe} for why it, not this
* one, is the strictly stronger guarantee.
*
* <p><b>On a type</b> ({@link ElementType#TYPE}): every method of this type is background-only
* unless a method-level {@link ForegroundSafe} widens it.
*
* <p><b>On a method</b> ({@link ElementType#METHOD}): this method specifically is background-only,
* regardless of what the enclosing type declares -- a method-level marker always wins over the
* type-level one.
*/
@Documented
@Retention(RetentionPolicy.SOURCE)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface BackgroundOnly {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package datadog.trace.api.function;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Marks code cheap enough to call from an application thread (the foreground) -- the request or
* transaction thread the instrumented application itself is running, where any added cost is
* customer-visible latency, as opposed to a background thread the tracer owns and paces itself (see
* {@link BackgroundOnly}).
*
* <p>This is a documentation-and-tooling marker; it changes no behavior. It exists to telegraph the
* guarantee to readers and to give a future checker (see {@code APMLP-1645}) something to verify --
* that no {@link BackgroundOnly} code is reachable from a foreground call site. The discipline it
* names is <b>not yet enforced</b>; hold to it by hand until the checker lands.
*
* <p>The two markers are <b>not symmetric</b>. {@code @ForegroundSafe} is the strictly stronger
* guarantee: code cheap enough for the foreground is automatically fine to call from a background
* thread too, so a {@code @ForegroundSafe} type or method may be called from either. {@link
* BackgroundOnly} code carries no such guarantee and must never be reached from a foreground call
* site.
*
* <p><b>On a type</b> ({@link ElementType#TYPE}): every method of this type is foreground-safe
* unless a method-level {@link BackgroundOnly} narrows it.
*
* <p><b>On a method</b> ({@link ElementType#METHOD}): this method specifically is foreground-safe,
* regardless of what the enclosing type declares -- a method-level marker always wins over the
* type-level one.
*/
@Documented
@Retention(RetentionPolicy.SOURCE)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface ForegroundSafe {}
Loading