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 3 years ago.
Improve this question
I want to mutate a function of a class that is loaded at runtime (it has a bug in it but the project is long gone so i cannot build the binary). What i want to do instead is write a piece of code which will run during the application initialization phase and mutate this function so that it works fine. And simply keep that code around until the replacement is ready.
Having no experience with bytecode modification what library could i use to modify and reload a class at runtime? Specifically i need to replace a throw instruction with a noop instruction (i did this once using hex editor but lost the binary).
Also if you know any tutorial on how to do something like that please share.
I can see many libraries for doing this but i cant know which ones are good/bad do the job...
I think use Java Attach API. Java Attach API is procedure of loading a Java agent into an already running JVM. you can understand the work of javaagents by reading the Java Instrument javadoc. AgentMain help to you.
Agentmain is invoked when an agent is started after the application is already running. Agents started with agentmain can be attached programatically using the Sun tools API (for Sun/Oracle JVMs only -- the method for introducing dynamic agents is implementation-dependent).
This tutorial is useful about java instrumentation.
Related
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 1 year ago.
Improve this question
I have installed CUDA toolkit and download some libraries and exported to my Java project in Netbeans. I never using CUDA before and I am very interesting to learn for my parallel algorithm. My question is:
How I know that my environment is ready to use CUDA? Is there any code to check it in Java?
I need a best practice to implement parallel processing using CUDA in Java? Is there anybody that has simple parallel code that I can use to learn CUDA?
If this is your first time using Cuda, I would highly recommend using the language it was designed for (C/C++). Cuda is only available through java through bindings like JCuda. Using these bindings reduces your example code sample size and support pool, along with adding yet another thing that can go wrong. More complexity, more problems.
If you do insist on using JCuda, here are their official sample projects.
As for testing if your "environment" is ready to use cuda, you can check your cuda version in a command prompt with nvcc -V. If the command is unrecognized, something is wrong.
You can use nvcc to compile the sample projects that should have come with your cuda installation. I believe by default on windows they are located in C:\ProgramData\NVIDIA Corporation\CUDA Samples\.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I have developed apps using Swift as an Agent. It was a simple application that sat in the menubar without any icon on the dock. I would like to create one using Java for some accessibility reasons and I stumbled upon something called a Javaagent.
I couldn't tell if that was what I was looking for and don't want to dive in if its not. If its not, was am I looking for? How do I make an application that doesn't have java popup and just runs on the menubar?
I have looked on many different sites on how to make one but none explaining what it actually is:
example of how to create java instrumentation agent.
Tutorials about javaagents
A java agent is a basically a specialized "component" that you can load into a JVM that runs your "core application". The agent then provides certain "add-on" functionality; functionality that has nothing to do with what your "core application" is doing.
An example would be JRebel. That is a commercial product which comes Java agent; it is loaded into the JVM when starting up your application server. JRebel then allows you later on "hot swap" java classes. Meaning: the JRebel agent knows nothing about the purpose of the code that you are running within your application server; it only exists to change the bytecode of your classes while the JVM is still running.
Long story short: java agents are for INSTRUMENTATION; they have nothing to do with UI applications or accessibility. Thus the answer is: no, java agents is not what you are looking for.
Instead you might turn to frameworks like Swing, JavaFx or Eclipse RTP; which help you creating GUI applications.
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 8 years ago.
Improve this question
I am new in Java programming. I started to learn java recently. Everything works fine and my question is not about a code. I wonder mechanisms, how does JUniut "understand" how to use classes of my program?
Normal program has a flow and it starts from Main()... and what is about JUnit? has it its own flow? Could you please explain it to me?
What is a program on JUnit? what does make it work? netbeans or maven\ant??
Can I create unit tests without maven\ant?
Are there some design patterns? I would like to read about it.
Thanks!!
Every Java application you launch from the command line or from a script will have a main class and it will have a main() method.*
It's just that in the case of JUnit and TestNG these main classes are part of the JUnit and TestNG libraries themselves. That main class in turn is responsible for loading your unit test classes, calling your test methods, then produce a report.
You can download the source code for both libraries and check yourself.
And you can read more on how the Java Virtual Machine starts up here.
*Applets running in a browser appear to have a different entry point, hence the roundabout wording. Though even behind an applet container there is a main() method somewhere.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Is there a way to get textual output of every method invoked by the JVM at runtime?
If you are using Eclipse you can right click the method and choose "Open call hierarchy"
I am not very sure if you are looking for ASM, it is used for analyzing the bytecodes
ASM is an all purpose Java bytecode manipulation and analysis
framework. It can be used to modify existing classes or dynamically
generate classes, directly in binary form. Provided common
transformations and analysis algorithms allow to easily assemble
custom complex transformations and code analysis tools.
ASM offer similar functionality as other bytecode frameworks, but it
is focused on simplicity of use and performance. Because it was
designed and implemented to be as small and as fast as possible, it
makes it very attractive for using in dynamic systems*.
My suggestion is please use debugger to see the whole process is being done.
You can write a CGLIB proxy to trace your methods.
You should use Java profiler tool. There are two well-known profilers - YourKit Java Profiler and JProfiler.
I prefer first one, but you can try both and make your choice.
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 9 years ago.
Improve this question
Can you program external application from Java app.?
I know this is a wierd question but lately I really need to do it.
So the lets say I have "VLC" player or MPC or whatever it is, I want to be able to create a Java/C++ application or whatever it is to control the application such as play the video, pause the video and stuff.
If it possible please let me know and how.
It's certainly possible with VLC. Look here: http://wiki.videolan.org/Java_bindings as well as here: how to control VLC by java
For MPC, I don't know of any resources that can be used to do so. You can at least launch it to the best of my knowledge.
To start (execute) an external application you should use Runtime.getRuntime().exec(params);
or ProcessBuilder class.
http://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html
See Execute external program in java for more information.
To send key strokes to another application you could use the "Robot" class (http://docs.oracle.com/javase/6/docs/api/java/awt/Robot.html).
What is expected is to have access to interface to do these operations, you can get some references from http://caprica.github.io/vlcj/
This is java api for controlling the VLC instance embedded in AWT.
I have found this site that describes how to run external programms from java
http://www.rgagnon.com/javadetails/java-0014.html