Heap allocation source code in in jdk(G1GC) [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
I want to understand how java allocates objects in heap. I want to know which parts of the JDK code are triggered when the "new" keyword is used.
How can I define a function that a user can call from the java code and that would implement functionality in JDK source code?
I am aware of the fact that jdk14 uses G1GC as a default garbage collector and G1GC code is present in jdk14/src/hotspot/share/GC/G1 folder but I am unable to follow G1Allocator allocates memory to the user threads(if it does).

Any known implementation will use TLAB (thread local allocation buffer) by default when allocating memory. Without it - the allocation would be much more slower. Though I have not dived into the code too much about this subject, you can start from here, for example.
There is a very good comment in the source code about what happens when a new is requested here. Basically if TLAB can be used (an Object is not bigger than that for example), it will be; otherwise raw malloc for every new will be done.
Regarding G1 here are the mains points of what it does. A general explanation is again in the comments, with a phrase :
All non-TLAB allocation requests should go to mem_allocate()
What mem_allocate does can be started from here.

Related

How to prevent fragmentation in Java? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have an interview and I was ask how to prevent Memory Fragmentation in Java. Can Anyone summarize how Java deal with it ? I've read some documents but it very complicated.
The short answer is: you use a generational garbage collector.
Except that most modern Java implementations1 use a generational collector by default. In other words, you (the programmer) don't need to deal with the problem because it is already dealt with.
The only situation where you might run into fragmentation is if you have mis-tuned the low-pause collector and it has fallen back to doing a "stop the world" full collection. At that point, you might be using a non-compacting collector, and fragmentation might ensue. But the solution there is to adjust the tuning (or the application, or the heap size) to avoid getting into that situation.
If you want more information about garbage collectors work, there are whole textbooks on the subject. And the various Java collectors are covered in depth in various articles and published research papers.
I've read some documents but it very complicated.
Yes, it is. It is hard work becoming an expert.
1 - Some really old Java implementations used primitive mark-sweep collectors. But they are long gone.

Comparing garbage generation in Java [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I'm looking for tools that will let me measure and compare the amount of garbage generated by certain code on the JVM.
I'm aware that tools like YourKit will allow tracking of allocations, but using that tool is very clicky-clicky. (Change code, run with agent, enable tracking, run actual code, take snapshot, etc) It requires a lot of my time/work per iteration.
I'm ideally looking for something like a microbenchmark suite, where it's easy to tweak something and take a new measurement. But instead of measuring speed, I'm interested in measuring allocations.

Can anyone recommend a scriptable Java profiler? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 months ago.
Improve this question
I want to automate our field case analysis.
We sometimes get HPROF files from crashes of our product in production, and look for "typical" problems we know of. Examples:
specific threads creating problems
specific classes filling up the heap
etc.
Currently the HPROF analysis is done manually.
I want to automate that.
Does anyone know of a good Java profiler who allows that? I know Yourkit and JProfiler quite well, and am unaware of such features.
Thank you!
You can find something in VisualVM. It integrates the OQL scripting engine and allows you to persist your own queries so you can easily run them against various heap dumps. However, it is not yet ready for headless analysis.
The OQL implementation in VisualVM is based on the one you can find in jhat and it means that it is javascript based - in addition to "standard" OQL queries it allows you to use plain javascript thus increasing the flexibility many times.
There are few examples of the javascript analysis bundled with VisualVM or you can use the user mailing list to get help.
Cheers!

Which Java static code analyzer is recommendable for creating reports? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I need a static code analyzer for Java that produces an output file about the: relationships of the classes (also inheritance relationships), fields of the classes, method signatures, and method call hierarchies.
The important point is that the analysis data can be (easily) processed by a program. (I need the analysis for a kind of automatic "refactoring" tool for university.)
JastAdd is a good source level analyzer (and much more).
You might prefer to work on bytecode level though. This is simpler, faster, provides all information you requested, works without source (obviously) and with other JVM-based languages. For that, either Soot or ASM is a good choice.
UPDATED
Of course with bytecode you can't really perform source level refactoring (though you could do bytecode modification).
For completeness you may want to combine both approaches.

Is there a good reference on how java executes bytecode? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I'm interested in how java organizes memory and executes code (like what gets put in the stack or the heap), from the start of main, to assigning variables, calling functions, passing parameters, returning values, instantiating objects, etc. Has anyone found a good, beginner-friendly article/reference on it?
The canonical reference is the JVM spec. However, different JVMs can implement the spec in different ways. You can also check out the open source Java platform implementation, OpenJDK.
I don't know exactly how they execute their bytecode, but I found this link describing java's bytecode. I am not sure if it helps, but at least it's something to start on.
Quote:
This article gives you an understanding of Java bytecode that will enable you to be a better programmer. Like a C or C++ compiler translates source code into assembler code, Java compilers translate Java source code into bytecode. Java programmers should take the time to understand what the bytecode is, how it works, and most importantly, what bytecode is being generated by the Java compiler. In some cases, the bytecode generated is not what you expect.

Categories

Resources