java-allocation-instrumenter

A Java agent that rewrites bytecode to instrument allocation sites.

License

License

Categories

Categories

Java Languages
GroupId

GroupId

com.google.code.java-allocation-instrumenter
ArtifactId

ArtifactId

java-allocation-instrumenter
Last Version

Last Version

3.3.0
Release Date

Release Date

Type

Type

jar
Description

Description

java-allocation-instrumenter
A Java agent that rewrites bytecode to instrument allocation sites.
Project URL

Project URL

https://github.com/google/allocation-instrumenter/
Project Organization

Project Organization

Google, Inc.
Source Code Management

Source Code Management

https://github.com/google/allocation-instrumenter/

Download java-allocation-instrumenter

How to add to project

<!-- https://jarcasting.com/artifacts/com.google.code.java-allocation-instrumenter/java-allocation-instrumenter/ -->
<dependency>
    <groupId>com.google.code.java-allocation-instrumenter</groupId>
    <artifactId>java-allocation-instrumenter</artifactId>
    <version>3.3.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.google.code.java-allocation-instrumenter/java-allocation-instrumenter/
implementation 'com.google.code.java-allocation-instrumenter:java-allocation-instrumenter:3.3.0'
// https://jarcasting.com/artifacts/com.google.code.java-allocation-instrumenter/java-allocation-instrumenter/
implementation ("com.google.code.java-allocation-instrumenter:java-allocation-instrumenter:3.3.0")
'com.google.code.java-allocation-instrumenter:java-allocation-instrumenter:jar:3.3.0'
<dependency org="com.google.code.java-allocation-instrumenter" name="java-allocation-instrumenter" rev="3.3.0">
  <artifact name="java-allocation-instrumenter" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.google.code.java-allocation-instrumenter', module='java-allocation-instrumenter', version='3.3.0')
)
libraryDependencies += "com.google.code.java-allocation-instrumenter" % "java-allocation-instrumenter" % "3.3.0"
[com.google.code.java-allocation-instrumenter/java-allocation-instrumenter "3.3.0"]

Dependencies

compile (7)

Group / Artifact Type Version
org.ow2.asm : asm jar 7.2
org.ow2.asm : asm-analysis jar 7.2
org.ow2.asm : asm-commons jar 7.2
org.ow2.asm : asm-tree jar 7.2
org.ow2.asm : asm-util jar 7.2
com.google.guava : guava jar 28.1-android
javax.annotation : javax.annotation-api jar 1.3.2

test (3)

Group / Artifact Type Version
com.google.guava : guava-testlib jar 28.1-android
junit : junit jar 4.13
org.apache.bcel : bcel jar 6.0

Project Modules

There are no modules declared in this project.

The Allocation Instrumenter is a Java agent written using the java.lang.instrument API and ASM. Each allocation in your Java program is instrumented; a user-defined callback is invoked on each allocation.

How to get it

The latest release is available from Maven Central as:

<dependency>
  <groupId>com.google.code.java-allocation-instrumenter</groupId>
  <artifactId>java-allocation-instrumenter</artifactId>
  <version>3.3.0</version>
</dependency>

Basic usage

In order to write your own allocation tracking code, you have to implement the Sampler interface and pass an instance of that to AllocationRecorder.addSampler():

AllocationRecorder.addSampler(new Sampler() {
  public void sampleAllocation(int count, String desc, Object newObj, long size) {
    System.out.println("I just allocated the object " + newObj +
      " of type " + desc + " whose size is " + size);
    if (count != -1) { System.out.println("It's an array of size " + count); }
  }
});

You can also use the allocation instrumenter to instrument constructors of particular classes. You do this by instantiating a ConstructorCallback and passing it to ConstructorInstrumenter.instrumentClass():

try {
  ConstructorInstrumenter.instrumentClass(
      Thread.class, new ConstructorCallback<Thread>() {
        @Override public void sample(Thread t) {
          System.out.println("Instantiating a thread");
        }
      });
} catch (UnmodifiableClassException e) {
  System.out.println("Class cannot be modified");
}

For more information on how to get or use the allocation instrumenter, see Getting Started.

com.google.code.java-allocation-instrumenter

Google

Google ❤️ Open Source

Versions

Version
3.3.0
3.2.0
3.1.0
3.0.1
3.0
2.1
2.0