Skip to content

Commit

Permalink
Merge pull request #70 from rshivane/master
Browse files Browse the repository at this point in the history
Fixes for JDK11+
  • Loading branch information
rshivane authored Sep 13, 2020
2 parents ab40713 + fd6b73d commit a9e076f
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 70 deletions.
21 changes: 16 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,24 @@
# limitations under the License.
#

language: java
sudo: false

env:
matrix:
- METRICS_VERSION=3.2.6
- METRICS_VERSION=4.1.9
language: java

jdk:
- openjdk8
- openjdk11
- openjdk12
- openjdk13
- openjdk14

env:
- METRICS_VERSION=3.2.6
- METRICS_VERSION=4.1.9

#jobs:
# allow_failures:
# - jdk: openjdk11

services:
- memcached
Expand Down Expand Up @@ -104,6 +112,7 @@ deploy:
on:
tags: true
condition: $PACKAGE_VERSION != "" && $IS_PRIMARY_MATRIX_JOB == "true" && $BINTRAY_API_KEY != ""
jdk: openjdk8
- edge:
branch: v1.8.47
provider: bintray
Expand All @@ -113,6 +122,7 @@ deploy:
on:
tags: true
condition: $PACKAGE_VERSION != "" && $IS_PRIMARY_MATRIX_JOB == "true" && $BINTRAY_API_KEY != ""
jdk: openjdk8
- edge:
branch: v1.8.47
provider: bintray
Expand All @@ -122,3 +132,4 @@ deploy:
on:
tags: true
condition: $PACKAGE_VERSION != "" && $IS_PRIMARY_MATRIX_JOB == "true" && $BINTRAY_API_KEY != ""
jdk: openjdk8
25 changes: 10 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,18 @@ limitations under the License.
<java.version>1.8</java.version>
<maven.version>3.5</maven.version>
<netty.version>4.1.15.Final</netty.version>
<surefire.version>3.0.0-M3</surefire.version>
<surefire.version>3.0.0-M5</surefire.version>
<junit.version>4.13</junit.version>
<jacoco.version>0.8.5</jacoco.version>
<byteman.version>4.0.6</byteman.version>
<byteman.version>4.0.13</byteman.version>
<metrics.version>4.1.9</metrics.version>
<prometheus.version>0.9.0</prometheus.version>
<apptuit.reporter.version>0.9.2</apptuit.reporter.version>

<!-- Acceptance Criteria -->
<enforce.code.style>false</enforce.code.style>
<ignore.license.checks>false</ignore.license.checks>
<enforce.findbugs>true</enforce.findbugs>
<enforce.spotbugs>true</enforce.spotbugs>
<minimum.complexity.coverage>0.60</minimum.complexity.coverage>
<minimum.instruction.coverage>0.80</minimum.instruction.coverage>
<max.agent.file.size>2.5</max.agent.file.size>
Expand Down Expand Up @@ -147,7 +147,6 @@ limitations under the License.
<groupId>org.jboss.byteman</groupId>
<artifactId>byteman</artifactId>
<version>${byteman.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.dropwizard.metrics</groupId>
Expand Down Expand Up @@ -434,6 +433,7 @@ limitations under the License.
<Premain-Class>ai.apptuit.metrics.jinsight.Agent</Premain-Class>
<Agent-Class>ai.apptuit.metrics.jinsight.Agent</Agent-Class>
<Agent-Version>${project.version}</Agent-Version>
<Implementation-Version>${project.version}</Implementation-Version>
<Can-Redefine-Classes>true</Can-Redefine-Classes>
<Can-Retransform-Classes>true</Can-Retransform-Classes>
</manifestEntries>
Expand Down Expand Up @@ -569,7 +569,7 @@ limitations under the License.
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.33</version>
<version>8.36.1</version>
</dependency>
</dependencies>
<configuration>
Expand Down Expand Up @@ -615,13 +615,13 @@ limitations under the License.
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.5</version>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>4.0.4</version>
<configuration>
<xmlOutput>true</xmlOutput>
<effort>Max</effort>
<failOnError>${enforce.findbugs}</failOnError>
<failOnError>${enforce.spotbugs}</failOnError>
<includeTests>false</includeTests>
<xmlOutputDirectory>${project.build.directory}/reports/</xmlOutputDirectory>
<outputDirectory>${project.build.directory}/reports/</outputDirectory>
Expand Down Expand Up @@ -784,11 +784,6 @@ limitations under the License.
<artifactId>apache-rat-plugin</artifactId>
<version>0.12</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
Expand Down Expand Up @@ -851,7 +846,7 @@ limitations under the License.
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>3.1.11</version>
<version>4.0.4</version>
<configuration>
<effort>Max</effort>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@
package ai.apptuit.metrics.jinsight;

import ai.apptuit.metrics.jinsight.ContextualModuleLoader.ModuleClassLoader;
import java.io.File;
import java.io.IOException;
import java.lang.ref.SoftReference;
import java.net.URL;
import java.net.URLClassLoader;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;
import java.util.WeakHashMap;
Expand Down Expand Up @@ -88,8 +92,47 @@ public Class<?> loadHelperAdapter(ModuleClassLoader helperLoader, String helperA

public static class ModuleClassLoader extends URLClassLoader {

private static final URL[] SYS_CLASS_PATH = getSystemClassPath();

public ModuleClassLoader(ClassLoader cl) {
super(((URLClassLoader) ClassLoader.getSystemClassLoader()).getURLs(), cl);
super(SYS_CLASS_PATH, cl);
}

private static URL[] getSystemClassPath() {
String cp = System.getProperty("java.class.path");
if (cp == null || cp.isEmpty()) {
String initialModuleName = System.getProperty("jdk.module.main");
cp = initialModuleName == null ? "" : null;
}

ArrayList<URL> path = new ArrayList<>();
int off;
if (cp != null) {
off = 0;

int next;
do {
next = cp.indexOf(File.pathSeparator, off);
String element = next == -1 ? cp.substring(off) : cp.substring(off, next);
if (!element.isEmpty()) {
URL url = toFileURL(element);
if (url != null) {
path.add(url);
}
}

off = next + 1;
} while (next != -1);
}
return path.toArray(new URL[0]);
}

private static URL toFileURL(String path) {
try {
return (new File(path)).getCanonicalFile().toURI().toURL();
} catch (IOException e) {
return null;
}
}

public Class<?> addClass(String name, byte[] bytes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package ai.apptuit.metrics.jinsight.modules.jvm;

import static ai.apptuit.metrics.jinsight.modules.jvm.MemoryUsageMetrics.sanitizePoolName;

import ai.apptuit.metrics.client.TagEncodedMetricName;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Metric;
Expand Down Expand Up @@ -46,7 +48,7 @@ public Map<String, Metric> getMetrics() {
final Map<String, Metric> gauges = new HashMap<>();

for (BufferPoolMXBean pool : pools) {
final String poolName = pool.getName();
final String poolName = sanitizePoolName(pool.getName());
gauges.put(getMetricName("capacity.bytes", POOL_TAG_NAME, poolName),
(Gauge<Long>) pool::getTotalCapacity);
gauges.put(getMetricName("count", POOL_TAG_NAME, poolName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
*/
class MemoryUsageMetrics implements MetricSet {

private static final Pattern WHITESPACE = Pattern.compile("[\\s]+");
private static final Pattern SPECIAL_CHARS = Pattern.compile("[\\s-']+");
private static final Pattern SPECIAL_CHARS_ENDING = Pattern.compile("[\\s-']+$");

private static final String EDEN_GEN = "eden";
private static final String SURVIVOR_GEN = "survivor";
Expand Down Expand Up @@ -121,9 +122,9 @@ protected Ratio getRatio() {
});

for (final MemoryPoolMXBean pool : memoryPools) {
final String poolName = WHITESPACE.matcher(pool.getName()).replaceAll("_").toLowerCase();

String generation = getPoolGeneration(pool.getName());
String poolNameOrig = pool.getName();
final String poolName = sanitizePoolName(poolNameOrig);
String generation = getPoolGeneration(poolNameOrig);
String[] poolNameTags;
if (generation != null) {
poolNameTags = new String[]{"pool", generation, "name", poolName};
Expand Down Expand Up @@ -162,6 +163,11 @@ protected Ratio getRatio() {
return Collections.unmodifiableMap(gauges);
}

static String sanitizePoolName(String poolName) {
String s = SPECIAL_CHARS_ENDING.matcher(poolName.toLowerCase()).replaceAll("");
return SPECIAL_CHARS.matcher(s).replaceAll("_");
}

private String getMetricName(String base, String... tags) {
return TagEncodedMetricName.decode(base).withTags(tags).toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,13 @@ private static void printStackTraceElement(Writer writer, StackTraceElement trac
at java.lang.reflect.Method.invoke(Method.java:497)
*/

if ("sun.reflect.NativeMethodAccessorImpl".equals(className)) {
if ("sun.reflect.NativeMethodAccessorImpl".equals(className) || "jdk.internal.reflect.NativeMethodAccessorImpl".equals(className)) {
if (traceElement.getMethodName().equals("invoke0")) {
return;
}
className = "sun.reflect.$$MethodAccessor$$";
} else if (className.startsWith("sun.reflect.GeneratedMethodAccessor")) {
} else if (className.startsWith("sun.reflect.GeneratedMethodAccessor")
|| className.startsWith("jdk.internal.reflect.GeneratedMethodAccessor")) {
className = "sun.reflect.$$MethodAccessor$$";
}
}
Expand Down
Loading

0 comments on commit a9e076f

Please sign in to comment.