Skip to content

Commit

Permalink
remove obsolete ibm workaround
Browse files Browse the repository at this point in the history
run tests for 8 and 11 on J9

test exclude openj9 on scl test

try use Ibm sys classloader

expect GeneratedSerializationConstructor

remove -Porg.gradle.java.installations.auto-download=false

get branch current with rebase

exclude cassandra datastax test

add some why comments

add some why comments

add some why comments

fix java install

add incompatible test marker

revert back to temurin
  • Loading branch information
tbradellis committed Oct 17, 2022
1 parent f1430eb commit ced4864
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.newrelic.agent.Transaction;
import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Trace;
import com.newrelic.test.marker.IBMJ9IncompatibleTest;
import com.newrelic.test.marker.Java17IncompatibleTest;
import com.newrelic.test.marker.Java19IncompatibleTest;
import org.junit.Assert;
Expand Down Expand Up @@ -67,7 +68,7 @@ public void testMissingNewRelicClass() throws ClassNotFoundException {

// Java 12 no longer lets us access the declared field
@Test
@Category({ Java17IncompatibleTest.class, Java19IncompatibleTest.class })
@Category({ IBMJ9IncompatibleTest.class, Java17IncompatibleTest.class, Java19IncompatibleTest.class })
public void testSetSystemClassLoader() throws Exception {

final ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
import com.newrelic.agent.interfaces.SamplingPriorityQueue;
import com.newrelic.agent.model.SpanEvent;
import com.newrelic.agent.service.ServiceFactory;
import com.newrelic.test.marker.IBMJ9IncompatibleTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Categories;
import org.junit.experimental.categories.Category;
import test.newrelic.EnvironmentHolderSettingsGenerator;
import test.newrelic.test.agent.EnvironmentHolder;

Expand Down Expand Up @@ -98,6 +101,7 @@ public void testNoticedStringDoesNotBubble() {
));
}

@Category(IBMJ9IncompatibleTest.class)
@Test
public void testNoticedErrorOverridesThrownError() {
runTransaction(new SpanErrorFlow.NoticeAndThrow());
Expand Down
7 changes: 5 additions & 2 deletions gradle/script/java.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,19 @@ test {
if (project.hasProperty("test11")) {
configureTest("jdk11") {
useJUnit {
excludeCategories 'com.newrelic.test.marker.Java11IncompatibleTest'
excludeCategories 'com.newrelic.test.marker.Java11IncompatibleTest', 'com.newrelic.test.marker.IBMJ9IncompatibleTest'
}

}
}
if (project.hasProperty("test8")) {
configureTest("jdk8") {
useJUnit {
excludeCategories 'com.newrelic.test.marker.Java8IncompatibleTest'
excludeCategories 'com.newrelic.test.marker.Java8IncompatibleTest', 'com.newrelic.test.marker.IBMJ9IncompatibleTest'
}

}

}

// Alternate JDK distributions that we test against
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.newrelic.agent.introspec.Introspector;
import com.newrelic.agent.introspec.TraceSegment;
import com.newrelic.agent.introspec.TransactionTrace;
import com.newrelic.test.marker.IBMJ9IncompatibleTest;
import com.newrelic.test.marker.Java11IncompatibleTest;
import com.newrelic.test.marker.Java17IncompatibleTest;
import com.newrelic.test.marker.Java19IncompatibleTest;
Expand All @@ -32,7 +33,7 @@
import static org.junit.Assert.assertNotNull;

// Issue when running cassandra unit on Java 9+ - https:/jsevellec/cassandra-unit/issues/249
@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java19IncompatibleTest.class })
@Category({ IBMJ9IncompatibleTest.class, Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java19IncompatibleTest.class })
@RunWith(InstrumentationTestRunner.class)
@InstrumentationTestConfig(includePrefixes = { "com.datastax.oss.driver" })
public class CassandraInstrumented {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.newrelic.agent.introspec.InstrumentationTestConfig;
import com.newrelic.agent.introspec.InstrumentationTestRunner;
import com.newrelic.agent.introspec.Introspector;
import com.newrelic.test.marker.IBMJ9IncompatibleTest;
import com.newrelic.test.marker.Java11IncompatibleTest;
import com.newrelic.test.marker.Java17IncompatibleTest;
import com.newrelic.test.marker.Java19IncompatibleTest;
Expand All @@ -25,7 +26,7 @@
import static org.junit.Assert.assertEquals;

// Issue when running cassandra unit on Java 9+ - https:/jsevellec/cassandra-unit/issues/249
@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java19IncompatibleTest.class })
@Category({ IBMJ9IncompatibleTest.class, Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java19IncompatibleTest.class })
@RunWith(InstrumentationTestRunner.class)
@InstrumentationTestConfig(includePrefixes = { "none" })
public class CassandraNoInstrumentation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,6 @@ public interface AgentConfig extends com.newrelic.api.agent.Config, DataSenderCo

boolean isHighSecurity();

boolean getIbmWorkaroundEnabled();

/**
* Get the agent's label configuration.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public class AgentConfigImpl extends BaseConfig implements AgentConfig {
public static final String EXT_CONFIG_DIR = "extensions.dir";
public static final String HIGH_SECURITY = "high_security";
public static final String HOST = "host";
public static final String IBM_WORKAROUND = "ibm_iv25688_workaround";
public static final String IGNORE_JARS = "ignore_jars";
public static final String INSERT_API_KEY = "insert_api_key";
public static final String JDBC_SUPPORT = "jdbc_support";
Expand Down Expand Up @@ -148,7 +147,6 @@ public class AgentConfigImpl extends BaseConfig implements AgentConfig {
* host in newrelic.yml. This value makes the default behavior always work.
*/
public static final String DEFAULT_HOST = "collector.newrelic.com";
public static final boolean DEFAULT_IBM_WORKAROUND = IBMUtils.getIbmWorkaroundDefault();
public static final String DEFAULT_INSERT_API_KEY = "";
// jdbc support
public static final String GENERIC_JDBC_SUPPORT = "generic";
Expand Down Expand Up @@ -208,7 +206,6 @@ public class AgentConfigImpl extends BaseConfig implements AgentConfig {
private final boolean genericJdbcSupportEnabled;
private final boolean highSecurity;
private final String host;
private final boolean ibmWorkaroundEnabled;
private final List<String> ignoreJars;
private final String insertApiKey;
private final boolean isApdexTSet;
Expand Down Expand Up @@ -328,7 +325,6 @@ private AgentConfigImpl(Map<String, Object> props) {
caBundlePath = initSSLConfig();
trimStats = getProperty(TRIM_STATS, DEFAULT_TRIM_STATS);
platformInformationEnabled = getProperty(PLATFORM_INFORMATION_ENABLED, DEFAULT_PLATFORM_INFORMATION_ENABLED);
ibmWorkaroundEnabled = getProperty(IBM_WORKAROUND, DEFAULT_IBM_WORKAROUND);
transactionNamingMode = parseTransactionNamingMode();
maxStackTraceLines = getProperty(MAX_STACK_TRACE_LINES, DEFAULT_MAX_STACK_TRACE_LINES);
String[] jdbcSupport = getProperty(JDBC_SUPPORT, DEFAULT_JDBC_SUPPORT).split(",");
Expand Down Expand Up @@ -1318,11 +1314,6 @@ public boolean isPutForDataSend() {
return putForDataSend;
}

@Override
public boolean getIbmWorkaroundEnabled() {
return this.ibmWorkaroundEnabled;
}

@Override
public LabelsConfig getLabelsConfig() {
return labelsConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,9 @@

public class IBMUtils {
private static final String IBM_VENDOR = "IBM Corporation";
private static final Pattern srNumberPattern = Pattern.compile("\\(SR([0-9]+)[^()]*\\)\\s*$");

public static boolean isIbmJVM() {
return IBM_VENDOR.equals(System.getProperty("java.vendor"));
}

/**
* See JAVA-1206.
*
* Default ibm workaround flag to true for known bad or unparsable ibm versions.
*/
public static boolean getIbmWorkaroundDefault() {
try {
if (isIbmJVM()) {
String jvmVersion = System.getProperty("java.specification.version", "");
int srNum = getIbmSRNumber();

if ("1.7".equals(jvmVersion) && srNum >= 4) {
// IBM Ticket says 7.SR3 is fixed, but no jvm can be found to test against
return false;
}
return true;
}
return false;
} catch (Exception e) {
return true;
}
}

/**
* Parse the IBM Service Refresh patch version out of the system properties.
*
* @return the SR[0-9]* int, or -1 if no version can be found.
*/
public static int getIbmSRNumber() {
if (isIbmJVM()) {
String runtimeVersion = System.getProperty("java.runtime.version", "");
Matcher matcher = srNumberPattern.matcher(runtimeVersion);
if (matcher.find()) {
return Integer.valueOf(matcher.group(1));
}
}
return -1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ public boolean isMissingResourceExpected(String className) {
}

// generated classes
if (className.contains("GeneratedConstructorAccessor") || className.contains("GeneratedMethodAccessor")
|| className.contains("BoundMethodHandle$") || className.startsWith("jdk.jfr.internal.handlers.EventHandler")) {
if (className.contains("GeneratedConstructorAccessor") ||
className.contains("GeneratedMethodAccessor") ||
className.contains("GeneratedSerializationConstructor") ||
className.contains("BoundMethodHandle$") ||
className.startsWith("jdk.jfr.internal.handlers.EventHandler")) {
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.newrelic.agent.InstrumentationProxy;
import com.newrelic.agent.bridge.AgentBridge;
import com.newrelic.agent.config.ClassTransformerConfig;
import com.newrelic.agent.config.IBMUtils;
import com.newrelic.agent.instrumentation.ClassLoaderClassFinder;
import com.newrelic.agent.instrumentation.builtin.AgentClassLoaderBaseInstrumentation;
import com.newrelic.agent.instrumentation.builtin.AgentClassLoaderInstrumentation;
Expand Down Expand Up @@ -264,18 +263,11 @@ public void start(Class<?>[] loadedClasses) {
}
}

// Avoid the IBM jvm crasher. See JAVA-1206.
if (ServiceFactory.getConfigService().getDefaultAgentConfig().getIbmWorkaroundEnabled()) {
Agent.LOG.log(Level.FINE,
"ClassLoaderClassTransformer: skipping redefine of {0}. IBM SR {1}. java.runtime.version {2}",
ClassLoader.class.getName(), IBMUtils.getIbmSRNumber(), System.getProperty("java.runtime.version"));
} else {
try {
Agent.LOG.log(Level.FINER, "ClassLoaderClassTransformer: Attempting to redefine {0}", ClassLoader.class);
InstrumentationProxy.forceRedefinition(instrumentation, ClassLoader.class);
} catch (Exception e) {
Agent.LOG.log(Level.FINEST, e, "ClassLoaderClassTransformer: Error redefining {0}", ClassLoader.class.getName());
}
try {
Agent.LOG.log(Level.FINER, "ClassLoaderClassTransformer: Attempting to redefine {0}", ClassLoader.class);
InstrumentationProxy.forceRedefinition(instrumentation, ClassLoader.class);
} catch (Exception e) {
Agent.LOG.log(Level.FINEST, e, "ClassLoaderClassTransformer: Error redefining {0}", ClassLoader.class.getName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,33 +160,28 @@ private static void startAgent(String agentArgs, Instrumentation inst) {
String javaVersion = System.getProperty("java.version", "");
BootstrapLoader.load(inst, isJavaSqlLoadedOnPlatformClassLoader(javaVersion));

// Check for the IBM workaround
boolean ibmWorkaround = IBMUtils.getIbmWorkaroundDefault();
if (System.getProperty("ibm_iv25688_workaround") != null) {
ibmWorkaround = Boolean.parseBoolean(System.getProperty("ibm_iv25688_workaround"));
}
ClassLoader agentClassLoaderParent = getPlatformClassLoaderOrNull();

ClassLoader classLoader;
if (ibmWorkaround) {
// For the IBM workaround lets just use the System ClassLoader
classLoader = ClassLoader.getSystemClassLoader();
// Create a new URLClassLoader instance for the agent to use instead of relying
// on the System ClassLoader (aka and now called Application ClassLoader)
URL[] codeSource;
if (isJavaSqlLoadedOnPlatformClassLoader(javaVersion)) {
//Java 9+ we haven't added the agent-bridge-datastore.jar to the classpath yet
//because java.sql is loaded by the platform loader, so we skipped loading agent-bridge-datastore for Java 9+ versions.
//We now need to give the agent-bridge-datastore url and the platform classloader (as the parent classloader).
URL url = BootstrapLoader.getDatastoreJarURL();
codeSource = new URL[] { getAgentJarUrl(), url };
} else {
ClassLoader agentClassLoaderParent = getPlatformClassLoaderOrNull();

// Create a new URLClassLoader instance for the agent to use instead of relying on the System ClassLoader
URL[] codeSource;
if (isJavaSqlLoadedOnPlatformClassLoader(javaVersion)) {
URL url = BootstrapLoader.getDatastoreJarURL();
codeSource = new URL[] { getAgentJarUrl(), url };
} else {
codeSource = new URL[] { getAgentJarUrl() };
}

classLoader = new JVMAgentClassLoader(codeSource, agentClassLoaderParent);

redefineJavaBaseModule(inst, classLoader);
addReadUnnamedModuleToHttpModule(inst, agentClassLoaderParent);
//agent-bridge-datastore.jar was already added to the classpath by the BootstrapLoader
codeSource = new URL[] { getAgentJarUrl() };
}
// When we have come through the above 'else' path (java versions < 9) the agentClassLoaderParent will be null. This is okay
// because the url provides the jar and all the agent classes. The weaver, agent-api, agent-bridge, and agent-datastore
//jars have already been added to the classpath and loaded by the com.newrelic.BootstrapLoader (which is loaded by AppClassLoader) for this case.
ClassLoader classLoader = new JVMAgentClassLoader(codeSource, agentClassLoaderParent);

redefineJavaBaseModule(inst, classLoader);
addReadUnnamedModuleToHttpModule(inst, agentClassLoaderParent);

Class<?> agentClass = classLoader.loadClass(AGENT_CLASS_NAME);
Method continuePremain = agentClass.getDeclaredMethod("continuePremain", String.class, Instrumentation.class, long.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import com.newrelic.jfr.ThreadNameNormalizer;
import com.newrelic.jfr.daemon.DaemonConfig;
import com.newrelic.jfr.daemon.JfrRecorderException;
import com.newrelic.test.marker.IBMJ9IncompatibleTest;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

Expand Down Expand Up @@ -50,6 +52,7 @@ public void before() {
.thenReturn(ThreadNameNormalizer.DEFAULT_PATTERN);
}


@Test
public void daemonConfigBuiltCorrect() {
JfrService jfrService = new JfrService(jfrConfig, agentConfig);
Expand Down Expand Up @@ -94,7 +97,7 @@ public void jfrLoopDoesNotStartWhenIsEnabledIsFalse() throws JfrRecorderExceptio
assertFalse(spyJfr.isEnabled());
verify(spyJfr, times(0)).startJfrLoop();
}

@Category( IBMJ9IncompatibleTest.class )
@Test
public void jfrLoopDoesStart() {
JfrService jfrService = new JfrService(jfrConfig, agentConfig);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.newrelic.test.marker;


/**
* Marker interface to denote a unit/functional/instrumentation test that is incompatible with IBM Semeru and other OpenJ9 runtimes.
*/

public interface IBMJ9IncompatibleTest {
}

0 comments on commit ced4864

Please sign in to comment.