Tricky try-catch java code - java
public class Strange1 {
public static void main(String[] args) {
try {
Missing m = new Missing();
} catch (java.lang.NoClassDefFoundError ex) {
System.out.println("Got it!");
}
}
}
public class Strange2 {
public static void main(String[] args) {
Missing m;
try {
m = new Missing();
} catch (java.lang.NoClassDefFoundError ex) {
System.out.println("Got it!");
}
}
}
class Missing {
Missing() { }
}
If you run Strange1 and Strange2 after deleting Missing.class, Strange1 will throw NoClassDefFoundError; but Strange2 will print Got it!
Can anyone explain that? Thanks.
updated:
java bytecode for Strange1 :
0 new info.liuxuan.test.Missing [16]
3 dup
4 invokespecial info.liuxuan.test.Missing() [18]
7 astore_1 [m]
8 goto 20
11 astore_1 [ex]
12 getstatic java.lang.System.out : java.io.PrintStream [19]
15 ldc <String "Got it!"> [25]
17 invokevirtual java.io.PrintStream.println(java.lang.String) : void [27]
20 return
Exception Table:
[pc: 0, pc: 8] -> 11 when : java.lang.NoClassDefFoundError
Line numbers:
[pc: 0, line: 14]
[pc: 11, line: 15]
[pc: 12, line: 16]
[pc: 20, line: 18]
Local variable table:
[pc: 0, pc: 21] local: args index: 0 type: java.lang.String[]
[pc: 8, pc: 11] local: m index: 1 type: info.liuxuan.test.Missing
[pc: 12, pc: 20] local: ex index: 1 type: java.lang.NoClassDefFoundError
java bytecode for Strange2 :
0 new info.liuxuan.test.Missing [16]
3 dup
4 invokespecial info.liuxuan.test.Missing() [18]
7 astore_1 [m]
8 goto 20
11 astore_2 [ex]
12 getstatic java.lang.System.out : java.io.PrintStream [19]
15 ldc <String "Got it!"> [25]
17 invokevirtual java.io.PrintStream.println(java.lang.String) : void [27]
20 return
Exception Table:
[pc: 0, pc: 8] -> 11 when : java.lang.NoClassDefFoundError
Line numbers:
[pc: 0, line: 15]
[pc: 11, line: 16]
[pc: 12, line: 17]
[pc: 20, line: 19]
Local variable table:
[pc: 0, pc: 21] local: args index: 0 type: java.lang.String[]
[pc: 8, pc: 11] local: m index: 1 type: info.liuxuan.test.Missing
[pc: 12, pc: 20] local: ex index: 2 type: java.lang.NoClassDefFoundError
There is only one place is different:
11 astore_1 [ex]
and
11 astore_2 [ex]
updated again:
Everyone can try it in eclipse.
Prior to saying anything, i doub't this code won't even compile. because when compiler cannot find a class (Since its deleted). may be you are getting an error when trying to compile it using javac command. if thats the case its pretty normal and in no way its weird.
and let me add an another point.. check your imports, to contain Missing class. if it is there then remove it. and tell us whats happening.
I created two java files. Strange1.java contained classes Strange1 and Missing. Strange2.java contained Strange2 class. I removed Missing.class.
I got "Got it!" from both.
Please see the following details:
manohar#manohar-natty:~$ java -version
java version "1.6.0_25"
Java(TM) SE Runtime Environment (build 1.6.0_25-b06)
Java HotSpot(TM) Server VM (build 20.0-b11, mixed mode)
manohar#manohar-natty:~$ gedit Strange1.java
manohar#manohar-natty:~$ gedit Strange2.java
manohar#manohar-natty:~$ javac Strange1.java
manohar#manohar-natty:~$ javac Strange2.java
manohar#manohar-natty:~$ java Strange1
manohar#manohar-natty:~$ java Strange2
manohar#manohar-natty:~$ rm Missing.class
manohar#manohar-natty:~$ java Strange1
Got it!
manohar#manohar-natty:~$ java Strange2
Got it!
I executed it in Ubuntu 11.04 linux machine.
So it might be the java's version that you are using.
NoClassDefFoundError is thrown whenever the first reference(declaring or creating an instance) to the missing class is made. Now, throwing an error or catching it depends on whether you use try-catch block for your first reference or not.
Output
The behavior of both programs depends on the version of javac used to compile them and not the version of java used to run the compiled classes. However, it's easier to use the same javac and java versions.
We'll be using J2SE 5.0 and Java SE 6 because those are the earliest versions where the programs' behavior deviates.
With build 1.5.0_22-b03:
$ jdk1.5.0_22/bin/javac {Strange1,Strange2,Missing}.java
$ rm Missing.class
$ jdk1.5.0_22/bin/java Strange1
Exception in thread "main" java.lang.NoClassDefFoundError: Missing
$ jdk1.5.0_22/bin/java Strange2
Got it!
$ jdk1.5.0_22/bin/javap -c Strange1
Compiled from "Strange1.java"
public class Strange1 extends java.lang.Object{
public Strange1();
Code:
0: aload_0
1: invokespecial #1; //Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]);
Code:
0: new #2; //class Missing
3: dup
4: invokespecial #3; //Method Missing."<init>":()V
7: astore_1
8: goto 20
11: astore_1
12: getstatic #5; //Field java/lang/System.out:Ljava/io/PrintStream;
15: ldc #6; //String Got it!
17: invokevirtual #7; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
20: return
Exception table:
from to target type
0 8 11 Class java/lang/NoClassDefFoundError
}
Compiled from "Strange2.java"
public class Strange2 extends java.lang.Object{
public Strange2();
Code:
0: aload_0
1: invokespecial #1; //Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]);
Code:
0: new #2; //class Missing
3: dup
4: invokespecial #3; //Method Missing."<init>":()V
7: astore_1
8: goto 20
11: astore_2
12: getstatic #5; //Field java/lang/System.out:Ljava/io/PrintStream;
15: ldc #6; //String Got it!
17: invokevirtual #7; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
20: return
Exception table:
from to target type
0 8 11 Class java/lang/NoClassDefFoundError
}
With build 1.6.0_45-b06:
$ jdk1.6.0_45/bin/javac {Strange1,Strange2,Missing}.java
$ rm Missing.class
$ jdk1.6.0_45/bin/java Strange1
Got it!
$ jdk1.6.0_45/bin/java Strange2
Got it!
$ jdk1.6.0_45/bin/javap -c Strange1
<Same output as the corresponding command for J2SE 5.0>
$ jdk1.6.0_45/bin/javap -c Strange2
<Same output as the corresponding command for J2SE 5.0>
Analysis
The bytecode of Strange1 and Strange2 is nearly identical, except for the mapping of the catch parameter ex to a VM local variable. Strange1 stores it in VM variable 1, i.e., 11: astore_1. Strange2 stores it in VM variable 2, i.e., 11: astore_2.
In both classes, the local variable m is stored in VM variable 1. Both versions of main also have a merge point where the flow of control from two different code paths converge. The merge point is 20: return. It can be reached either by completing the try block normally, i.e., 8: goto 20, or by completing the catch block and falling through from instruction 17.
The existence of the merge point causes an exception during the verification of class Strange1, but not class Strange2 in J2SE 5.0.
JLS, Java SE 6 Edition - Chapter 12 - Execution specifies activities that occur during execution of a program:
The Java Virtual Machine starts up by loading a specified class and then invoking the method main in this specified class. Section §12.1 outlines the loading, linking, and initialization steps involved in executing main, as an introduction to the concepts in this chapter. Further sections specify the details of loading (§12.2), linking (§12.3), and initialization (§12.4).
JLS, Java SE 6 Edition - Section 12.3 - Linking of Classes and Interfaces specifies that the first activity that is involved in linking is verification.
JVMS, Java SE 7 Edition - Section 4.10 - Verification of class Files specifies the two strategies that a VM may use for verification:
There are two strategies that Java Virtual Machine implementations may
use for verification:
Verification by type checking must be used to verify class files whose version number is greater than or equal to 50.0.
Verification by type inference must be supported by all Java Virtual Machine implementations, except those conforming to the Java
ME CLDC and Java Card profiles, in order to verify class files whose
version number is less than 50.0.
Verification on Java Virtual Machine implementations supporting the Java ME CLDC and Java Card profiles is governed by their
respective specifications.
(Verification by type checking was added to JVMS, Second Edition for Java SE 6, and JVMS, Java SE 7 Edition incorporates these changes in a more accessible way.)
Verification by type inference (for class files whose version number is less than 50.0, i.e., Java SE 6)
To merge two local variable array states, corresponding pairs of local
variables are compared. If the two types are not identical, then
unless both contain reference values, the verifier records that the
local variable contains an unusable value. If both of the pair of
local variables contain reference values, the merged state contains a
reference to an instance of the first common superclass of the two
types.
JVMS, Second Edition - Section 4.9.2 - The Bytecode Verifier
When instruction 20 is reached from instruction 8 in Strange1.main, VM variable 1 contains an instance of the class Missing. When reached from instruction 17, it contains an instance of the class NoClassDefFoundError.
Because Missing.class has been deleted, the verifier can't load it to determine the first common superclass, and throws a NoClassDefFoundError. Note that there is no stack trace printed for the uncaught exception because it's thrown during verification, before class initialization and long before main begins execution.
Verification by type checking (for class files whose version number is greater than or equal to 50.0, i.e., Java SE 6)
(I've tried my best to follow the rules as precisely as possible. However, they are complex, dense and new to me. Hence, if you spot any mistakes, please feel free to correct them. If you could summarize the rules, that'd be great too.)
Because of the StackMapTable attribute, it's not necessary for the verifier to compute the first common superclass to merge the two VM variable 1's types as in the other strategy. Also, there's no need to actually load classes Missing, NoClassDefFoundError, or any other classes other than Strange1 for verification thanks to the constant pool and how the rules work.
Hence, there are no exceptions during verification. If you modify the catch block to print out the exception's stack trace, you'll see that the exception is thrown during the execution of Strange1.main with a proper stack trace:
# Modify Strange1.main's catch block to print out the exception's stack trace
$ jdk1.6.0_45/bin/javac {Strange1,Missing}.java
$ rm Missing.class
$ jdk1.6.0_45/bin/java Strange1
java.lang.NoClassDefFoundError: Missing
at Strange1.main(Strange1.java:4)
Caused by: java.lang.ClassNotFoundException: Missing
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 1 more
Got it!
The StackMapTable of Strange1:
$ jdk1.6.0_45/bin/javap -verbose Strange1 | tail
line 10: 20
StackMapTable: number_of_entries = 2
frame_type = 75 /* same_locals_1_stack_item */
stack = [ class java/lang/NoClassDefFoundError ]
frame_type = 8 /* same */
}
Let's go through the rules (as the verifier) to prove that Strange1.main is type safe. Each instruction of Strange1.main is verified to be type safe and satisfies all applicable (exception) handlers:
methodWithCodeIsTypeSafe(Strange1Class, MainMethod) :-
parseCodeAttribute(Strange1Class, MainMethod, FrameSize, MaxStack,
ParsedCode, Handlers, StackMap),
mergeStackMapAndCode(StackMap, ParsedCode, MergedCode),
methodInitialStackFrame(Strange1Class, MainMethod, FrameSize, StackFrame, ReturnType),
Environment = environment(Strange1Class, MainMethod, ReturnType, MergedCode,
MaxStack, Handlers),
handlersAreLegal(Environment),
mergedCodeIsTypeSafe(Environment, MergedCode, StackFrame).
mergedCodeIsTypeSafe(Environment, [instruction(Offset, Parse) | MoreCode],
frame(Locals, OperandStack, Flags)) :-
instructionIsTypeSafe(Parse, Environment, Offset,
frame(Locals, OperandStack, Flags),
NextStackFrame, ExceptionStackFrame),
instructionSatisfiesHandlers(Environment, Offset, ExceptionStackFrame),
mergedCodeIsTypeSafe(Environment, MoreCode, NextStackFrame).
mergedCodeIsTypeSafe(Environment, [stackMap(Offset, MapFrame) | MoreCode],
afterGoto) :-
mergedCodeIsTypeSafe(Environment, MoreCode, MapFrame).
instructionSatisfiesHandlers(Environment, Offset, ExceptionStackFrame) :-
exceptionHandlers(Environment, Handlers),
sublist(isApplicableHandler(Offset), Handlers, ApplicableHandlers),
checklist(instructionSatisfiesHandler(Environment, ExceptionStackFrame),
ApplicableHandlers).
instructionSatisfiesHandler(Environment, StackFrame, Handler) :-
...
/* The stack consists of just the exception. */
StackFrame = frame(Locals, _, Flags),
ExcStackFrame = frame(Locals, [ ExceptionClass ], Flags),
operandStackHasLegalLength(Environment, ExcStackFrame),
targetIsTypeSafe(Environment, ExcStackFrame, Target).
targetIsTypeSafe(Environment, StackFrame, Target) :-
offsetStackFrame(Environment, Target, Frame),
frameIsAssignable(StackFrame, Frame).
Instructions 0-7 are type safe because instructionIsTypeSafe is true and frameIsAssignable(Environment, frame(Locals, [ NoClassDefFoundErrorClass ], Flags), frame(Locals, [ NoClassDefFoundErrorClass ], Flags)) is true for each of them thanks to the first stack map frame for the (exception) handler target at instruction 19 (= 75 - 64):
frame_type = 75 /* same_locals_1_stack_item */
stack = [ class java/lang/NoClassDefFoundError ]
Instructions 12-17 are type safe thanks to the constant pool and the corresponding rules which are not listed (because they don't make up of the StackMapTable attribute).
There are 3 instructions left to prove their type-safety:
8: goto 20 is type safe thanks to the second stack map frame for the target at instruction 20 (= 75 - 64 + 8 + 1 = 19 + 8 + 1), instructing the verifier that the stack frame there is the same as the previous stack frame at instruction 8:
frame_type = 8 /* same */
instructionIsTypeSafe(goto(Target), Environment, _Offset, StackFrame,
afterGoto, ExceptionStackFrame) :-
targetIsTypeSafe(Environment, StackFrame, Target),
exceptionStackFrame(StackFrame, ExceptionStackFrame).
11: astore_1 is type safe because the store is type safe, because it can pop a NoClassDefFoundError that is a subtype of reference off the stack (thanks to the first stack map frame again), and then legally assign that type to the local variable 1, i.e., Locals = [arrayOf(String), class(Missing, Lm)] -> NewLocals = [arrayOf(String), class(NoClassDefFoundError, Ln)].
An astore instruction with operand Index is type safe and yields an outgoing type state NextStackFrame, if a store instruction with operand Index and type reference is type safe and yields an outgoing type state NextStackFrame.
instructionIsTypeSafe(astore(Index), Environment, _Offset, StackFrame,
NextStackFrame, ExceptionStackFrame) :-
storeIsTypeSafe(Environment, Index, reference, StackFrame, NextStackFrame),
exceptionStackFrame(StackFrame, ExceptionStackFrame).
More precisely, the store is type safe if one can pop a type ActualType that "matches" Type (that is, is a subtype of Type) off the operand stack (§4.10.1.4), and then legally assign that type the local variable LIndex.
storeIsTypeSafe(_Environment, Index, Type,
frame(Locals, OperandStack, Flags),
frame(NextLocals, NextOperandStack, Flags)) :-
popMatchingType(OperandStack, Type, NextOperandStack, ActualType),
modifyLocalVariable(Index, ActualType, Locals, NextLocals).
20: return is type safe because Strange1.main declares a void return type, and the enclosing method is not an <init> method:
A return instruction is type safe if the enclosing method declares a void return type, and either:
- The enclosing method is not an <init> method, or
- this has already been completely initialized at the point where the instruction occurs.
instructionIsTypeSafe(return, Environment, _Offset, StackFrame,
afterGoto, ExceptionStackFrame) :-
thisMethodReturnType(Environment, void),
StackFrame = frame(_Locals, _OperandStack, Flags),
notMember(flagThisUninit, Flags),
exceptionStackFrame(StackFrame, ExceptionStackFrame).
Related
Found an unspecified JVM Bytecode (0xe2) in java class file
I'm recently developing a program which can analyze a java class file. After running the program this was it's output: class test_1 { public static String a = "Hello World"; public static void main(String[] args) { int j = 0; for(int i = 0;i<10;i++) { System.out.println(a); j = j + j*j +j/(j+1); } } } I got a bytecode 0xe2 which is not specified in jvm specification 14. What does 0xe2 do??
You fail to account for multibyte opcodes. From the reference for goto, the format is: goto branchbyte1 branchbyte2 The unsigned bytes branchbyte1 and branchbyte2 are used to construct a signed 16-bit branchoffset, where branchoffset is (branchbyte1 << 8) | branchbyte2. Execution proceeds at that offset from the address of the opcode of this goto instruction. The target address must be that of an opcode of an instruction within the method that contains this goto instruction. goto is 0xa7, and it should be followed by 2 bytes that denote the branch location, making the instruction 3 bytes wide. Your code ignores this, disassembling 1 byte, then treating the next 2 bytes as valid instructions, which they aren't.
Your program is outputting every byte as-if they are bytecode instructions, ignoring the fact that many instructions have parameters, so they are multi-byte instructions. E.g. your program is incorrectly outputting the constructor as follows: 2a: aload_0 b7: invokespecial 00: nop 01: aconst_null b1: return If you run javap -c test_1.class, you will however see: 0: aload_0 1: invokespecial #1 // Method java/lang/Object."<init>":()V 4: return The number before the colon is the offset, not the bytecode. As you can see, offsets 2 and 3 are missing, because the invokespecial instruction uses 2 bytes for parameters, which is documented: Format invokespecial indexbyte1 indexbyte2 Description The unsigned indexbyte1 and indexbyte2 are used to construct an index into the run-time constant pool of the current class (§2.6), where the value of the index is (indexbyte1 << 8) | indexbyte2. With the 2 bytes being 00 and 01, index is 1, so the bytecode instruction is as javap showed: invokespecial #1 If you then look at the constant pool output, you'll see that constant #1 is a methodref to the Object no-arg constructor. Your specific question is related to bytecodes a7 ff e2, which is not 3 instructions, but the 3-byte instruction for goto: Format goto branchbyte1 branchbyte2 Description The unsigned bytes branchbyte1 and branchbyte2 are used to construct a signed 16-bit branchoffset, where branchoffset is (branchbyte1 << 8) | branchbyte2. Meaning that ff e2 is branchoffset = 0xffe2 = -30, which means that instead of a7: goto ff: impdep2 e2: (null) You program should have printed something like: a7 ff e2: goto -30
Byte code difference in #-values after change Ant to Maven
I changed the compilation of a project from Ant to Maven. We still use Java 1.7.0_80. The ByteCode of all classes stayed the same except for a Comparator class. I disassembled the class with javap -c. The only differences are in #-values, e.g.: before: invokevirtual #2 after: invokevirtual #29 What do these #-values mean? Is this a functional difference or just a difference in naming? EDIT: The first method in Bytecode before and after: public de.continentale.kvrl.model.comp.KvRLRechBetragEuroComparator(); Code: 0: aload_0 1: invokespecial #1 // Method java/lang/Object."<init>":()V 4: return public de.continentale.kvrl.model.comp.KvRLRechBetragEuroComparator(); Code: 0: aload_0 1: invokespecial #21 // Method java/lang/Object."<init>":()V 4: return
The #29 refers to an index in the constant table that describes the method being invoked. It would have been better if you had pasted the full output of javap -c, because the comment at the end of the line indicates the actual method descriptor. Example of javap -c on an invocation of an instance method test in class Z: 7: invokevirtual #19 // Method snippet/Z.test:()V You can ignore the # number, as long as the method descriptor in the comment is the same. Why As to the "why" question, it is very likely caused by the debug in the ant and maven compiler task/plugin settings. By default, the maven-compiler-plugin compiles with the debug configuration option set to true, which will attach among other the name of the source file, and thing like line number tables and local variable names. https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html By default, the ant java compiler has this set to false. https://ant.apache.org/manual/Tasks/javac.html To compare and check, set the debug parameter of the Ant Javac task to true and see if that makes the generated .class files the same.
Getting a ClassFormatError in Jasmin
I'm trying to create a program that would print some text using jasmin. This is a piece of the whole code: zfor: 1 iload 3 ; pushes z to stack 2 iload 1 ; pushes i to stack 3 if_icmpge nextfor ; if (z>=i) goto nextfor 4 getstatic java/lang/System/out Ljava/io/PrintStream 5 ldc "O" ; push string constant 6 invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V 7 iinc 3 1 ; z++ 8 goto zfor after compiling, i'm getting this error: Error: A JNI error has occurred, please check your installation and try again. Exception in thread "main" java.lang.ClassFormatError: Field "out" in class examples/Triangle has illegal signature "Ljava/io/Printstream" it seems like the error is somewhere in line 4, since, after making that line as a comment i'm not getting any errors.
Add ; to the signature: Ljava/io/PrintStream;
AEM performance issues (slow memory leak) org.slf4j.helpers.BasicMarker and org.slf4j.helpers.BasicMarkerFactory
I am currently using the Adobe Experience Manager (AEM also known as CQ) for a Client's site (Java platform). It uses OpenJDK: java version "1.7.0_65" OpenJDK Runtime Environment (rhel-2.5.1.2.el6_5-x86_64 u65-b17) OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode) It is running on Rackspace with the following: vCPU: 4 Memory: 16GB Guest OS: Red Hat Enterprise Linux 6 (64-bit) Since it has been in production I have been experiencing very slow performance on the part of the application. It goes like this I launch the app, everything is smooth then 7 to 10 days later the CPU usage spikes to 400% (~4000 users/day hit the site). The site becomes exceptionally slow and never becomes an OOM exception. Since I am a novice at Java Memory management I started reading about how it works and found tools like jstat and jmap. When the system was overwhelmed the second time around, I got a heap dump and dug into it. It all seems to be pointing out at org.slf4j.helpers.BasicMarkerFactory and org.slf4j.helpers.BasicMarker as when I analyze it with MAT eclipse I see that the biggest retained object by retained size is: org.slf4j.helpers.BasicMarkerFactory # 0x6021a4f00 Shallow Size: 16 B Retained Size: 6.8 GB and When I run a Leak suspects report I get the following result: Description One instance of "org.slf4j.helpers.BasicMarkerFactory" loaded by "org.apache.felix.framework.BundleWiringImpl$BundleClassLoaderJava5 # 0x60219a878" occupies 7,263,024,848 (96.71%) bytes. The memory is accumulated in one instance of "java.util.concurrent.ConcurrentHashMap$Segment[]" loaded by "<system class loader>". Keywords java.util.concurrent.ConcurrentHashMap$Segment[] org.apache.felix.framework.BundleWiringImpl$BundleClassLoaderJava5 # 0x60219a878 org.slf4j.helpers.BasicMarkerFactory and Shortest Paths To the Accumulation Point Class Name Shallow Heap Retained Heap java.util.concurrent.ConcurrentHashMap$Segment[16] # 0x6021a4f40 80 7,263,024,784 . ... segments java.util.concurrent.ConcurrentHashMap # 0x6021a4f10 48 7,263,024,832 . ... markerMap org.slf4j.helpers.BasicMarkerFactory # 0x6021a4f00 16 7,263,024,848 . ... markerFactory org.slf4j.impl.StaticMarkerBinder # 0x6021d3970 16 16 . ... SINGLETON class org.slf4j.impl.StaticMarkerBinder # 0x6021d38f8 8 24 . ... [328] java.lang.Object[640] # 0x6021d2ee8 2,576 9,592 . ... elementData java.util.Vector # 0x6021d0fe0 32 9,624 . ... classes org.apache.felix.framework.BundleWiringImpl$ BundleClassLoaderJava5 # 0x6021c32e0 96 26,888 . ... <classloader> class ch.qos.logback.classic.Logger # 0x600be4310 16 16 . . . ...<class> ch.qos.logback.classic.Logger # 0x600282a78 48 48 . ... <Java Local> java.lang.Thread # 0x60077b450 pool-9-thread-1 Thread 104 3,344 . ... <class> ch.qos.logback.classic.Logger # 0x60025b850 48 48 . ... <class> ch.qos.logback.classic.Logger # 0x604b0a708 48 48 . ... <class> ch.qos.logback.classic.Logger # 0x604b0a6d8 48 48 . ... <class> ch.qos.logback.classic.Logger # 0x6049debe0 48 48 . ... <class> ch.qos.logback.classic.Logger # 0x604535228 48 48 . ... <class> ch.qos.logback.classic.Logger # 0x604124248 48 48 Also when I run: $ sudo -u aem jmap -histo PID num #instances #bytes class name ---------------------------------------------- 1: 11460084 950827248 [C 2: 10740160 257763840 java.lang.String 3: 7681495 245807840 java.util.concurrent.ConcurrentHashMap$HashEntry 4: 7563527 181524648 org.slf4j.helpers.BasicMarker 5: 217007 173568376 [I 6: 177602 158721184 [B 7: 60611 69739136 [Ljava.util.concurrent.ConcurrentHashMap$HashEntry; 8: 1147481 69348496 [Ljava.lang.Object; 9: 1797107 43130568 org.apache.jackrabbit.oak.plugins.segment.RecordId 10: 208912 33824544 <constMethodKlass> 11: 570143 31928008 org.mozilla.javascript.ast.Name 12: 22350 27643920 <constantPoolKlass> 13: 208912 26752544 <methodKlass> 14: 821217 26278944 java.util.UUID 15: 793800 25401600 java.util.HashMap$Entry 16: 532946 21317840 org.mozilla.javascript.Node 17: 792296 19015104 java.lang.Long 18: 191294 18335600 [Ljava.util.HashMap$Entry; 19: 22350 16133328 <instanceKlassKlass> 20: 173883 15855152 [Ljava.lang.String; 21: 635690 15256560 org.apache.sling.engine.impl.request.SlingRequestProgressTracker$TrackingEntry 22: 18509 14662848 <constantPoolCacheKlass> 23: 911112 14577792 java.lang.Integer 24: 255426 14303856 org.apache.jackrabbit.oak.plugins.segment.SegmentNodeBuilder 25: 519324 12463776 java.util.ArrayList 26: 254643 12222864 org.apache.jackrabbit.oak.core.SecureNodeBuilder 27: 137703 11016240 java.lang.reflect.Method 28: 312116 9987712 org.apache.jackrabbit.oak.plugins.segment.SegmentNodeState 29: 19236 9828448 [Lorg.apache.jackrabbit.oak.plugins.segment.SegmentId; 30: 242179 9687160 java.util.TreeMap$Entry 31: 197121 9461808 java.util.HashMap 32: 15041 9416328 <methodDataKlass> 33: 387927 9310248 org.apache.jackrabbit.oak.plugins.segment.MapRecord 34: 250049 8001568 org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder$UnconnectedHead 35: 248586 7954752 org.apache.jackrabbit.oak.core.MutableTree 36: 107865 7948112 [S 37: 191950 7678000 java.util.LinkedHashMap$Entry 38: 102212 6541568 org.mozilla.javascript.ast.PropertyGet 39: 37021 6515696 org.mozilla.javascript.ast.FunctionNode 40: 161905 6476200 org.mozilla.javascript.ScriptableObject$Slot ..... 8210: 1 16 org.slf4j.helpers.BasicMarkerFactory I noticed: 4: 7563527 181524648 org.slf4j.helpers.BasicMarker and 8210: 1 16 org.slf4j.helpers.BasicMarkerFactory When I go into the documentation of org.slf4j.helpers.BasicMarkerFacotry I see the following that gets my attention: detachMarker public boolean detachMarker(String name) Description copied from interface: IMarkerFactory Detach an existing marker. Note that after a marker is detached, there might still be "dangling" references to the detached marker. Specified by: detachMarker in interface IMarkerFactory Parameters: name - The name of the marker to detach Returns: whether the marker could be detached or not In particular: Note that after a marker is detached, there might still be "dangling" references to the detached marker. Hopefully someone will be able to help pinpoint the cause of my issues as I am a little lost here ? Has anyone seen this before ? How could I go about troubleshooting this issue furthermore ? Do you agree that org.slf4j.helpers.BasicMarker and org.slf4j.helpers.BasicMarkerFactory seem to be the root cause of my issues ? Is my logging configuration a suspect ? Is this a slow memory leak or a performance tuning issue (in my opinion seem like the memory leaks slowly over a week or so) ? Any advice is welcomed. Thanks in advance.
Are you using the MarkerFactory to create your Marker instances ? Sounds obvious that theConcurrentHashMap holding your Marker is ever growing. That would be the case for e.g. if you create a marker with each time a different name (for e.g. using a date). Marker are to mark you log so you can filter them accordingly. You may want to post the part of the code where you are creating your marker.
Java Bytecode Subroutines - Cannot load return address
I have been trying to write some Java bytecode and assemble it using Jasmin. I am trying to get my head around subroutines, and am not sure why I obtain the following error message when running my program: >java -jar jasmin.jar test.j Generated: test.class >java test Exception in thread "main" java.lang.VerifyError: (class: test, method: main signature: ([Ljava/lang/String;)V) Cannot load return address from register 0 Could not find the main class: test. Program will exit. Here's the bytecode in test.j: .class public test .super java/lang/Object .method public static main([Ljava/lang/String;)V .limit stack 6 .limit locals 5 jsr a ;Jump to subroutine 'a', pushing return address on operand stack return ;Exit the program a: astore_0 ;Store the return address in variable 0 aload_0 ;Save the address onto the stack as address will be overwritten in 'b' jsr b ;Jump to subroutine 'b', pushing return address on operand stack astore_0 ;Store the address that was on the stack back into variable 0 ret 0 ;Return to just after "jsr a" b: astore_0 ;Store return address in variable 0 ret 0 ;Return to address stored in 0 (ie back to just after the jump in 'a') .end method I haven't had any problems with jumping to a single subroutine, but it seems as though something is going wrong when jumping to a subroutine from within a subroutine. Any insight as to why this is failing would be much appreciated!
You can't load an address type value into any register, you can only store it and then ret instruction can retrieve it from there. Java Virtual Machine Specification: ret jsr