public static void addSampler(Sampler sampler) {
    synchronized (samplerLock) {
      Sampler[] samplers = additionalSamplers;
      /* create a new list of samplers from the old, adding this sampler */
      if (samplers != null) {
        Sampler[] newSamplers = new Sampler[samplers.length + 1];
        System.arraycopy(samplers, 0, newSamplers, 0, samplers.length);
        newSamplers[samplers.length] = sampler;
        additionalSamplers = newSamplers;
      } else {
        Sampler[] newSamplers = new Sampler[1];
        newSamplers[0] = sampler;
        additionalSamplers = newSamplers;
      }
    }
  }
Adds a {@link Sampler} that will get run <b>every time an allocation is performed from Java
code</b>. Use this with <b>extreme</b> judiciousness!

@param sampler The sampler to add.
src/main/java/com/google/monitoring/runtime/instrumentation/AllocationRecorder.java