javap | javap pastebin for viewing the bytecode of small pieces
kandi X-RAY | javap Summary
kandi X-RAY | javap Summary
javap
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of javap
javap Key Features
javap Examples and Code Snippets
Community Discussions
Trending Discussions on javap
QUESTION
Context
I'm working on a Kotlin program which runs on the JVM and consumes large amounts of memory. While I do trust the garbage collector to (eventually) free memory used by objects which are no longer reachable, I don't trust future maintainers of the project (including my future self) – especially as the project progresses and becomes more evolved - to write the code in a way that makes sure that objects which are no longer needed are indeed unreachable.
So in order to reduce the risk, as part of my testing suite (which is already exhaustive with regards to the logic of the program's functionality) I'm also writing (or trying to write, with different degrees of success) various tests which aim to ensure that references aren't kept to objects which have run their course.
As this is quite difficult to do directly, the technique I'm using in the tests is to employ objects with finalizers, simulate the conditions when they're no longer needed, force garbage collection, and assert the finalizers have indeed run. (Note: my question is not about this technique per se, but if someone has comments or ideas for improvement or can propose alternatives – I'll be interested to hear!).
This generally works well, and can be shown to do the job, e.g. in TDD style: I write naive code which does the job as far as the business logic is concerned but doesn't take care of losing references to old objects, I write a test as described above, I make sure that the test fails, I add code to take care of memory (e.g., in simple cases, set references to null
), and then see that the test passes.
My question
For some reason, my tests don't always work (clarification: I don't mean that they fail non-deterministically; I mean that some of the tests consistently work and some consistently fail). The real examples from the project contain lots of intricate, proprietary details, but I've managed to boil it down to the following minimal example:
...ANSWER
Answered 2022-Mar-15 at 16:20It seems, Kotlin’s println(…)
function has a different behavior than Java’s System.out.println(…)
statement, regarding the order of evaluation.
In Java when you write
QUESTION
When the Java file is a interface, such as TestInterface.java
:
ANSWER
Answered 2022-Mar-17 at 16:26The LocalVariableTable
describes the scope of the variable - the portion of the bytecode in which the variable is accessible.
In a class, the parameter of a non-abstract method has a scope - it's accessible in the whole of the body of the method. Even when the method is "empty", the bytecode still consists of a single return
command.
(There's also the implicit this
variable in an instance method, which is also accessible in the whole body of the method).
In an abstract interface method (i.e. not a default
or static
method), there's no bytecode in which that variable is accessible, because the method has no body, and thus no bytecode. Hence, there's no need for the LocalVariableTable
.
An abstract method (whether in an interface or a class) is just a specification which says "implementors need to provide this". There is no implementation, no body etc.
QUESTION
I have a java web application. Previously I compiled all .java files with JDK 15. But because of some 3rd party apps I had to switch to JDK1.8. Now the problem is when I build the project .class files are not updated. I have checked the version with javap -verbose ClassName.class | findstr "major"
command. Class version is still 59.0. I have already tried steps in this link Why isn't Eclipse updating the classes?. I have also checked JAVA_HOME and Path variable. These are set to JDK1.8 And here are other configurations in eclipse
- JRE System Library is jre1.8
- Project -> Properties -> Builders, Java Builder is checked
- Project -> Properties -> Java Build Path -> Order and Export JRE System Library is checked
- Checked .project file
ANSWER
Answered 2022-Mar-01 at 07:55Make sure in Properties > Project: Java Build Path tab Source the correct output folder(s) are configured.
QUESTION
I'm getting the following error in my java web app (The application launches okay but when I click a button following error occurs). I'm using Tomcat (7.0.109) to run this application.
java.lang.UnsupportedClassVersionError: FileDetailsServlet has been compiled by a more recent
version of the Java Runtime (class file version 59.0), this version of the Java Runtime only
recognizes class file versions up to 52.0 (unable to load class [FileDetailsServlet])
Previously I used Java 15 (class version 59.0). But then I switched to JDK and JRE 1.8.0_311 (class version upto 52.0)because of other 3rd party apps.
Here are some things that I did
- I've checked class version of FileDetailsServlet class using this
javap -verbose FileDetailsServlet| findstr "major"
command. And it shows that version is 51.0 (Java 7). - I've set JDK compliance to 1.8 in eclipse. (Project specific settings)
- After changing JDK I recompiled all the files using JDK 1.8.0_311
- I've checked environment variables. JAVA_HOME is "C:\Program Files\Java\jdk1.8.0_311" JRE_HOME is "C:\Program Files\Java\jre1.8.0_311" and Path is "C:\Program Files\Java\jdk1.8.0_311\bin"
Am I missing anything? I can not go back to Java 15. So is there any way around?
...ANSWER
Answered 2022-Feb-24 at 14:20Check your class path for any "leftovers" from the old system. It looks like you are not inspecting the correct files. Maybe you have the FileDetailsServlet in a wrong version as depencency somewhere, or just in a "standalone" JAR- or WAR-file.
It is also important that Eclipse settings alone will maybe not cover, how the used container serves the servlet, so which technology do you use to run the FileDetailsServlet? That's the crucial point: this thing that you use to run (Tomcat, Jetty, other container, maybe included in a fat WAR or fat JAR file from Sprint Boot or another similar technology) has to use the correct .class file.
As you are using Tomcat as container: You should check the class files inside the folder webapps/appname folder below your tomcat folder (replace appname with the deployment context name) Take care: when you run tomcat from Eclipse this could be somewhere completely different than the installation folder on disk, but I don't have an Eclipse installation ready to check that.
QUESTION
Given a domain class with a parameterless constructor, how do we get a reference to that constructor through the Reflection API?
Consider for example a Student
data class, such as:
ANSWER
Answered 2022-Feb-22 at 12:21The parameterless constructor here only exists in the compiled Java class, and not in your Kotlin code. As far as Kotlin code is concerned, your Student
class has one single constructor, with 2 optional parameters.
The Kotlin reflection API is designed to be platform-independent, so you have to use Java reflection to get the parameter constructor.
If you just want to see if you can call createInstance
safely, you can just check if the class has a single constructor whose parameters are all optional. This is documented:
Creates a new instance of the class, calling a constructor which either has no parameters or all parameters of which are optional. If there are no or many such constructors, an exception is thrown.
QUESTION
How does the new Java 17 type pattern matching switch works under the hood ? As the feature is fairly new, this question doesn't talk about it.
Reminder: for this code to work under Java 17, you need to enable preview features
...ANSWER
Answered 2021-Dec-17 at 10:04What does this typeSwitch()
method do?
The invokeDynamic
instruction (upon first being hit) calls the SwitchBootstraps.typeSwitch()
method. This method then returns what method call should be executed (this is what invokedynamic
generally does).
The last argument of the SwitchBootstraps.typeSwitch()
method (the labels
parameter) is in this case the list of classes in the switch: Number.class
, Enum.class
, String.class
The SwitchBootstraps.typeSwitch()
bootstrap method checks the labels
parameter for correctness and then returns a ConstantCallSite
for the SwitchBootstraps.doTypeSwitch()
method that does the effective handling (i.e. the final execution of the invokeDynamic
instruction).
If you look at what SwitchBootstraps.doTypeSwitch()
does: it iterates over the list of classes and returns the first found match.
What's the purpose of the additional int
passed?
The additional parameter (startIndex
) is needed because of this case:
QUESTION
I have the following class:
...ANSWER
Answered 2021-Nov-03 at 05:27The MethodParameters attribute is used to indicate that parameters are final. https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.24
In order for javac to add this attribute, you need to pass the -parameters
option.
QUESTION
I've Linux Mint 20.2 Cinnamon and I tried to install jenkins
. Detailed steps for installation is as below:
1. Installing java
- installed via apt
ANSWER
Answered 2021-Nov-26 at 06:56jenkins will work with java 8 on mint 20 and 21. If you have different java versions installed on your system then select the jdk8 as default by
QUESTION
I compiled the following method:
...ANSWER
Answered 2021-Nov-02 at 16:39Frontend compilers generate code using simple patterns, and they rely on optimization passes to clean things up. At the point that the x == y
expression is generated, the compiler doesn't "know" that the very next thing is a return statement. It could potentially check this, but that extra step can be handled just as easily with some sort of peephole optimizer.
The benefit of a peephole optimizer is that it can perform cascading optimizations, that is, the result of one optimization can feed into the next one. The code that generated the x == y
expression doesn't really have any way of performing anything more than one optimization step without adding more complexity.
The java compiler used to have an optimization feature, but this was ditched in favor of HotSpot, which can perform even more powerful optimizations. Performing optimizations in the java compiler would slow it down and not really improve things all that much.
QUESTION
The latest Byteman documentation (4.0.16) mentions inner classes, but doesn't mention lambdas. I have a rule looking like:
...ANSWER
Answered 2021-Jul-29 at 14:27Hmm, grabbing the name of the method which implements the body of the lambda out of a javap decompile is a neat trick for identifying the target method. I'm not sure why Byteman is failing to inject coe. Could you report this via the Byteman JIRA instance? I'll investigate and report the outcome on the JIRA. It may actually be possible to make this work.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install javap
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page