JDK Bug System | Webbug Group | 2 months ago
  1. 0

    FULL PRODUCT VERSION : java version "1.8.0_102" Java(TM) SE Runtime Environment (build 1.8.0_102-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode) FULL OS VERSION : Linux 4.6.2-1-ARCH #1 SMP PREEMPT Wed Jun 8 08:40:59 CEST 2016 x86_64 GNU/Linux A DESCRIPTION OF THE PROBLEM : This is about Java agent, or Java Instrumentation. I created a ClassFileTransformer which does basically nothing. It looks like public class LoggingTransformer implements ClassFileTransformer { static int transformCount = 0; public LoggingTransformer() { } public byte[] transform(ClassLoader loader, String className, Class classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { transformCount++; if (transformCount % 100 == 0) System.out.println("transformCount:" + transformCount); return null; } } Then I created this transformer and repeatedly invoke inst.retransformClasses(), as depicted below: public class LoggingAgent { public static void premain(String agentArgs, Instrumentation inst) throws Exception { LoggingTransformer t = new LoggingTransformer(); inst.addTransformer(t, true); Class demoClass = Class.forName("Tester"); while (true) { inst.retransformClasses(demoClass); } } } The command I used to run the application with my Java agent is : java -XX:+TraceClassLoading -XX:+TraceClassUnloading -XX:MetaspaceSize=12m -XX:MaxMetaspaceSize=12m -javaagent:../lib/loggingagent.jar MyDemoMain Note I set metaspace to 12m just to make it fail in a shorter time. The result is that, after about 5600 times of invocation of inst.retransformClasses() which triggers LoggingTransformer.transform(), the JVM crashes with below error: Exception in thread "main" java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke( at sun.reflect.DelegatingMethodAccessorImpl.invoke( at java.lang.reflect.Method.invoke( at sun.instrument.InstrumentationImpl.loadClassAndStartAgent( at sun.instrument.InstrumentationImpl.loadClassAndCallPremain( Caused by: java.lang.OutOfMemoryError at sun.instrument.InstrumentationImpl.retransformClasses0(Native Method) at sun.instrument.InstrumentationImpl.retransformClasses( at LoggingAgent.premain( ... 6 more Since I enabled classloading and class unloading logs, I do see messages 'Loaded Tester from __VM_RedefineClasses__]' appearing in the log output, but I can't find any unloading messages related. THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Yes THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : 1. Write a couple of Agent classes as mentioned above; 2. Write a manifest file as below: Premain-Class: LoggingAgent Agent-Class: LoggingAgent Can-Redefine-Classes: true Can-Retransform-Classes: true 3. Make sure you call inst.retransformClasses() releatedly from within the agent's premain method 4. package your agent classes with manifest file and produces a jar file 5. Write a simple class MyDemoMain which has a main() method which just sleeps forever. 6. Once the number of invocation of inst.retransformClasses() is high enough, you will see JVM complains. EXPECTED VERSUS ACTUAL BEHAVIOR : 1. JVM should garbage collect the old class definitions when a class is transformed; 2. Such that JVM should not run out of memory if the same class is being redfined again and again; 3. We shall see class unloading logs from enabling -XX:+TraceClassUnloading option when running the program. REPRODUCIBILITY : This bug can be reproduced always.

    JDK Bug System | 2 months ago | Webbug Group
  2. Speed up your debug routine!

    Automated exception search integrated into your IDE

  3. 0

    Byte[] and java.lang.OutOfMemoryError read/write file by bits

    Stack Overflow | 10 months ago | Gowtham
    java.lang.RuntimeException: An error occured while executing doInBackground()

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.OutOfMemoryError

      No message provided

      at sun.instrument.InstrumentationImpl.retransformClasses0()
    2. Java RT
      1. sun.instrument.InstrumentationImpl.retransformClasses0(Native Method)
      2. sun.instrument.InstrumentationImpl.retransformClasses(
      2 frames
    3. Unknown
      1. LoggingAgent.premain(
      1 frame
    4. Java RT
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(
      4. java.lang.reflect.Method.invoke(
      5. sun.instrument.InstrumentationImpl.loadClassAndStartAgent(
      6. sun.instrument.InstrumentationImpl.loadClassAndCallPremain(
      6 frames