1 2 Previous Next 21 Replies Latest reply: Jan 29, 2010 6:39 PM by EJP Go to original post RSS
      • 15. Re: Constants in Java Compiler
        843810
        jschell wrote:
        That isn't huge. It isn't even big. It is either small or even tiny.
        Thanks for correcting me.
        • 16. Re: Constants in Java Compiler
          jschellSomeoneStoleMyAlias
          This dependency is at compile time only. I wish to see this at run time as well.
          Did you understand my reply?
          • 17. Re: Constants in Java Compiler
            jschellSomeoneStoleMyAlias
            ejp wrote:
            it means that that the variable only exists as a compile time value
            Untrue.
            Without an initializer block there is no way for the compiler to initialize it at runtime.
            Untrue. It doesn't have to be initialized at run time. It can be in the constant pool. And just because you can't write an initializer block doesn't imply that the compiler can't.
            So it just disappears.
            Untrue. It is embedded into the object file. Otherwise how can javac and javap find it at all?
            And no JNI nor reflection access either.
            Untrue.
            So now that I have bit more time to investigate...

            You are correct.

            And the same holds for similar situations in a class.

            The initialization will be handled either via a static initializer or a constant attribute defined in the following.

            http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html#1405

            If this appears in the class structure (whether one starts with a java class or interface) then there is no initializer. It redirects directly to a value in the pool.

            If the value cannot be represented in the pool, such as object creation, then a static initializer is created (both interface and class.)

            The constant attribute can only be used for a 'final' value and 'static'. Not sure why it would matter if it was static or not.


            One result of this per the OPs question is that if the value had not been a primitive but rather an object then one could have manipulated the static initializer on loading the interface to change the value.
            • 18. Re: Constants in Java Compiler
              EJP
              This dependency is at compile time only. I wish to see this at run time as well.
              I do not understand.
              • 19. Re: Constants in Java Compiler
                843810
                >
                The initialization will be handled either via a static initializer or a constant attribute defined in the following.

                http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html#1405

                If this appears in the class structure (whether one starts with a java class or interface) then there is no initializer. It redirects directly to a value in the pool.
                >
                I want to modify this pool.
                If the value cannot be represented in the pool, such as object creation, then a static initializer is created (both interface and class.)

                The constant attribute can only be used for a 'final' value and 'static'. Not sure why it would matter if it was static or not.
                My question is do u have any clue, how to proceed with modifying the compiler code such that my purpose is served. It may be possible that code may not run, it doesnot matter.
                • 20. Re: Constants in Java Compiler
                  EJP
                  We still don't know what your purpose is, but modifying Java bytecode almost certainly isn't the solution.
                  • 21. Re: Constants in Java Compiler
                    jschellSomeoneStoleMyAlias
                    raghavx wrote:
                    I want to modify this pool.
                    Pointless.

                    The compiler already moved the constant into the other compiled classes.

                    Are you going to re-compile the classes? If yes there are easier ways to change the value. If no then the value in the compiled classes will not be impacted by this.
                    If the value cannot be represented in the pool, such as object creation, then a static initializer is created (both interface and class.)

                    The constant attribute can only be used for a 'final' value and 'static'. Not sure why it would matter if it was static or not.
                    My question is do u have any clue, how to proceed with modifying the compiler code such that my purpose is served. It may be possible that code may not run, it doesnot matter.
                    That question doesn't make sense.

                    Are you going to recompile? The answer to that question is the ONLY question that matters.
                    1 2 Previous Next