Silently Attaching to a JVM

I want to use the Attach API to silently attach to a running JVM - that is through the agentmain() method. By silently, I mean I don't want the target JVM to detect my act of attaching to it. But the problem is, assuming my class name is widely known (say I distribute it as a product to users), the attach api will try to append my class into the system class path. In that case, all the target JVM classes need to do to detect my intruding class is to search for the existence of my classname in the classpath e.g.
try {
Class s=Class.forName("IntrudingClassName");
if (s!=null)
return "intruder detected";
} catch (ClassNotFoundException e) {
return "intruder not found";
Is there any way to prevent my class being visible in the attached JVM's classpath? I tried to rename my attaching class to say, java.awt.Canvas (same as the core system library classes); however, this just make the attach api fails to find the agentmain() method as it probably looked into the core system library's version of the class. I am not sure if renaming my attaching class to one of the target JVM's running class instead of the core system library classes would work or not. But is there any better method, say replacing the ClassLoader returned by the ClassLoader.getSystemClassLoader to my own version.( according to the specification, it is the SystemClassLoader the append the jar to the system class path)

Why on earth do you want to do this?

Similar Messages

  • JNI Calling Java code when attaching to existing JVM

    I've got an Active/X that runs within IE, and also makes JNI calls (via the Invocation API) to Java code. Running within IE means there's already a JVM around, so I attach to it using JNI_GetCreatedJavaVMs
    This is fine. The problem is that I can't use the JNI findClass() to locate my Java classes, because I have no control over the classpath that the JVM is using to locate classes. The only solution I can think of so far is to either add my classes as part of the JVM, OR find out the classpath of the existing JVM (using System.getProperty("java.class.path") and copy my classes into that directory.
    Both solutions look ugly - anyone know of a cleaner way ?
    Mark.

    Toby, thanks for the reply.
    You're welcome.
    I notice from elsewhere on this forum, you're clearly a JNI expert.
    I've been known to work with it a little from time to time. =)
    My code has to work with JDK 1.1 so URLClassLoader is out. Writing my own classloader is fine, but how do I load it in the first place ? Is there something in JNI I've missed ?
    Possibly. Using DefineClass() you can load a class into the virtual machine, given it's byte-code. Now here's the tricky part. First, write your ClassLoader. It will be easiest if it doesn't rely on any other classes other than what is core to the JRE. Once you compile that classloader, you then need to include the bytecode as a resource in your executable/dll. Then, at runtime, you can load that resource, and use DefineClass to class-load it. Once you've class-loaded it, you can use NewObject, GetMethodID, CallXXXMethod, etc... to do the other class loading you need to do.
    Trust me, this really isn't as hard as it might sound.
    God bless,
    -Toby Reyelts
    As always, I recommend you check out the free, open-source JNI toolkit, Jace, at http://jace.reyelts.com/jace.

  • Is there an API to attach a particular JVM with the Firefox browser instance when it comes up?

    I am using Firefox 3.6.x with JRE 6 u10 and above on Linux. I attach the JVM to the Firefox process using the dlopen() and AttachToCurrentThread() calls. The plugins folder within Firefox contains a soft link to the libnpjp2.so shared library from JRE 6. When I bring up the browser instance with no pages loaded, the process information confirms that the JRE is loaded (libjava.so, libjvm.so are present and attached to the firefox process). Now when I open an applet on this firefox instance - the browser crashes.
    It seems that for some reason that the firefox process is oblivious of the already loaded JVM instance and tries to open another instance of the JVM to attach with the applet which causes the crash.
    Is there an API that is exposed by Firefox that can help me load the JVM programmatically within the browser? And if so will this help in avoiding a call to reload the JVM when an applet is opened?

    Can you post the original link you have in Excel. We need to see what the
    full link looks like.

  • Stack size for native thread attaching to JVM

    All:
    I have a native thread (see below, FailoverCallbackThread) that attaches to the JVM and does a Java call through JNI. The stack size for the native thread is 256KB.
    at psiUserStackBangNow+112()@0x20000000007a96d0
    at psiGuessUserStackBounds+320()@0x20000000007a8940
    at psiGuessStackBounds+48()@0x20000000007a8f60
    at psiGetPlatformStackInfo+336()@0x20000000007a9110
    at psiGetStackInfo+160()@0x20000000007a8b40
    at psSetupStackInfo+48()@0x20000000007a5e00
    at vmtiAttachToVMThread+208()@0x20000000007c88b0
    at tsAttachCurrentThread+896()@0x20000000007ca500
    at attachThread+304()@0x2000000000751940
    at genericACFConnectionCallback+400(JdbcOdbc.c:4624)@0x104b1bc10
    at FailoverCallbackThread+512(vocctx.cpp:688)@0x104b8ddc0
    at start_thread+352()@0x20000000001457f0
    at __clone2+208()@0x200000000030b9f0
    This causes stack overflow in Oracle JRockit JVM. (It does not cause overflow with Oracle Sun JDK.) Is there a recommended stack size for this use case for JRockit? Is there a way to compute it roughly?
    Platform Itanium 64 (linux)]
    java version "1.5.0_06"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
    BEA JRockit(R) (build R26.4.0-63-63688-1.5.0_06-20060626-2259-linux-ia64, )
    mp

    How do I found default heap size, stack size for the
    thread, number of threads per jvm/process supported ?The threads is OS, OS install and jvm version specific. That information is also not useful. If you create the maximum number of threads that your application can create you will run out of memory. Threads require memory. And it is unlikely to run very well either.
    The default heap size and stack size are documented in the javadocs that explain the tools that come with the sun jdk.
    and how the above things will vary for each OS and how
    do I found ? Threads vary by OS, and OS install. The others do not (at least not with the sun jvm.)
    If I get "OutOfMemoryError: Unable to create new native thread" Most of the time it indicates a design problem in your code. At the very lease, you should consider using a thread pool instead.
    I found in one forum, in linux you can create maximum
    of 894 threads. Is it true ?Seems high since in linux each thread is a new process, but it could be.

  • Accessing objects from an existing JVM on Windows

    I have a Java class that is running in an existing JVM which is running on local windows workstation. Is there a way I can access any methods or objects from the running Java class and other objects running inside the JVM from C or C++ code using Invocation API?. I know there is a way for us to ATTACH to a JVM that was created from C/C++ but I am looking for a way to access objects from a JVM that was started either as a service or started by other means.

    How did you start the C++ code?
    It is possible to load the c++ dll within your Java code then you may access the c++ code by using native methods out of Java. By calling the c++ method you have the pointer to your Java object and my use it (=> don't forget to use global references).
    If you have started both seperatly C++ in an extra process and Java in an extra process then it can be complicated. Guess that there aren't any easy solution.
    This mean: either you have your Java code loading a dll or you have C++ creating a JVM...

  • Help with JDPA failure on JVM Startup from C++ using JNI_CreateJavaVM

    The short version:
    When I try to start a jvm with the -Xrunjdwp from C++ using JNI_CreateJavaVM and the following settings, it simply crashes. I can run my program just fine when this option is not present.
    JavaVMOption aoOptions[5];     
    aoOptions[0].optionString = m_ustrClassPath.GetStringA();
    aoOptions[1].optionString = "-Xdebug";
    aoOptions[2].optionString = "-Xnoagent";
    aoOptions[3].optionString = "-Djava.compiler=NONE";
    aoOptions[4].optionString = "-Xrunjdwp:transport=dt_socket,address=localhost:8000,server=y,suspend=n";
    I have all the appropriate jar files on the classpath and the DLL's are on the path. I am running 1.4.2. I have also tried dt_shmem and a combination of most of the adjustable paramaters being on/off or not present. Any help would be greatly appreciated!!!
    Thanks,
    Chris
    The long version (or why I want to do this crazy thing):
    I am migrating a product line from Visual Basic/C++/COM to Java. I recently purchased JBuilder 9 with the hope that I could use the attach to running JVM process to debug fully. When I attempted to add the neccessary options, my jvm create dies. I can't get to a point to attach from JBuilder.

    I have finally found a solution...
    Please see this bug: http://developer.java.sun.com/developer/bugParade/bugs/4335526.html
    The bug has not been fixed but a workaround exists. Please see the bug for full information, the short answer is this.
    When using the below settings, the -Xrun option is causing an Access Exception crash within jvm.dll. This seems to be because the -Xrun string is modified within jvm.dll.
    JavaVMOption aoOptions[5];
    aoOptions[0].optionString = m_ustrClassPath.GetStringA();
    aoOptions[1].optionString = "-Xdebug";
    aoOptions[2].optionString = "-Xnoagent";
    aoOptions[3].optionString = "-Djava.compiler=NONE";
    aoOptions[4].optionString = "-Xrunjdwp:transport=dt_socket,address=localhost:8000,server=y,suspend=n";
    The solution that worked for me was to use strdup as indicated in the workaround for the bug.
    JavaVMOption aoOptions[5];     
    pTempStrOption = m_ustrClassPath.GetStringA();
    aoOptions[0].optionString = strdup(pTempStrOption);
    aoOptions[1].optionString = strdup("-Xdebug");
    aoOptions[2].optionString = strdup("-Xnoagent");
    aoOptions[3].optionString = strdup("-Djava.compiler=NONE");
    aoOptions[4].optionString = strdup("-Xrunjdwp:transport=dt_socket,address=3333,server=y");
    This has caused me grief for months. It was not easy to locate in the bug database. It existed in 1.3 and still exists as of 1.4.2. I am not sure about the 1.5 beta.

  • What's an easy way to start an agent in current JVM after it is running?

    I want to be able to start a Java agent in the current JVM. I cannot control how the JVM is started, therefore I cannot specify -javaagent on the java command.
    I know the attach API lets me attach to a JVM if I have its PID. But unless I have missed something there is no platform-independent way of getting the current PID to pass to VirtualMachine.attach.
    I have run an experiment that seems to work in which my code:
    1. Uses File.createTempFile to create a unique temp file.
    2. Sets a system property to the temp file's path.
    3. Uses VirtualMachine.list to get VirtualMachineDescriptors for all known VMs.
    4. For each VMD:
    4a. Attaches to the VM using theVirtualMachineDescriptor.id().
    4b. Retrieves the system properties from the VM.
    4c. Searches the Properties for the system property name and, if found, checks its value.
    4d. If they match, the VirtualMachine in the loop is the currently-running VM one and do what I want.
    4e. If they do not match, detach from that VM and check the next VM in the list.
    This is terribly cumbersome, plus it requires that tools.jar be available.
    Is there no simpler way to establish an agent in the current VM? Or to attach to the current VM?
    (I also tried passing an empty string and "-1" as the PID to VirtualMachine.attach with no luck. Not that I expected those to work, given that the JavaDoc said nothing about these special values.)
    Thanks.
    - Tim
    Edited slightly for clarity by: tjquinn on Jan 23, 2008 4:26 PM

    Thanks a lot for the pointers, Alan.
    The real underlying difficulty I didn't mention earlier is that Java Web Start is launching the applications of interest here. The JNLP spec currently provides no way of indicating an agent in the JNLP document, the -javaagent command line option is not one of the ones that Java Web Start chooses to handle (for the obvious security reasons I presume), and JNLP provides no mechanism for defining environment variables. So perhaps this is a lost cause until the JNLP spec and/or the Java Web Start implementation evolve.
    (There is a bug from years ago filed against Java Web Start asking for the equivalent of the -javaagent feature.)
    My questions in this thread reflect my (unsuccessful) attempts at side-stepping those Java Web Start restrictions.
    It does seem to me that the management enhancements over the past several Java SE versions have done a nice job of allowing different JVMs to manage and monitor each other. The special case of a JVM managing or monitoring itself is not so easy. In my particular case I don't really need the ability to attach to a different JVM. If I could just get the VirtualMachine instance for the current JVM (without needing tools.jar) I'd be done and on my way.
    Is that worth an RFE against management/monitoring do you think?
    - Tim

  • Calling JVM from C native code

    I'd like to call JVM from C native call.
    I work in W2000 enviroment using GCC Cygnus compiler.
    I followed JNI instructions.
    I read in this forum there was a change in JDK, and instead of attaching javai.dll, jvm.dll must be attached.
    Then I made a test using invoke.c example from JDK.
    I built following .bat file:
    gcc -c invoke.c -Id:\jdk1.3.1\include -Id:\jdk1.3.1\include\win32
    DLLTOOL dllname jvm.dll def libjvm.def --output-lib d:\jdk1.3.1\jre\bin\classic\libjvm.a
    c++ -o invoke.exe invoke.o -Ld:\jdk1.3.1\jre\bin\classic -ljvm
    with libjvm.def :
    EXPORTS
    imp_JNI_GetDefaultJavaVMInitArgs@4
    imp_JNI_CreateJavaVM@12
    All seems to work fine, and invoke.exe is generated. But when trying to run it, I get a windows message telling me :
    invoke.exe doesn't find the entry point to imp_JNI_CreateJavaVM@12 in jvm.dll.
    What am I going wrong ?
    Any calling convention issue ?
    Thanks in advance. Ignasi Villagrasa.

    Have a look at http://www.xraylith.wisc.edu/~khan/software/gnu-win32/. It has examples of how to use gcc, java JNI on cygwin and should work on all versions of Windows. It has the command line options for using dlltool.

  • Error Running Oracle Apps and Discoverer at the same time

    Hello,
    We are having trouble running Oracle Apps and Discoverer at the same time on certain user's machines. Here are the specifics:
    The user opens Oracle Apps in Internet Explorer. The user then opens Discoverer in another Internet Explorer windows and receives the following error: Runtime Error! Program: C:\Program Files\Internet Explorer\iexplore.exe abnormal program termination
    As a work around, I installed Firefox on those user's machines. These users run Oracle Apps in Internet Explorer and run Discoverer in FireFox. This has solved the problem in 99% of the cases. However, there is one user who is having FireFox using Discoverer freeze when running Oracle Apps in Internet Explorer.
    Can anyone provide any insight on how I can solve these conflict issues so users can run Oracle Apps and Discoverer at the same time?
    Thanks in advance for your help,
    Carlos

    Hi Michael,
    I agree with you completely. It is reccommended to run 10g on a separate physical server unless you have sufficient resources to run on the same server (which even most large clients do not) Even then, I would recommend a separate server.
    I should have put my comment in context :-)
    a.) I was only stating that it was possible
    and
    b.) whether 10g is installed on the same physical server or separate should not affect the client browser crashing issue that was posted.
    I do have an install with EBS11i and Discoverer 10g on the same physical server and it works fine (this is sandbox/ TEST). Most of my large customers have 10g installed on multiple physical servers due to load balancing (capacity).
    I do work for Oracle. I try to help out on the forum when I can, but it is hit or miss :-(
    I would be glad to discuss anything privately.
    As for the issue at hand, I can reproduce the problem and here is what is occuring.
    I have EBS 11i configured with Jiniator 1.3.24
    I have Discoverer 10g configured with Sun Java plugin 1.4.2_06
    1. If you launch EBS 11i apps and a form with MS IE, then the browser launches the form using Jiniator JRE 1.3.xx (whatever you have configured in AutoConfig for EBS11i)
    2. Next, the user navigates to EBS 11i SSWA and launches a Discoverer workbook.
    What occurs is a child IEXPLORE.exe process is spawned from the parent IEXPLORE.exe process and Discoveer Plus is launched. The parent iexplore.exe process will be attached to the Jiniator JVM. Now if Discoverer is configured with
    a.) Sun Java Plugin or
    b.)a version of Jinitiator that is a different version from what EBS 11i is configured with
    then you may get this conflict.
    It really is an MS IE/JRE conflict with Jinitiator and Sun Java Plugi and the way the broswers attaches to the JVM (IMHO) as this behaviour could be reproduced with other non-oracle java applets.
    You can workaround the situation by:
    a. configure EBS11i and Discoverer to use the same version of Jiniator 1.3.xx
    b. educate the users to open one MS IE browser to connect to EBS11i and then open a second MS IE browser to login to EBS11i SSWA or Discoverer 10g Plus directly to launch workbooks. They need to to this by clicking on the icon and not using File >> New browser. Clicking on the icon will spawn a new parent iexplore.exe process that can attach to a second/different JVM. File >> New Window will spawan a child of the parent.
    c. As you did use two browser versions. MS IE for EBS11 connection and FireFox for Disocverer 10g connection.
    I would choose optoin b, so that you can use Sun Java Plugin with Discoverer.
    Open to any comments. I hope that helps you workaround the problem. The ideal solution is to have EBS 11i use/cerified with the 1.4 or 1.5 JRE. In poking around, I see there is a related post to this on one of Oracle's EBS 11i Product Managers Blog.
    See:
    http://blogs.oracle.com/schan/2006/04/18#a23

  • JNI native threads causing JRE to fail to shut down?

    Hello,
    I am using JNI to communicate with a COM object. I am reasonably certain at this point that my JNI code is handling this properly and the third party COM library is releasing the object in question. We allocate and release hundreds of these objects and we aren't observing any memory leaks. Likewise in our handling of events we receive from the COM object. We attach the thread to Java, deliver the event, and then detach the thread from Java, with very careful error handling around the event delivery to ensure that whatever else happens the detach gets called. This code is very robust and stable in operation and has been working at load in the field for over a year now without any customer problems in the JNI area.
    However, since day one, when I go to shut down the application, the JNI isn't winding down properly. As it happens, since the JRE is running a Tomcat, driven by a wrapper service, the wrapper eventually gives up waiting and shoots the JRE in the head, but the user experience of stopping the wrapper service is ugly and we'd like to clean that up. The JNI code, of course, runs as shared code in the Tomcat.
    It is possible that the third-party library, which does network communications, is keeping a thread pool for use with any of the COM objects even after all COM objects are released. This would be experienced as a one-time hit when the first object is allocated and not as a continual leak, so we'd be unlikely to notice it otherwise.
    Will native non-Java threads running in the JRE but not allocated by the JRE itself cause the JRE to hang on until they've spontaneously decided to clean themselves up? Threads that have never been attached to the JVM? How about threads that were briefly attached to the JVM but then detached? Any worse?
    Ralph

    Hi Ralph,
    I will need some more information regarding this issue.
    1. What platform are you on?
    2. Which JRockit version are you running?
    3. If you remove the wrapper service, does JRockit freeze without exiting properly?
    As a general recommendation I would try to upgrade to the latest JRockit version. It can be downloaded from the OTN http://www.oracle.com/technology/software/products/jrockit/index.html
    You may also try some verbose printouts to debug the issue a little further. Try
    -Xverbose:thread=debug,jni=debug
    This might give us some more insight in what is going on.
    Also when JRockit freezes you can output a Java stack trace using our 'jrcmd' tool which you can find in the same folder as the java executable. Run this tool without any parameters and it will output identifiers (numbers) for every running JRockit instance on your machine. Run the same tool again, this time append the identifier you believe is the one running the Tomcat and add the command 'print_threads', ie
    jrcmd <some_id_here> print_threads
    This may show what JRockit is waiting for.
    Cheers,
    /Henrik

  • AttachCurrentThread hangs after a few calls in a Apache2 PHP5 Extension

    Hello everybody,
    I have created a small C Library/API that calls with JNI a simple Java class with a few methods to work with a underlying Java Framework (Carrot2). That JVM/JNI code functions some kind like a bridge between C and Java. In a single-threaded environment I experienced no problems, the complete runtime flow works well, I get no crashes or other strange behaviour.
    Now I have built an PHP5 extension that makes use of that JNI/C code, the extension is built as a class with constructor/destructor and has a few methods that call functions of my C library. The JNI/C side I have 2 data structs, one is for the JVM and its handle (JavaVM) as well as the Java class name and its path, the jclass object of that class, jvm options, classpath, etc. A second data struct is for the Java environment containing the JNIEnv pointer, the jobject of the Java class and a few more application related variables. The C code consists of JNI functions to work with the Java class to call its methods, a few JNI helper functions and some internal application code and data handling.
    At module initialization (Apache startup) I use the PHP_MINIT and PHP_MSHUTDOWN functions to load and unload (on apache stop) the JVM. The JVM gets created and destroyed at these points.
    I use the PHP constructor (inside the extension) to attach to the JVM, that is AttachCurrentThread with the class constructor, I create and object of the Java class and preload a few Java primitives that I need for my methods later on and after all this I can work with the Java class through JNI. On PHP5 class destruction (also in the extension), I detach from the JVM using 'DetachCurrentThread', free some resources and "delete" the JNIEnv pointer (set it to NULL).
    The JVM data struct (containing the JVM object) is a static global in the PHP5 module since I think there is no need for thread safety. This data is only modified/used in module startup/shutdown. The JNI worker struct (data struct with the JNIEnv pointer and jobject, etc is safely handled by the Zend object store throughout the complete class, so this should be thread-safe. So I do not suspect any problem here.
    Testing the PHP 5 extension with a small PHP5 script using that PHP class and a few methods in Apache debug mode (that is the -X switch for just one worker process) works like a charm, no problems, crashes or misbehaving situations, not up to now with my testing though. But running Apache in regular mode with multiple processes, I run in to problems. One major problem is, after a few reloads of the php script using the extension class (lets say 10-15 reloads; The request is handled by the same apache child process) the `AttachCurrentThread' call hangs and the child process remains in that state. Continuing reloading the script a new child process answers and also here, after 10-15 reloads of the script, I get the same problem. So I am not sure what is really happening here nor I do not know how to solve that issue. Is that a signal problem (I read, that there can be signal mask issues and the JVM hangs when a new thread tries to attach to it, for example, the Jakarta Tomcat JK JNI worker uses a signal hack because of this problem. But that does not help me.
    Or is there some problem with the multi-threading itself (since the JVM is multithreaded too)? Another problem is, besides that hanging thread attach, that the processing sometimes stops in middle of a java call (I have one method that insert data (calling a add method in a for loop) with JNI into a Java list on the Java class side, there it can stop in middle of the insertion process.
    So, for now, I have no idea how to continue. Like said, in a single threaded environment, as a process, the application runs fine without a flaw.
    Some details of my development machines: Ubuntu Lucic 10.04 LTS (also another Ubuntu 8 LTS), Apache2 MPM Worker (multithreaded model) and also on another machine the prefork version, Java JRE 6.0.22, PHP 5.2.16 (compiled from source).
    So any hints that can help me proceeding the development of this module for PHP would be great. Any help is appreciated. If there are questions or some unclear points, please let me know.
    Andreas

    jschell wrote:
    847069 wrote:
    I use the PHP constructor (inside the extension) to attach to the JVM, that is AttachCurrentThread with the class constructor, I create and object of the Java class and preload a few Java primitives that I need for my methods later on and after all this I can work with the Java class through JNI. On PHP5 class destruction (also in the extension), I detach from the JVM using 'DetachCurrentThread', free some resources and "delete" the JNIEnv pointer (set it to NULL).
    That is unclear.
    I presume that you have a PHP class which is making JNI calls.
    Presumably you have a single thread in the caller of the PHP class, specifically a single method, which creates the PHP class, interacts with it, and then destroys it.
    Yes, programming PHP5 extensions in C or C++ let you implement a class or just flat functions that can be used in the PHP scripting language. I implemented a class. So my constructor attaches to the (already at Apache/Module startup created JVM). After that, I can use the methods I have implemented to use the carrot2 framework. To communicate with the Carrot2 library, I have written a simple Java Class containing static functions for adding documents, executing clustering algorithms and receiving the search results, so all pretty straightforward I think. When the PHP script exists (request finished) then the class destructor is called (also implemented in my PHP5 extension) to detach from the JVM and make some cleanup. This is generally how things work.
    Most problems with JNI is caused by pointer problems or misusing the API (like not handling exceptions correctly.)
    Other than that the Sun VM has a command line option that reports useful information when using JNI.I can compile and run my JNI code with some test data from command line and I pass to the JVM some debugging parameters (such as -Xcheck:jni, -verbose:jni and Xint) for testing and debugging. I get no exceptions, errors or warnings. Everything is executed cleanly, I see some JNI/JVM debugging output (such as Dynamic-linking native method messages) along my own debugging output and the program finishes normally. Most JNI calls are wrapped in special macros and I check for exceptions, describe and clear them and act with these situtions (if any), I also added a method to the Java Class where I am able to receive the Java backrace for further investigation and abort execution.
    So for now I am out of ideas. This is why I don't understand these problems within the Apache/PHP process. Like stated above, Apache with one worker "-X" the complete code runs fine, even with consecutive calls all is fine, but then in regular multiprocess mode, I get the above problems like the AttachCurrentThread hangs or the execution of called methods of my Java class (inserting documents to a ArrayList or executing one of the clustering algorithms) hang and I have no other choice but to stop Apache.
    One more thing, I valgrinded my C code as far as possible. It is not possible to valgrind C code that creates and executes a JVM. Valgrind will stop and report "Error occurred during initialization of VM". No wonder though, I do not expect valgrind to execute the JVM beast in its context. The PHP5 version i compiled from source is thread-safe (at least I compiled it with the proper flags for that).
    So any other debugging hints or ideas are welcome.
    Edited by: 847069 on Mar 24, 2011 10:31 PM
    Edited by: 847069 on Mar 24, 2011 10:35 PM

  • Long.parseLong("2") returned 6001

    I ran into a really strange issue where Long.parseLong("2") started returning 6001. Here is what happened:
    - This happened on windows 7 - 64 bit OS and in an application running on the weblogic server - v10.3.2. Weblogic was set to use jdk160_14_R27.6.5-32 that comes along with it.
    - When this started happening, I debugged the server using eclipse and entered the expression Long.parseLong("2") in the eclipse-debug expression window. This itself was returning 6001.
    - Even Long.valueOf("2") returned 6001.
    - Other values - like Long.parseLong("1"), Long.parseLong("3"), Long.parseLong("4"), Long.parseLong("8"), etc were fine.
    - I tried giving a radix of 10, etc but nothing helped
    I suspect there was some corruption in the JVM due to which the representation of 2 got screwed.
    Do note 1 thing, this started happening on a morning when I had resumed the machine from a hibernation that I had done the previous night.
    It so happened that when I had hibernated the machine the previous night, the debugger was attached to the JVM and thats the state the machine was hibernated in.
    I have done this many times on previous occasions but never came across any issues. I am not sure if this could be the cause of the issue.
    I restarted the server and all was well after that.
    Anyone having any clue what could have happened here ?

    EJP wrote:
    Well an application couldn't actually do that without a hardware fault.Not sure what scenario you are referring to.
    But one application can certainly mess with the application space of another on any modern desktop OS.
    For example the following windows method.
    http://msdn.microsoft.com/en-us/library/windows/desktop/ms681674%28v=vs.85%29.aspx
    And if it does it incorrectly then it would cause some really odd error in the target app.

  • Does CallStaticVoidMethod return inmediately?

    I'm writing a Window application which has to invoke the JVM. The routine is more or lees like this:
    int InvokeJavaVirtualMachine()
        char sJRERuntimeLib[512];
        HMODULE hModule;
        p_JNI_GetDefaultJavaVMInitArgs p_JNI_GetDefaultJavaVMInitArgs_function;
        p_JNI_CreateJavaVM p_JNI_CreateJavaVM_function;
        JavaVM* javaVM;
        JNIEnv* jniEnv;
        JavaVMInitArgs javaVMInitArgs;
        JavaVMOption javaVMOptions[1];
        jint jintRes;
        jclass jclassString;
        jclass jclassMainClass;
        jmethodID jmethodIDMain;
        jstring jstringMainParameter;
        jobjectArray jobjectArrayArgs;
        int iReturnCode = 0;
        if (GetJRERuntimeLib("1.4", sJRERuntimeLib)!=0) {
            iReturnCode = -1;
            goto invokejavavirtualmachine_error;
        hModule = LoadLibrary(sJRERuntimeLib);
        if (hModule==NULL) {
            iReturnCode = -2;
            goto invokejavavirtualmachine_error;
        p_JNI_GetDefaultJavaVMInitArgs_function = (p_JNI_GetDefaultJavaVMInitArgs)GetProcAddress(hModule, "JNI_GetDefaultJavaVMInitArgs");
        if (p_JNI_GetDefaultJavaVMInitArgs_function==NULL) {
            iReturnCode = -3;
            goto invokejavavirtualmachine_error;
        p_JNI_CreateJavaVM_function = (p_JNI_CreateJavaVM)GetProcAddress(hModule, "JNI_CreateJavaVM");
        if (p_JNI_CreateJavaVM_function==NULL) {
            iReturnCode = -4;
            goto invokejavavirtualmachine_error;
        javaVMOptions[0].optionString = USER_CLASSPATH;
        javaVMInitArgs.version = JNI_VERSION_1_2;
        javaVMInitArgs.options = javaVMOptions;
        javaVMInitArgs.nOptions = 1;
        javaVMInitArgs.ignoreUnrecognized = JNI_TRUE;
        jintRes = (p_JNI_CreateJavaVM_function)(&javaVM, (void**)&jniEnv, &javaVMInitArgs);
        if (jintRes<0) {
            iReturnCode = -5;
            goto invokejavavirtualmachine_error;
        jclassMainClass = (*jniEnv)->FindClass(jniEnv, "JApp");
        if (jclassMainClass==NULL) {
            iReturnCode = -6;
            goto invokejavavirtualmachine_error;
        jmethodIDMain = (*jniEnv)->GetStaticMethodID(jniEnv, jclassMainClass, "main", "([Ljava/lang/String;)V");
        if (jmethodIDMain == NULL) {
            iReturnCode = -7;
            goto invokejavavirtualmachine_error;
        jstringMainParameter = (*jniEnv)->NewStringUTF(jniEnv, " from C!");
        if (jstringMainParameter == NULL) {
            iReturnCode = -8;
            goto invokejavavirtualmachine_error;
        jclassString = (*jniEnv)->FindClass(jniEnv, "java/lang/String");
        if (jclassString==NULL) {
            iReturnCode = -9;
            goto invokejavavirtualmachine_error;
        jobjectArrayArgs = (*jniEnv)->NewObjectArray(jniEnv, 1, jclassString, jstringMainParameter);
        (*jniEnv)->CallStaticVoidMethod(jniEnv, jclassMainClass, jmethodIDMain, jobjectArrayArgs);
        invokejavavirtualmachine_error:
            if ((*jniEnv)->ExceptionOccurred(jniEnv)) {
                (*jniEnv)->ExceptionDescribe(jniEnv);
           if (javaVM!=NULL && (*javaVM)!=NULL) (*javaVM)->DestroyJavaVM(javaVM);
            if (hModule!=NULL) FreeLibrary(hModule);
            return iReturnCode;
    }Everything seems to work fine but CallStaticVoidMethod doesn't wait for the Java application to end. It returns inmediately. Is this normal?
    Besides when I clic on the close button in the Java application, the Window application whick invoked the Java application is closed too. Is this normal?
    Any help would be welcomed. Thanks.

    I am trying to learn JNI myself so if I havesomething
    wrong here, please correct me.
    1) To prevent your C/C++ application from exitingwhen
    you close your java app, try set the default close
    action in your java class
    "setDefaultCloseOperation(DISPOSE_ON_CLOSE);" That
    seemed to work for me.If you call System.exit() the app will close
    regardless of this (presuming that you have not set a
    security manager.
    2) I have also noticed that once the main is calledin
    the java class the GUI is started and the main
    completes right away. As suggested above, I addedthe
    System.Out. However, the Gui stays open until I
    select close. The C program waits at DestroyJavaVM
    until I close the GUI. As a test, I commented outthe
    DestroyJavaVM and it caused my GUI to flash onscreen
    (open and close). I believe the DestroyJavaVM causes
    the C program to wait until the GUI thread has
    completed. My problem is that I cannot call the GUIa
    second time from with the same C program if needed
    because I cannot recreate the javaVM afterdestroying
    it. Hope this help a bit.Items....
    - Once you create the Sun JVM once, then you can
    neither destroy it nor recreate it. There is only one
    for the entire life of the application.
    - When your C app exited, after commenting out
    DestroyJavaVM did you call the C method 'exit' or some
    variant?1) Instead of using System.ex.t(0), I used "frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);". This prevented my C program from terminating when I closed the java GUI..
    2) When I commented out DestroyJavaVM, I saw the same bahavior as above. My java GUI appeared as though it didn't start. As suggested above, I added print statements and I saw that my class was bing called. With the DestroyJavaVM in place, the program would wait for me to close the window.
    3) I am still experiencing issues creating or attaching to the JVM a second time from within the same C program. I have a C program that calls a function to Create the JVM and launch the GUI. When I am finished withe the GUI, I return to my program. If I call the function again, I cannot create the JVM. Prior to creating it, I check to see if it exists and it doesn't.

  • JPDA 1.5 Sun Connectors

    Hello,
    I'm trying to use the connectors described in http://java.sun.com/j2se/1.5.0/docs/guide/jpda/conninv.html
    Namly I'd like to try these connectors:
    SA Core Attaching Connector: sun.jvm.hotspot.jdi.SACoreAttachingConnector
    SA PID Attaching Connector: sun.jvm.hotspot.jdi.SAPIDAttachingConnector
    SA Debug Server Attaching Connector: sun.jvm.hotspot.jdi.SADebugServerAttachingConnector
    But don't see them returned as available connectors. Do I need a supplemental library or anything else? I'm using SunOS 5.9 with the jre and jdk posted as of 9/13/2005.
    Thanks

    Everything is in jdk5.0. You can check which JDI Connectors are available by doing this:
    jdb -listconnectorsYou should see 3 Connectors name sun.jvm.hotspot..jdi.SA<something>. To test that you can use them just start an application and get its pid. Then try:
    jdb -connect sun.jvm.hotspot.jdi.SAPIDAttachingConnector:pid=<pid>Hope this helps.

  • Can'n attach to JVM using remote debug

    Hello!
    I have some problem. I have create a JVM in C++ program usin JNI. Parameters (reat from conf file):
    -Xdebug
    -Xnoagent
    -Djava.compiler=NONE
    -Xrunjdwp:transport=dt_socket,server=y,address=5007,suspend=n
    -Djava.class.path=jar_1;jar_2;...;jar_n
    JVM is created successfullly. Then I try attach to JVM from IDEA by remote debug with parameters:
    -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5007
    After this I have get the next error: "Unable to open debugger port: java.net.SocketException Connection reset". And my program is shut down. I can't solve this problem. Maybe anybody have some ideas. Thanks.

    Try to debug the next java cod:
    public class TestClass {
    public static void FileCrt(String str)
    DataOutputStream OutStream;
    String sOut;
    sOut = new String(str);
    try
    OutStream = new DataOutputStream( new BufferedOutputStream(new FileOutputStream("c:\\output.txt")));
    OutStream.writeBytes(sOut);
    OutStream.close();
    catch (IOException e)
    e.printStackTrace();
    public static void main(String[] args)
    FileCrt("Test");
    I have created the test.jar and run it by the command:
    java -cp test.jar -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,address=8787,suspend=y testpackage.TestClass
    Then I try to connect to JVM by remote debuger (-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8787) and get exception "Unable to open debugger port java.net.ConnectException". What's the problem?

Maybe you are looking for

  • How can I replace just the corrupt page(s) in the domain file of iWeb using Time Machine?

    I back up with Time Machine and have an extensive elaborate website I created in iWeb '09 over a couple months and publish to a local folder and then upload to my server, but in the last few days I notice certain pages (that I haven't even worked on

  • Safari 5.0.3 Crashing Often Mac OS 10.5.8

    Since upgrading, we're experiencing multiple, random crashes of Safari 5.0.3. We're on a Mac with OX 10.5.8. I've read many posts similar but suggestions are all different. Have cleared Cache and History. That helps, but happens again without fail. H

  • To make a set of records in 1 table to affect another table(dashboards)

    Dear All,         I am using Web Application Designer and making a Dashboard.The situation is the following: I am using 2 tables(table A and table B) and One(1) navigation filter(characteristic for filter : customer).The tables display 2 different qu

  • Re: Express White Paper

    nhijazi @ optimum.org wrote Paul Krinsky comments... .............................................................. I can change the underlying database schema and all my queries still work. ............. This is something that I have a particularly

  • ODT Package Load Failure

    I am running VS.NET 2005 SP1 on XP Pro SP2 and I have Oracle 10gR2 installed on this box. I downloed and installed ODT beta in my 10gR2 Home. Now I ge the following: Package 'Oracle Developer Tools for Visual Studio .NET' has failed to load properly