Bug in the JIT compiler?

Hi All,
I don't know if I have found a bug in the JIT compiler.
uname -a : Linux kiloo-server2 2.6.26-2-amd64 #1 SMP Fri Mar 27 04:02:59 UTC 2009 x86_64 GNU/Linux
java -version:
java version "1.6.0_12";
Java(TM) SE Runtime Environment (build 1.6.0_12-b04)
Java HotSpot(TM) 64-Bit Server VM (build 11.2-b01, mixed mode)
all in our server module runs fine, until we try to rescale/transform an Image from a rss feed. after this a CompilerThread0 is started and never stops.
it just keeps running at 100% on core0
so right now we are running our server module with the -Xint option.. this is of course not an ideal solution.
Before we moved the server module to linux, it was running on a windows machine (the same code), and there was no JIT compilerthreads problems.
Is there anybody who has experienced anything like this, and is there a workaround to it?
BR
Kristian

Kristian_Iversen wrote:
Hi All,
I don't know if I have found a bug in the JIT compiler.To start with you would need to reduce the code from your "server module" to a very small piece of code that demonstrates the problem.

Similar Messages

  • Reporting a bug for the C++ compiler

    How do I report a bug to Oracle regarding the C++ compiler ? I am using Solaris Studio 12.3.

    Here is an alternative implementation, as a file called has_xxx_test_ex.cpp, also supported by the mpl and tti code for introspecting a class/struct for a class template of a given name taking typename ( or class ) type parameters:
    struct stype { template< typename T > struct xxx {}; };
    typedef void boost_mpl_has_xxx_has_xxx_template_substitute0_tag ;
    template < template < typename U0 > class U >
    struct boost_mpl_has_xxx_has_xxx_template_substitute0
        typedef boost_mpl_has_xxx_has_xxx_template_substitute0_tag type ;
    template < template < typename U0 , typename U1 > class U >
    struct boost_mpl_has_xxx_has_xxx_template_substitute1
        typedef boost_mpl_has_xxx_has_xxx_template_substitute0_tag type ;
    template < typename T >
    class has_xxx_template
        template < typename U , typename V = boost_mpl_has_xxx_has_xxx_template_substitute0_tag >
        struct has_xxx_template_test
            static const bool value = false ;
        template < typename U >
        struct has_xxx_template_test <     U ,
                                        typename boost_mpl_has_xxx_has_xxx_template_substitute0
                                            < typename U :: xxx < > > :: type
                                     >
            static const bool value = true ;
        template < typename U >
        struct has_xxx_template_test <    U ,
                                        typename boost_mpl_has_xxx_has_xxx_template_substitute1
                                            < typename U :: xxx < > > :: type
                                     >
            static const bool value = true ;
        template < typename U >
        struct has_xxx_template_introspect : has_xxx_template_test < U > { } ;
        public :
            static const bool value = has_xxx_template_introspect < T > :: value ;
    int main()
        has_xxx_template<stype> aclass;
        return 0;
    When this is compiled with the C++ compiler of 12.3 with this command line:
    CC +d -library=stlport4 -features=tmplife -features=tmplrefstatic -g -erroff=%none -KPIC -c -o "has_xxx_test_ex2.o" "has_xxx_test_ex2.cpp"
    the result is:
    "has_xxx_test_ex2.cpp", line 30: Warning (Anachronism): Using xxx as a template without a declaration.
    "has_xxx_test_ex2.cpp", line 54:     Where: While specializing "has_xxx_template<stype>".
    "has_xxx_test_ex2.cpp", line 54:     Where: Specialized in non-template code.
    "has_xxx_test_ex2.cpp", line 30: Error: Template template-parameter U<U0> requires a class template argument.
    "has_xxx_test_ex2.cpp", line 54:     Where: While specializing "has_xxx_template<stype>".
    "has_xxx_test_ex2.cpp", line 54:     Where: Specialized in non-template code.
    "has_xxx_test_ex2.cpp", line 39: Warning (Anachronism): Using xxx as a template without a declaration.
    "has_xxx_test_ex2.cpp", line 54:     Where: While specializing "has_xxx_template<stype>".
    "has_xxx_test_ex2.cpp", line 54:     Where: Specialized in non-template code.
    "has_xxx_test_ex2.cpp", line 39: Error: Template template-parameter U<U0, U1> requires a class template argument.
    "has_xxx_test_ex2.cpp", line 54:     Where: While specializing "has_xxx_template<stype>".
    "has_xxx_test_ex2.cpp", line 54:     Where: Specialized in non-template code.
    "has_xxx_test_ex2.cpp", line 36: Error: Multiple declaration for has_xxx_template<stype>::has_xxx_template_test.
    "has_xxx_test_ex2.cpp", line 54:     Where: While specializing "has_xxx_template<stype>".
    "has_xxx_test_ex2.cpp", line 54:     Where: Specialized in non-template code.
    3 Error(s) and 2 Warning(s) detected.

  • BUG in WLE IDL compiler

    Hi,
    I want to report a bug in the WLE5.0 IDL compiler. It occurs in the
    generated stub, skeleton and implementation files (*c,*s and _i)
    files. Here is a description of the problem:
    Say we have the following IDL:
    Filename:filewithmoduleM1.idl
    module M1 {
    #include "BoundaryClasses\CORBA\Types\M1Complex.idl"
    interfaceService {
    boolean method1 (
    interface Factory {
    Service findService ();
    The IDL compiler loses track of the Module M1 and does not scope the
    interfaces inside the module. Henck even if we register a factory called
    APSBalReporting::Factory it is registered as Factory. The problem gets
    more interesting if we have another module that includes the first as
    shown below:
    Filename:filewithmoduleM2.idl
    #include filewithmoduleM1.idl
    module M2 {
    #include "BoundaryClasses\CORBA\Types\M1Complex.idl"
    interface Service {
    boolean method2 (
    interface Factory {
    Service findService ();
    Here it thinks that Service and Factory are the ones for module M1 and
    so generates the return type as M1::Factory and M1::Service instead of
    M2::Factory and M2::Service.
    The IDL compiler used to work fine with code such as the above
    previously.
    Please let me know if you have any feedback for this bug and if any of
    you have tried it.
    Thanks,
    Raman Ramesh
    678-358-3581
    mailto:[email protected]
    www.cicube.com

    BEA customers who need this problem corrected must use WLE 5.1. A patch to WLE 5.0
    or WLE 5.0.1 is not available.
    Wendell MacKenzie wrote:
    We received a patch that fixed this problem under WLE 5.01. There were problems
    back porting the fix into the 5.0 release. Talk to Tom Hegadorn.
    Mary Ann Slavin wrote:
    Actually that is Clarify CASE 162819 not a Clarify CR number. That particular
    problem has been corrected in WLE 5.1. This problem cannot be patched in WLE
    5.0.1, so if you have encountered this problem, you should upgrade to WLE 5.1
    and it is corrected as part of the base product, no patch required.
    MAS
    Wendell MacKenzie wrote:
    You have 2 choices:
    - upgrade to Version 5.1 (which includes CR162819)
    - obtain the patch from BEA support for CR162819 to fix a bug in the IDL
    compiler
    that caused Module and Interface scope names to work incorrectly. Also,
    where
    nesting of IDL #includes exceeded 1 level deep, this caused problems.
    You will have to install the patch onto version 5.01.
    Regards,
    Wendell MacKenzie
    Ram Ramesh wrote:
    Hi,
    I want to report a bug in the WLE5.0 IDL compiler. It occurs in the
    generated stub, skeleton and implementation files (*c,*s and _i)
    files. Here is a description of the problem:
    Say we have the following IDL:
    Filename:filewithmoduleM1.idl
    module M1 {
    #include "BoundaryClasses\CORBA\Types\M1Complex.idl"
    interfaceService {
    boolean method1 (
    interface Factory {
    Service findService ();
    The IDL compiler loses track of the Module M1 and does not scope the
    interfaces inside the module. Henck even if we register a factory called
    APSBalReporting::Factory it is registered as Factory. The problem gets
    more interesting if we have another module that includes the first as
    shown below:
    Filename:filewithmoduleM2.idl
    #include filewithmoduleM1.idl
    module M2 {
    #include "BoundaryClasses\CORBA\Types\M1Complex.idl"
    interface Service {
    boolean method2 (
    interface Factory {
    Service findService ();
    Here it thinks that Service and Factory are the ones for module M1 and
    so generates the return type as M1::Factory and M1::Service instead of
    M2::Factory and M2::Service.
    The IDL compiler used to work fine with code such as the above
    previously.
    Please let me know if you have any feedback for this bug and if any of
    you have tried it.
    Thanks,
    Raman Ramesh
    678-358-3581
    mailto:[email protected]
    www.cicube.com

  • JIT compiler "jitc" not found

    Hi,
    I've just installed JVM 1.4.2 for Unix Systems Services on z/OS 1.4 mainframe.
    When I issue the command java -version I get the following:
    # java -version
    Could not load dll : /usr/lpp/java/IBM/J1.4/bin/libjitc.so
    : EDC5157I An internal error has occurred.
    Warning: JIT compiler "jitc" not found. Will use interpreter.
    java version "1.4.2"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2)
    Classic VM (build 1.4.2, J2RE 1.4.2 IBM z/OS Persistent Reusable VM build cm142-
    20070329 (SR8) (JIT disabled))
    I have check for libjitc.so in the java directory and it is there. Java compiles and runs fine. Can anyone help?

    OS/400 interprets Java methods until reaching the threshold specified by the os400.jit.mmi.threshold Java system property. After reaching the threshold, OS/400 uses the JIT compiler to compile methods into native machine instructions.
    To use the Just-In-Time compiler, you need to set the compiler value to jitc (default it isn't). You can set the value by adding an environment variable or setting the java.compiler system property. Select one method from the list below to set the compiler value:
    * From a command line prompt on your iSeries server, add the environment variable by using the Add Environment Variable (ADDENVVAR) command. Then, run your Java program using the Run Java (RUNJVA) command or JAVA command. For example, use:
    ADDENVVAR ENVVAR (JAVA_COMPILER) VALUE(jitc)
    JAVA CLASS(Test)
    * Set the java.compiler system property on the iSeries command line. For example, enter JAVA CLASS(Test) PROP((java.compiler jitc))
    * Set the java.compiler system property on the Qshell Interpreter command line. For example, enter java -Djava.compiler=jitc Test
    Once you set this value, the JIT compiler optimizes all of the Java code before running it.

  • Difference between JIT compiler and Execution engine...

    where does bytecode get generated???is is in the JIT compiler or in the execution engine???What actually is the process happening inside JVM???can anybody help me in knowing this???

    where does bytecode get generated?Bytecode is the output of javac, the j2se sdk java source compiler.
    is it in the JIT compiler or in the execution engine?No, and No.
    What actually is the process happening inside JVM?The bytecode of the classes to be used
    is loaded and verified
    For an application the main() method of the primary class is launched.
    can anybody help me in knowing this?Unknown.
    We can tell you the answers to the questions you seem to be asking.
    It would help if you could be a bit more specific.

  • Jit compiler "symcjit" not found

    while installing the database 8i enterprise edition on p4 , win 2000 the net8 configuration assistant succeeded but the oracle database configuration assistant failed.
    note that i can still continuing the installation ... but the details on this error in the detail section note " warning jit compiler "symcjit not foubd.will use interpreter.
    folderstarterdb is an invalid command line argument.
    any solution please?

    symcjit.dll is a library for the Just In Time compiler and this was an issue that made people think there was a but with the Pentium IV CPU. This was due to a but with the jit compiler included with the Oracle install media.
    The problem was specifically when the install process took place on P-IV platfoms, the OUI graphical interface didn't appear. The workaround to solve this issue was to create a stage area where the symcjit.dll file was removed. Afterwards, the install ran smoothly. This should not be an issue during the regular oracle operation since the binaries included the correct symcjit.dll file, so it was not necessary to do anything else. If you removed not only the symcjit.dll file from the install media, but also from the Oracle Home then you can expect this error to show up.
    ~ Madrid
    http://hrivera99.blogspot.com/

  • Adaptive Optimization Vs JIT Compilation

    Hello All
    In the below link it is stated that Adaptive Optimization improves the preformance by compiling only frequently used methods.
    Now even in JIT compilation I believe there is threshold that is set , like only if a method has been invoked 400 times the JIT compilations will happen. So my understanding is even in JIT compilation only frequently used methods are compiled.
    But I know I am certainly missing something here as the link is from Oracle.
    Could some one please clarify ? Any insight is higly appreciated.
    http://www.oracle.com/technetwork/java/whitepaper-135217.html#hotspot
    Thanks

    Thanks for the reply but I think HotSpot is only the name of the JVM that has the new technology built into it.Sun have been calling it a technology for ten years, including one of the links you cited.
    The new technology should be the AdaptiveOptimization.Try telling Sun. It's not your decision.
    My question is what is the difference between AdaptiveOptimization and JIT Compilation.Considering you just made up the former name, it's really up to you to tell us.
    I googles a lot but did not get many resources and also were not clear.I find that very difficult to believe.
    For some reason I thought this -XX:CompileThreshold was also available on VMs that had JIT compilersVMs such as what? The whole -XX thing is Sun's, now Oracle's, and they stopped shipping JITs ten years ago, as I already said above.

  • Bug while editing and compiling the procedure

    Bug while editing and compiling the procedure in Sql Developer 1.5.4
    the error is
    ora -00904 "ATTRIBUTE" Invalid Identifier
    Edited by: user4448643 on Mar 16, 2009 5:09 AM

    I'm not trying to be snippy but this is the answer I got from you in another thread about the same issue:
    +"I'm not sure I said it's being worked on - the bug is logged and in the queue.+
    +Support will tell you to move to a supported version of the database, this is true. The same is true for the forum, if you are on an unsupported database version you're encouraged to move to a supported release.+
    +If you need to work with 9i, then use SQL Developer 1.5.3, the error is not in that release."+
    When I read that I got that I should not assume the bug was being worked on and that the SQL Developer team sees 9i as having a short remaining life.
    JB

  • Investigation on JVM crash without core dump (by JIT compiler)

    Hi, All
    I posted "JVM crash without core dump due to CompilerThread1" couple months ago.
    http://forum.java.sun.com/thread.jspa?threadID=5253434
    I would like show what we found, and ask couple questions
    1) The reason of JVM crash is "CompilerThread0/1 wanted to allocate more native memory and eventually exceeded the limit of 32-bit Linux (on Redhat, the limit of VIRT is 3G)
    2) After we lower the heap size (to reduce process size) and added process size monitor (track process size every minute) and JIT compilation log (-XX:+PrintCompilation),
    We found sometimes JVM process jumped more than 800M when compiling one method. with the following log
    Total time for which application threads were stopped: 0.1997400 seconds
    5828 xxx.xxx.SomeClass::someMethod (1507 bytes)
    5828 COMPILE SKIPPED: out of nodes during split (not retryable)
    549002.449: [GC [PSYoungGen: 517897K->28390K(551296K)] 942855K->453348K(1229952K), 0.0726350 secs]
    if we saw "COMPILE SKIPPED: out of nodes during split (not retryable)", the process size of JVM (VIRT/RES) always jumped 800M~1000M, and sometimes the memory get reverted in 30mins to couple hours, and sometimes it lasted forever. (so before we have larger footprint, this jump will kill JVM, right now, if the jump lasts forever, any more allocation on top of it also can kill jvm (much rare))
    3) This is definitely a bug of JVM, because
    it only happened on server mode, not client mode
    it is random, that method can be compiled success on other JVM or next restart (we have 20 JVMs)
    the method is not that complicate, like 100 lines, (bigger method gets compiled success)
    this only happen on PROD environment, we can't reproduce it locally or QA (the method is always compiled success)
    It mostly like under some condition (maybe node space is not enough), to compile that method will trigger JVM trying to allocate much more native memory.
    4) We are going to disable this method by ".hotspot_compiler" to fix it, right now we are using lower footprint, JVM dies rarely.
    +To understand more about this, I have some questions about JIT compiling+
    I saw same method are compiled more than once from JIT log, like the method caused our problem, it only happens on 2nd time compilation.
    Is it that JIT compiler will recompile the method with deeper optimization level some time, and more optimization it uses, the more memory it requires?
    (like gcc has -O2 -O3)
    Thanks!
    Neo

    Today, one JVM crashed again, with
    {Heap before gc invocations=4188:
    PSYoungGen      total 540864K, used 487958K [0x8ba50000, 0xb1250000, 0xb1250000)
      eden space 467328K, 100% used [0x8ba50000,0xa82b0000,0xa82b0000)
      from space 73536K, 28% used [0xa82b0000,0xa96d5850,0xaca80000)
      to   space 71680K, 0% used [0xacc50000,0xacc50000,0xb1250000)
    ParOldGen       total 1024000K, used 493477K [0x4d250000, 0x8ba50000, 0x8ba50000)
      object space 1024000K, 48% used [0x4d250000,0x6b439610,0x8ba50000)
    PSPermGen       total 101760K, used 101240K [0x2d250000, 0x335b0000, 0x4d250000)
      object space 101760K, 99% used [0x2d250000,0x3352e1f8,0x335b0000)
    405290.711: [GC [PSYoungGen: 487958K->17397K(544192K)] 981435K->518248K(1568192K), 0.0769350 secs]
    Heap after gc invocations=4188:
    PSYoungGen total 544192K, used 17397K [0x8ba50000, 0xb1250000, 0xb1250000)
    eden space 472512K, 0% used [0x8ba50000,0x8ba50000,0xa87c0000)
    from space 71680K, 24% used [0xacc50000,0xadd4d480,0xb1250000)
    to space 70208K, 0% used [0xa87c0000,0xa87c0000,0xacc50000)
    ParOldGen total 1024000K, used 500851K [0x4d250000, 0x8ba50000, 0x8ba50000)
    object space 1024000K, 48% used [0x4d250000,0x6bb6cf70,0x8ba50000)
    PSPermGen total 101760K, used 101240K [0x2d250000, 0x335b0000, 0x4d250000)
    object space 101760K, 99% used [0x2d250000,0x3352e1f8,0x335b0000)
    Total time for which application threads were stopped: 0.0779620 seconds
    Exception in thread "CompilerThread1" java.lang.OutOfMemoryError: requested 4522768 bytes for Chunk::new. Out of swap space?

  • Need of a jit compiler

    hi,
    what i know is jit compiler is used to boostup the process of converting byte code into native machine code .then in the absence of jit who will do this process.
    and please also calrify
    will byte code be interpreted or complied into native code ?
    if jit compiler will compile the byte code into native code then why java is called interpreted language?

    hi,
    what i know is jit compiler is used to boostup the
    process of converting byte code into native machine
    code .then in the absence of jit who will do this
    process.What ever it is that is used instead.
    and please also calrify
    will byte code be interpreted or complied into native
    code ?Take a guess: why is it called compiler and not interpreter?
    if jit compiler will compile the byte code into
    native code then why java is called interpreted
    language?It isn't.

  • Different results using Matcher.replaceAll on a literal depending on the Pattern compiled

    I would have expected that the results for all the following scenarios would have been the same:
    public class PatternMatcher {
        public static void main(String[] args) {
            Pattern p;
            Matcher m;
            // duplicates
            p = Pattern.compile("(.*)");
            m = p.matcher("abc");
            if (m.matches()) System.out.println(p + " : " + m.replaceAll("xyz"));
            // single
            p = Pattern.compile("(.+)");
            m = p.matcher("abc");
            if (m.matches()) System.out.println(p + " : " + m.replaceAll("xyz"));
            // wtf
            p = Pattern.compile("(.*?)");
            m = p.matcher("abc");
            if (m.matches()) System.out.println(p + " : " + m.replaceAll("xyz"));
            // duplicates
            p = Pattern.compile("(.*+)");
            m = p.matcher("abc");
            if (m.matches()) System.out.println(p + " : " + m.replaceAll("xyz"));
            // single
            p = Pattern.compile("^(.*)");
            m = p.matcher("abc");
            if (m.matches()) System.out.println(p + " : " + m.replaceAll("xyz"));
            // duplicates
            p = Pattern.compile("(.*)$");
            m = p.matcher("abc");
            if (m.matches()) System.out.println(p + " : " + m.replaceAll("xyz"));
            // single
            p = Pattern.compile("^(.*)$");
            m = p.matcher("abc");
            if (m.matches()) System.out.println(p + " : " + m.replaceAll("xyz"));
            // single
            p = Pattern.compile("(.(.*).)");
            m = p.matcher("abc");
            if (m.matches()) System.out.println(p + " : " + m.replaceAll("xyz"));
    But the results vary depending on the pattern compiled:
    (.*) : xyzxyz
    (.+) : xyz
    (.*?) : xyzaxyzbxyzcxyz
    (.*+) : xyzxyz
    ^(.*) : xyz
    (.*)$ : xyzxyz
    ^(.*)$ : xyz
    (.(.*).) : xyz
    Since all of the patterns have an all-encompassing capture group, but the replacement string does not have any group references, I was expecting that in every case the replacement string would simply be returned unchanged (so just "xyz").
    Have I uncovered a bug in the core library?  or am I misunderstanding how this should be working?

    jwenting wrote:
    And such is the case here.
    "You're doing it wrong, but I'm not going to tell you what it is you're doing wrong nah nah nah"
    That's the good thing about long lasting platforms such as Java - APIs become mature because they've been tested and re-tested by thousands of people for more than a decade. And thus when you go to use them and have to think "wtf", you can be almost certain you simply don't understand and meanies in forums can say so without having any ammunition to back up that accusation.

  • [svn:fx-trunk] 16929: Add a [Mixin] class that will register the required class aliases in the event the mxml compiler generation   [RemoteClass(alias="")] code is not called because an application does not use the Flex UI framework .

    Revision: 16929
    Revision: 16929
    Author:   [email protected]
    Date:     2010-07-15 07:38:44 -0700 (Thu, 15 Jul 2010)
    Log Message:
    Add a class that will register the required class aliases in the event the mxml compiler generation  [RemoteClass(alias="")] code is not called because an application does not use the Flex UI framework.
    Add a reference to this class in the RPCClasses file so it always gets loaded.
    QE notes: Need a remoting and messaging regression test that doesn't use Flex UI.
    Bugs: Watson bug 2638788
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/rpc/src/RPCClasses.as
    Added Paths:
        flex/sdk/trunk/frameworks/projects/rpc/src/mx/utils/RpcClassAliasInitializer.as

    Great exercise to document the problem like this.  It got me thinking about how an app with modules would be different from an app that does not use modules.  Solution: I moved the dummy reference of PersonPhotoView out to the main application file (as opposed to being inside the module) and it worked.  I've probably been lucky not to have experienced this problem earlier, because for most other entities I have an instance attached to my model which is linked / compiled with the main application.

  • Correcting a bug in the JRE classes

    I have run across a bug in the class java.text.DecimalFormat
    I am using JSE 1.3.1_04, Windows XP professional o.s.
    The bug resides in the following method:
    public StringBuffer format(double number, StringBuffer
    result, FieldPosition fieldPosition)
    The following line of code within the abovementioned
    method will produce a "hotspot divide by zero error",
    if the variable named "number" contains a value of zero.
    boolean isNegative = (number < 0.0) || (number == 0.0 &&
    1/number < 0.0);
    I would like to repair this bug "in place" (actually change the line of code in error), and return the fixed class to the java.text package. How can I do this? I have extracted the source from the src.jar file, made the change, and now I need to replace the older version of this class.
    BTW, I have submitted a bug report, however, I cannot wait for the fix.

    Anyways, here is my somewhat "hacked" version of DecimalFormat.java to bypass the problem. Just make sure the following program resides in a directory that precedes the "rt.jar" file in the classpath.
    import java.text.FieldPosition;
    * A convenenience class to override the default implementation of DecimalFormat.
    * This is purely a "workaround" to avoid the "divide by zero" error that is occasionally
    * issued by the HotSpot  compiler.  See #format(double value) method for details
    * When (and if) there is a problem resolution in a future release, this program should be disabled
    * @author Stuart Leonard
    * @version 1.0
    * @since 09/08/2002
    class DecimalFormat
        private java.text.DecimalFormat decfmt;
        private String dft = "";
        private static final char       PATTERN_DIGIT              = '#';
         * The public constructor for this class.  Accepts a pattern to be used
         * by a java.text.DecimalFormat object
         * @param fmt The pattern to be used
        public DecimalFormat(String fmt)
            decfmt = new java.text.DecimalFormat(fmt);
            // check to see if last position of pattern is zero
            // if so, initialize a "zero balance" default pattern.
            if (fmt != null && fmt.length() > 0)
                StringBuffer strbuf = new StringBuffer(fmt);
                int endPos = strbuf.length()-1;
                if (strbuf.charAt(endPos) == '0')
                    int begPos = endPos;
                    for (int i = endPos; i>0; i--)
                        char chr = strbuf.charAt(i);
                        if (chr == PATTERN_DIGIT)
                            begPos = i+1;
                            break;
                    dft = strbuf.substring(begPos, endPos+1);
         * An overridden implementation of #java.text.NumberFormat.format(double)
         * If value is zero, then initialize return value with a blank suppressed
         * "zero balance" value, as specified by the original format pattern.
         * @param value The incoming double value to be formatted by a string pattern
         * @return The incoming value represented as a string pattern
        public String format (double value)
            String formatted = dft;
            if (value != 0)
                formatted = decfmt.format(value);
            return formatted;   
         * An overridden implementation of #java.text.DecimalFormat.format(double, StringBuffer, FieldPosition)
         * If value is zero, then initialize return value with a blank suppressed
         * "zero balance" value, as specified by the original format pattern.
         * Formats a double to produce a string.
         * @param number    The double to format
         * @param toAppendTo    where the text is to be appended
         * @param fieldPosition    On input: an alignment field, if desired.
         * On output: the offsets of the alignment field.
         * @return The value passed in as the result parameter
         * @see java.text.FieldPosition
        public StringBuffer format(double number, StringBuffer result,
                                   FieldPosition fieldPosition)
            StringBuffer strbuf = new StringBuffer();
            if (number != 0)
                strbuf = decfmt.format(number, result, fieldPosition);
            else   
                strbuf.append(dft);
            return strbuf;   
         * The default implementation of #java.text.NumberFormat.format(long)
         * This exists ONLY because of the "divide by zero" error that
         * is being issued by #java.text.DecimalFormat.format(double, String Buffer, FieldPosition)
         * @param value The incoming value to be formatted by a string pattern
         * @return The incoming value represented as a string pattern
        public String format (long value)
              return decfmt.format(value);
         * The default implementation of #java.text.DecimalFormat.format(long, StringBuffer, FieldPosition)
         * This exists ONLY because of the "divide by zero" error that
         * is being issued by #java.text.DecimalFormat.format(double, String Buffer, FieldPosition)
         * Format a long to produce a string.
         * @param number    The long to format
         * @param toAppendTo    where the text is to be appended
         * @param fieldPosition    On input: an alignment field, if desired.
         * On output: the offsets of the alignment field.
         * @return The value passed in as the result parameter
         * @see java.text.FieldPosition
        public StringBuffer format(long number, StringBuffer result,
                                   FieldPosition fieldPosition)
            return decfmt.format(number, result, fieldPosition);

  • Bug in the ServerSocket InputStream.read()

    I believe there is a bug in the ServerSocket InputStream.read() method.
    This is demonstrated under Windows XP, running 1.4.0_01-b03
    I am looking for confirmation and an examination of my assumptions for this.
    There is nothing that suggests the InputStream.read() method should block on a EOL, yet it does.
    This is demonstrated with the following code.
    To reproduce uncomment one of the 'Case' sections in the MyServer code. Compile both classes. Run the MyServer then MyClient code.
    The expected result for ALL cases should be
    ***socket start
    text1
    text2
    But for the first case the last line is not printed. Note that for case 3 it does work, and the only exception is that available() is called.
    The InputStream of the server resolves to java.net.SocketInputStream. The read() method calls the read(byte, int, int) method (which how I guessed that calling available would produce different results.)
    //-----------------Client
        import java.io.*;
        import java.net.*;
        public class MyClient
            private MyClient() {}
            static public void main(String argv[])
                try
                    Socket s = new Socket("127.0.0.1", 50080);
                    OutputStream os = s.getOutputStream();
                    String text = "text1\r\ntext2";
                    os.write(text.getBytes());
                    os.flush();  // We know it was sent.
                    // Important!  The socket remains open!
                    while(true)
                        Thread.currentThread().sleep(60 * 1000);
                catch(Throwable e)
                    e.printStackTrace();
    //----------- Server
        import java.net.*;
        public class MyServer implements Runnable
            Socket s;
            public MyServer(Socket s)
                this.s = s;
            static public void main(String argv[])
                try
                    ServerSocket ss=new ServerSocket(50080);
                    while(true)
                        Socket s=ss.accept();
                        Thread t = new Thread(new MyServer(s));
                        t.start();
                catch(Throwable e)
                    e.printStackTrace();
            public void run()
                try
                    System.out.println("***socket start");
                    java.io.InputStream ins=s.getInputStream();
                    // Case 1: Does NOT work
                    int j;
                    while((j=ins.read())!=-1)
                        System.out.write(j);
                    // Case 3: Does work
                    while (true)
                        int len = ins.available();
                        if ((len < 0) || s.isClosed()) break;
                        byte b[] = new byte[len];
                        ins.read(b);
                        for (int i=0; i < len; i++)
                            System.out.print((char)b);
    // Case 3: Does work
    while (true)
    int len = ins.available();
    if ((len < 0) || s.isClosed()) break;
    for (int i=0; i < len; i++)
    int b = ins.read();
    System.out.print((char)b);
    System.out.println("***socket end");
    catch(Throwable e)
    e.printStackTrace();

    System.out is line buffered. (I can only hope that I might have noticed this myself if I had been smart enough to use the same output method.)
    Ok so it isn't a socket problem. But I still don't see anything that documents the behavior.
    System.out is documented as a java.io.PrintStream. And that is actually the class that implements it.
    Nothing in the documentation for PrintStream, the methods, the FilterOutputStream or even OutputStream would suggest the different behavior.
    C works the same way; this never prints "world" on most systems:C works that way because of the way file descriptors work and the way that the buffers for those are handled. And how it works is undefined, a C implementation is allowed to handle it anyway it wants.
    But this Java and not C. That means at a minimum that the behavior must be the same on all OSs. But given that the behavior is not documented then it could be that it is left to the implementation of the C library that the java io library is built upon. And that is not a good thing (in terms of normal java.)
    The following demonstrates the behavior using the two output methods...
          String text = "text1\r\ntext2";
          byte[] b = text.getBytes();
          System.out.println("--- print using print() sleep for 10 secs after");
          for (int i=0; i < b.length; i++)
             System.out.print((char)b);
    Thread.currentThread().sleep(10 *1000);
    System.out.println();
    System.out.println("--- print using write() sleep for 10 secs after");
    for (int i=0; i < b.length; i++)
    System.out.write((int)b[i]);
    Thread.currentThread().sleep(10 *1000);
    System.out.println();
    System.out.println("--- done");

  • JIT compiler and nested classes

    Q1. how does JIT compile on fly and improve the performance ?
    Q2. how is system.out.println(argument) implemented in java ? is it that system is a class in which out is a static nested class and println is a static method in out?

    Hello rishiluvsjava,
    Q1. How does JIT compile on fly and improve the performance?
    The following answer was taken from "The Java HotSpot Performance Engine Architecure: A White Paper About Sun's Second Generation Performance Technology" to view the full document go to:
    http://java.sun.com/products/hotspot/whitepaper.html
    Just-In-Time (JIT) compilers are essentially fast traditional compilers that translate the Java-technology bytecodes into native machine code on-the-fly. A JIT runs on the end-user's machine which actually executes the bytecodes, and compiles each method the first time it is executed.
    Q2. How is System.out.println(argument) implemented in java ? is it that system is a class in which out is a static nested class and println is a static method in out?
    From the Java docs:
    System is a public final class in the java.lang package. It has three fields:
    static PrintStream err    // The "standard" error output stream.
    static InputStream in    // The "standard" input stream.
    static PrintStream out  //The "standard" output stream.println is one of the methods in the java.io.PrintStream class.
    -Merwyn,
    Developer Technical Support,
    http://www.sun.com/developers/support.

Maybe you are looking for