>>
>> Any patch with lazy evaluation will not cause problems in the "normal"
>> case but will affect debugging Fred because turning on debug log level
>> for a single class will cause all lazy parameters everywhere to be
>> created.

Before someone calls me out on this one I this is how you can use lazy
evaluation without garbage on hotspot jvms.  The statement becomes
getLog().log( <lazy args> ) and the predicate goes in the getter.

===== CallSiteJitting.java =====
public class CallSiteJitting {

        static interface Logger {
                void log(Object ar1, Object ar2);
        }

        static class MuteLogger implements Logger {
                public void log(Object ar1, Object ar2){}
        }

        static class RealLogger implements Logger {
                static long sideEffect;
                public void log(Object ar1, Object ar2) {
                        sideEffect += ar1.hashCode();
                        sideEffect += ar2.hashCode();
                }
        }

        private static final Logger mute = new MuteLogger();
        private static final Logger real = new RealLogger();

        private static boolean once;
        private static Logger getLog() {
                if (!once) {
                        once = true;
                        System.out.println("real logging once");
                        // if you return real every time lots of
                        // garbage collections happen
                        return real;
                }
                return mute;
        }

        public static void main(String []ar) throws Exception {

                for (long l = 0; l < Long.MAX_VALUE; l++) {
                        getLog().log(new Object(), new Object());
                }

                System.out.println(RealLogger.sideEffect);
        }
}
===== end CallSiteJitting.java
_______________________________________________
Devl mailing list
Devl@freenetproject.org
https://emu.freenetproject.org/cgi-bin/mailman/listinfo/devl

Reply via email to