-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
238 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule integrations-core
updated
3622 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
dd-java-agent/agent-profiling/profiling-controller-jfr/implementation/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Set properties before any plugins get loaded | ||
ext { | ||
// the tests need Java 11 because the JFR writer got compiled with a version | ||
// of ByteBuffer.position(int) which is binary incompatible with Java 8 ¯\_(ツ)_/¯ | ||
minJavaVersionForTests = JavaVersion.VERSION_11 | ||
|
||
// need access to jdk.jfr package | ||
skipSettingCompilerRelease = true | ||
|
||
excludeJdk = ['SEMERU11', 'SEMERU17'] | ||
} | ||
|
||
apply from: "$rootDir/gradle/java.gradle" | ||
apply plugin: 'idea' | ||
|
||
|
||
sourceSets { | ||
"main_java11" { | ||
java.srcDirs "${project.projectDir}/src/main/java11" | ||
} | ||
} | ||
|
||
compileMain_java11Java.configure { | ||
setJavaVersion(it, 11) | ||
sourceCompatibility = JavaVersion.VERSION_1_9 | ||
targetCompatibility = JavaVersion.VERSION_1_9 | ||
} | ||
|
||
dependencies { | ||
api project(':dd-java-agent:agent-profiling:profiling-controller-jfr') | ||
main_java11CompileOnly project(':dd-java-agent:agent-profiling:profiling-controller-jfr') | ||
|
||
implementation deps.slf4j | ||
|
||
testImplementation deps.mockito | ||
testImplementation deps.junit5 | ||
} | ||
|
||
excludedClassesCoverage += ['com.datadog.profiling.controller.jfr.JdkTypeIDs'] | ||
|
||
|
||
// Shared JFR implementation. The earliest Java version JFR is working on is Java 8 | ||
|
||
//tasks.named("compileTestJava").configure { | ||
// setJavaVersion(it, 11) | ||
// // tests should be compiled in Java 8 compatible way | ||
// sourceCompatibility = JavaVersion.VERSION_1_8 | ||
// targetCompatibility = JavaVersion.VERSION_1_8 | ||
// // Disable '-processing' because some annotations are not claimed. | ||
// // Disable '-options' because we are compiling for java8 without specifying bootstrap - intentionally. | ||
// // Disable '-path' because we do not have some of the paths seem to be missing. | ||
// options.compilerArgs.addAll(['-Xlint:all,-processing,-options,-path'/*, '-Werror'*/]) | ||
//} | ||
|
||
forbiddenApisMain { | ||
failOnMissingClasses = false | ||
} | ||
|
||
idea { | ||
module { | ||
jdkName = '11' | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...fr/implementation/src/main/java/com/datadog/profiling/controller/jfr/SimpleJFRAccess.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.datadog.profiling.controller.jfr; | ||
|
||
import datadog.trace.api.Platform; | ||
import java.lang.instrument.Instrumentation; | ||
import jdk.jfr.internal.JVM; | ||
|
||
public class SimpleJFRAccess extends JFRAccess { | ||
public static class FactoryImpl implements JFRAccess.Factory { | ||
@Override | ||
public JFRAccess create(Instrumentation inst) { | ||
return !Platform.isJ9() && Platform.isJavaVersion(8) ? new SimpleJFRAccess() : null; | ||
} | ||
} | ||
|
||
@Override | ||
public void setStackDepth(int depth) { | ||
JVM.getJVM().setStackDepth(depth); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...fr/implementation/src/main/java11/com/datadog/profiling/controller/jfr/JPMSJFRAccess.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.datadog.profiling.controller.jfr; | ||
|
||
import datadog.trace.api.Platform; | ||
import java.lang.instrument.Instrumentation; | ||
import java.lang.invoke.MethodHandle; | ||
import java.lang.invoke.MethodHandles; | ||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Modifier; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import jdk.jfr.Event; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class JPMSJFRAccess extends JFRAccess { | ||
public static final class FactoryImpl implements JFRAccess.Factory { | ||
private static final Logger log = LoggerFactory.getLogger(FactoryImpl.class); | ||
|
||
@Override | ||
public JFRAccess create(Instrumentation inst) { | ||
if (!Platform.isJ9() && Platform.isJavaVersionAtLeast(9)) { | ||
try { | ||
return new JPMSJFRAccess(inst); | ||
} catch (Exception e) { | ||
log.debug("Unable to obtain JFR internal access", e); | ||
} | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
private final MethodHandle setStackDepthMH; | ||
|
||
public JPMSJFRAccess(Instrumentation inst) throws Exception { | ||
Module unnamedModule = JFRAccess.class.getClassLoader().getUnnamedModule(); | ||
Module targetModule = Event.class.getModule(); | ||
|
||
Map<String, Set<Module>> extraOpens = Map.of("jdk.jfr.internal", Set.of(unnamedModule)); | ||
|
||
// Redefine the module | ||
inst.redefineModule( | ||
targetModule, | ||
Collections.emptySet(), | ||
extraOpens, | ||
extraOpens, | ||
Collections.emptySet(), | ||
Collections.emptyMap()); | ||
|
||
Class<?> jvmClass = Class.forName("jdk.jfr.internal.JVM"); | ||
Method m = jvmClass.getMethod("setStackDepth", int.class); | ||
m.setAccessible(true); | ||
MethodHandle mh = MethodHandles.publicLookup().unreflect(m); | ||
if (!Modifier.isStatic(m.getModifiers())) { | ||
// instance method - need to call JVM.getJVM() and bind the instance | ||
Object jvm = jvmClass.getMethod("getJVM").invoke(null); | ||
mh = mh.bindTo(jvm); | ||
} | ||
setStackDepthMH = mh; | ||
} | ||
|
||
@Override | ||
public void setStackDepth(int depth) { | ||
try { | ||
setStackDepthMH.invokeExact(depth); | ||
} catch (Throwable throwable) { | ||
throw new RuntimeException(throwable); | ||
} | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
...c/main/resources/META-INF/services/com.datadog.profiling.controller.jfr.JFRAccess$Factory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
com.datadog.profiling.controller.jfr.SimpleJFRAccess$FactoryImpl | ||
com.datadog.profiling.controller.jfr.JPMSJFRAccess$FactoryImpl |
43 changes: 43 additions & 0 deletions
43
...rofiling-controller-jfr/src/main/java/com/datadog/profiling/controller/jfr/JFRAccess.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.datadog.profiling.controller.jfr; | ||
|
||
import java.lang.instrument.Instrumentation; | ||
import java.util.ServiceLoader; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public abstract class JFRAccess { | ||
private static final Logger log = LoggerFactory.getLogger(JFRAccess.class); | ||
|
||
public static final JFRAccess NOOP = | ||
new JFRAccess() { | ||
@Override | ||
public void setStackDepth(int depth) {} | ||
}; | ||
|
||
public interface Factory { | ||
JFRAccess create(Instrumentation inst); | ||
} | ||
|
||
private static volatile JFRAccess INSTANCE = NOOP; | ||
|
||
public static JFRAccess instance() { | ||
return INSTANCE; | ||
} | ||
|
||
public static void setup(Instrumentation inst) { | ||
JFRAccess access = NOOP; | ||
if (inst != null) { | ||
for (Factory factory : ServiceLoader.load(Factory.class, JFRAccess.class.getClassLoader())) { | ||
JFRAccess candidate = factory.create(inst); | ||
if (candidate != null) { | ||
access = candidate; | ||
break; | ||
} | ||
} | ||
} | ||
log.debug("JFR access: {}", access.getClass().getName()); | ||
INSTANCE = access; | ||
} | ||
|
||
public abstract void setStackDepth(int depth); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.