jvm-hotspot

How can I know whether a Java object is in tenure or eden space from heap dump

百般思念 提交于 2019-12-08 16:41:09
问题 I have a Hotspot JVM heap dump and I tried to find out whether an object is live in tenure space, eden space, or survivor space, but I could not. Appreciate if someone can help me. 回答1: I don't think you can. From this forum post, sorry, bad news, the heap dump neither contains the info about the space the object is in Looking at the contents of the java heap dumps from this page seems to confirm that the heap dump does not contain generation info, HEAP DUMP BEGIN (39793 objects, 2628264

What's the effect of -server option for the HotSpot JVM?

时光毁灭记忆、已成空白 提交于 2019-12-08 12:02:09
问题 I cannot find any clear documentation about the exact effect of passing the -server option when launching a sun HotSpot JVM. Can anybody sum-up what it does? 回答1: With -server the JVM will compile hotspots (i.e. parts of the code that are often executed) more aggressively, and as a consequence the compiler will take more time to do so. This is not a problem since you only use this option when your processes run for extended periods of time (e.g. on a server). When using -client, the

Class.getConstantPool()

一世执手 提交于 2019-12-08 05:06:22
问题 If you decompile the java.lang.Class class in java from the rt.jar library you will notice there is a native method declaration: native ConstantPool getConstantPool(); I played a while ago with class decompilation using Sun's .class file specification and I was able to obtain the constant pool record from each .class file. But that was actually decompiling classes. It's just that I was surprised to see this signature in the Class class. So what I did is I wrote a small piece of code in the

Can java inline a large method if the most of it would be dead code at the call site?

 ̄綄美尐妖づ 提交于 2019-12-07 17:49:22
问题 I know that one of the criteria that Java HotSpot uses to decide whether a method is worth inlining is how large it the method is. On one hand, this seems sensible: if the method is large, in-lining leads to code bloat and the method would take so long to execute that the call overhead is trivial. The trouble with this logic is that it might turn out that AFTER you decide to inline, it becomes clear that for this particular call-site, most of the method is dead code. For instance, the method

What is vmovdqu doing here?

﹥>﹥吖頭↗ 提交于 2019-12-07 14:32:53
问题 I have a Java loop that looks like this: public void testMethod() { int[] nums = new int[10]; for (int i = 0; i < nums.length; i++) { nums[i] = 0x42; } } The assembly I get is this: 0x00000001296ac845: cmp %r10d,%ebp 0x00000001296ac848: jae 0x00000001296ac8b4 0x00000001296ac84a: movl $0x42,0x10(%rbx,%rbp,4) 0x00000001296ac852: inc %ebp 0x00000001296ac854: cmp %r11d,%ebp 0x00000001296ac857: jl 0x00000001296ac845 0x00000001296ac859: mov %r10d,%r8d 0x00000001296ac85c: add $0xfffffffd,%r8d

Change JVM JIT Options at runtime

﹥>﹥吖頭↗ 提交于 2019-12-07 07:47:57
问题 Is it possible to change options and/or modes of Java JVM (JIT) at runtime? E.g. change XX:CompileThreshold, or even switch between interpreted and compiled code ( -Xcomp vs -Xint ). My JVM is from OpenJDK (1.6), Hotspot or Zero/Shark 回答1: You cannot change the JVM mode at runtime, however you can modify some flags without restarting the JVM. Just connect to the JVM using a JMX client (like VisualVM) and use the operation setVMOption of com.sun.management:type=HotSpotDiagnostic . For instance

Returning two values from Java function efficiently

浪尽此生 提交于 2019-12-06 14:19:17
Does anybody know if there is a way to return two values from Java with (close to) zero overhead? I'm only looking for two values - I have a couple use cases from processing an array of bytes (and need the return value and the next starting position) to trying to return a value with an error code to doing some ugliness with fixed-point calculations and need the whole and fractional part. I'm not below some really ugly hacks. The function is small and Hotspot happily inlines it. So now, I just need to get Hotspot to basically elide any object creation or bit shifting. If I restrict my returned

Runtime.getRuntime().maxMemory() Calculate Method

此生再无相见时 提交于 2019-12-06 10:09:07
问题 Here is the code: System.out.println("Runtime max: " + mb(Runtime.getRuntime().maxMemory())); MemoryMXBean m = ManagementFactory.getMemoryMXBean(); System.out.println("Non-heap: " + mb(m.getNonHeapMemoryUsage().getMax())); System.out.println("Heap: " + mb(m.getHeapMemoryUsage().getMax())); for (MemoryPoolMXBean mp : ManagementFactory.getMemoryPoolMXBeans()) { System.out.println("Pool: " + mp.getName() + " (type " + mp.getType() + ")" + " = " + mb(mp.getUsage().getMax())); } Run the Code on

Will the JVM ever inline an object's instance variables and methods?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 08:33:23
问题 Suppose I have a very tight inner loop, each iteration of which accesses and mutates a single bookkeeping object that stores some simple data about the algorithm and has simple logic for manipulating it The bookkeeping object is private and final and all of its methods are private, final and @inline. Here's an example (in Scala syntax): object Frobnicate { private class DataRemaining(val start: Int, val end: Int) { @inline private def nextChunk = .... } def frobnicate { // ... val bookkeeper

Can java inline a large method if the most of it would be dead code at the call site?

别来无恙 提交于 2019-12-06 04:06:16
I know that one of the criteria that Java HotSpot uses to decide whether a method is worth inlining is how large it the method is. On one hand, this seems sensible: if the method is large, in-lining leads to code bloat and the method would take so long to execute that the call overhead is trivial. The trouble with this logic is that it might turn out that AFTER you decide to inline, it becomes clear that for this particular call-site, most of the method is dead code. For instance, the method may be a giant switch statement, but most call sites call the method with a compile-time constant, so