Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.0
    • Fix Version/s: 2.5, 2.1
    • Component/s: None
    • Labels:
      None

      Description

      Greg, hello:

      1) in this example you say:
      http://pivot.apache.org/tutorials/list-buttons.html
      "Note that this example makes use of the global resource cache to store the loaded images."

      2) which reminds of the "java evil singleton pattern"
      http://java.sun.com/developer/technicalArticles/Programming/singletons/
      http://www.ibm.com/developerworks/webservices/library/co-single/index.html
      http://beust.com/weblog/2011/03/10/rehabilitating-the-singleton-pattern/
      http://tech.puredanger.com/2007/07/03/pattern-hate-singleton/
      and the consensus seems to be:
      "Singletons are fine as long as you don't implement them with static"

      3) and pivot uses them freely; few examples

      public abstract class ApplicationContext {

      protected static ArrayList<Display> displays = new ArrayList<Display>();
      protected static ArrayList<Application> applications = new ArrayList<Application>();

      private static HashMap<URI, Object> resourceCache = new HashMap<URI, Object>();
      private static ResourceCacheDictionary resourceCacheDictionary = new ResourceCacheDictionary();

      public abstract class Theme {

      private static Theme theme = null;

      4) do you think is it feasible to convert all of pivot into SPI:

      ServiceLoader<PivotFrameworkFactory> loader = ServiceLoader.load(PivotFrameworkFactory.class);
      PivotFrameworkFactory factory = loader.iterator().next();
      Map<String, Object> config = new HashMap<String, Object>();
      PivotFramework framework = factory.newFramework(config);

      5) the two use cases that affect me now:
      a) applet reload shares static
      b) pivot + osgi (not sure yet if I can find a workaround; possibly depends on what you do about PIVOT-742 PIVOT-22)

      thank you;

      Andrei

        Activity

        Hide
        Sandro Martini added a comment -

        I'm not against this, but at the moment I'd prefer to not complicate too much the usage in standard (not-OSGi) cases, so I assign it to 2.1 for the moment.

        On the Applets issue maybe this could be more important for us (could have more occurrences in our usual cases) in the short term.
        What others say ?

        Show
        Sandro Martini added a comment - I'm not against this, but at the moment I'd prefer to not complicate too much the usage in standard (not-OSGi) cases, so I assign it to 2.1 for the moment. On the Applets issue maybe this could be more important for us (could have more occurrences in our usual cases) in the short term. What others say ?
        Hide
        Greg Brown added a comment -

        Yes, it is possible to refactor this code to use a service provider. However, I'm not sure that it is justified. Can you elaborate a bit more on the problem(s) you are trying to solve?

        Show
        Greg Brown added a comment - Yes, it is possible to refactor this code to use a service provider. However, I'm not sure that it is justified. Can you elaborate a bit more on the problem(s) you are trying to solve?
        Hide
        Andrei Pozolotin added a comment -

        APPLETS:

        1) this project:
        https://github.com/carrot-garden/carrot-bugger/tree/master/carrot-bug-pivot-static-core
        with this launcher:
        https://github.com/carrot-garden/carrot-bugger/tree/master/carrot-bug-pivot-static-launch

        2) uses 3 files
        https://github.com/carrot-garden/carrot-bugger/blob/master/carrot-bug-pivot-static-core/src/main/java/com/carrotgarden/test/MainPivot.java
        https://github.com/carrot-garden/carrot-bugger/blob/master/carrot-bug-pivot-static-core/src/main/java/com/carrotgarden/test/MainPivot.bxml
        https://github.com/carrot-garden/carrot-bugger/blob/master/carrot-bug-pivot-static-core/src/main/java/com/carrotgarden/test/WindowExtra.java

        3) with 1 static counter:

        public class WindowExtra extends Window implements Bindable {

        protected static final Logger log = LoggerFactory
        .getLogger(WindowExtra.class);

        private static final AtomicInteger COUNTER = new AtomicInteger(0);

        @Override
        public void initialize(Map<String, Object> namespace, URL location,
        Resources resources)

        { Label counterLabel = (Label) namespace.get("counter"); counterLabel.setText("" + COUNTER.getAndIncrement()); }

        }

        4) you can try for yourself here:
        http://www.carrotgarden.com:8080/webstart-carrot-bug-pivot-applet-static-staging/

        when you select launch mode "applet (plugin V1)" (AKA "legacy", "non-jnlp", "apple-default")
        you will get an applet with counter that gets incremented on every applet reload;

        since I it is hard to tell how all the static fields in pivot interact, my concerns with pivot are:

        • memory leaks;
        • cross-page applet interferences;
        • security;

        thanks.

        Show
        Andrei Pozolotin added a comment - APPLETS: 1) this project: https://github.com/carrot-garden/carrot-bugger/tree/master/carrot-bug-pivot-static-core with this launcher: https://github.com/carrot-garden/carrot-bugger/tree/master/carrot-bug-pivot-static-launch 2) uses 3 files https://github.com/carrot-garden/carrot-bugger/blob/master/carrot-bug-pivot-static-core/src/main/java/com/carrotgarden/test/MainPivot.java https://github.com/carrot-garden/carrot-bugger/blob/master/carrot-bug-pivot-static-core/src/main/java/com/carrotgarden/test/MainPivot.bxml https://github.com/carrot-garden/carrot-bugger/blob/master/carrot-bug-pivot-static-core/src/main/java/com/carrotgarden/test/WindowExtra.java 3) with 1 static counter: public class WindowExtra extends Window implements Bindable { protected static final Logger log = LoggerFactory .getLogger(WindowExtra.class); private static final AtomicInteger COUNTER = new AtomicInteger(0); @Override public void initialize(Map<String, Object> namespace, URL location, Resources resources) { Label counterLabel = (Label) namespace.get("counter"); counterLabel.setText("" + COUNTER.getAndIncrement()); } } 4) you can try for yourself here: http://www.carrotgarden.com:8080/webstart-carrot-bug-pivot-applet-static-staging/ when you select launch mode "applet (plugin V1)" (AKA "legacy", "non-jnlp", "apple-default") you will get an applet with counter that gets incremented on every applet reload; since I it is hard to tell how all the static fields in pivot interact, my concerns with pivot are: memory leaks; cross-page applet interferences; security; thanks.
        Hide
        Andrei Pozolotin added a comment -

        BTW, speaking of "evil static":

        if I run both of these at the same time in the same firefox on linux, in different tabs:
        http://www.carrotgarden.com:8080/webstart-carrot-bug-pivot-applet-static-staging/index-applet.jsp?plugin=V1
        http://pivot.apache.org/demos/kitchen-sink.html

        then both of them become unresponsisve, seeminly locking in this part (in 2 different jvm instances!):
        org.apache.pivot.wtk.ApplicationContext$DisplayHost.paintVolatileBuffered

        if I kill one of them, the other starts running just fine;
        I guess video driver writers use a lot of static fields also

        Show
        Andrei Pozolotin added a comment - BTW, speaking of "evil static": if I run both of these at the same time in the same firefox on linux, in different tabs: http://www.carrotgarden.com:8080/webstart-carrot-bug-pivot-applet-static-staging/index-applet.jsp?plugin=V1 http://pivot.apache.org/demos/kitchen-sink.html then both of them become unresponsisve, seeminly locking in this part (in 2 different jvm instances!): org.apache.pivot.wtk.ApplicationContext$DisplayHost.paintVolatileBuffered if I kill one of them, the other starts running just fine; I guess video driver writers use a lot of static fields also
        Hide
        Andrei Pozolotin added a comment -

        the above "static in video driver" is actually reproducible in google chrome also;
        which likely means that it is a "feature" of pivot killing nsplugin via volatile memory access;
        since I cant remember any other applets / frameworks with this "feature", probably this can be fixed in pivot?

        Show
        Andrei Pozolotin added a comment - the above "static in video driver" is actually reproducible in google chrome also; which likely means that it is a "feature" of pivot killing nsplugin via volatile memory access; since I cant remember any other applets / frameworks with this "feature", probably this can be fixed in pivot?
        Hide
        Andrei Pozolotin added a comment -

        another confirmation that it is likely pivot + nsplugin: if you run
        http://pivot.apache.org/demos/kitchen-sink.html
        with this as a stand alone app
        http://www.carrotgarden.com:8080/webstart-carrot-bug-pivot-applet-static-staging/
        then there is no locking any more

        Show
        Andrei Pozolotin added a comment - another confirmation that it is likely pivot + nsplugin: if you run http://pivot.apache.org/demos/kitchen-sink.html with this as a stand alone app http://www.carrotgarden.com:8080/webstart-carrot-bug-pivot-applet-static-staging/ then there is no locking any more
        Hide
        Greg Brown added a comment -

        The static fields are there by design. Some of them, like the Display list, are used specifically to support applets.

        The issues you describe could very easily be due to the plugin implementation on Linux. Pivot does not use any native code and so should run the same on all JVM implementations.

        Show
        Greg Brown added a comment - The static fields are there by design. Some of them, like the Display list, are used specifically to support applets. The issues you describe could very easily be due to the plugin implementation on Linux. Pivot does not use any native code and so should run the same on all JVM implementations.
        Hide
        Andrei Pozolotin added a comment -

        APPLETS:

        1) re: "The issues you describe could very easily be due to the plugin implementation on Linux"

        2) I verified this page:
        http://www.carrotgarden.com:8080/webstart-carrot-bug-pivot-applet-static-staging/index-applet.jsp?plugin=V1

        on:

        • windows 7 (6.1 b 7600)
          java version "1.6.0_23"
          Java(TM) SE Runtime Environment (build 1.6.0_23-b05)
          Java HotSpot(TM) 64-Bit Server VM (build 19.0-b09, mixed mode)
        • firefox 4.0.1
        • internet explorer 8.0.7600
        • google chrome 11.0.696.68
        • ubuntu 10.04 2.6.32-29-generic #58-Ubuntu SMP Fri Feb 11 20:52:10 UTC 2011 x86_64 GNU/Linux
          java version "1.6.0_24"
          Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
          Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)
        • firefox 3.6.17
        • google chrome 11.0.696.68
        • macosx 10.6.7
          java version "1.6.0_24"
          Java(TM) SE Runtime Environment (build 1.6.0_24-b07-334-10M3326)
          Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02-334, mixed mode)
        • firefox 3.6.6
        • google chrome 11.0.696.68
        • safari 5.0.5

        3) and confirmed that "counter still goes up";
        which means that the perferred way you use to start all your pivot apps:
        http://pivot.apache.org/demos/kitchen-sink.html

        var attributes =

        { code:"org.apache.pivot.wtk.BrowserApplicationContext$HostApplet", width:"100%", height:"100%" }

        ;
        var libraries = [];
        libraries.push("/lib/pivot-core-2.0.jar");
        libraries.push("/lib/pivot-wtk-2.0.jar");
        libraries.push("/lib/pivot-wtk-terra-2.0.jar");
        libraries.push("/lib/pivot-tutorials-2.0.jar");
        libraries.push("/lib/svgSalamander-tiny.jar");
        attributes.archive = libraries.join(",");
        var parameters =

        { codebase_lookup:false, application_class_name:'org.apache.pivot.tutorials.KitchenSink' }

        ;
        var javaArguments = ["-Dsun.awt.noerasebackground=true","-Dsun.awt.erasebackgroundonresize=true"];
        parameters.java_arguments = javaArguments.join(" ");
        deployJava.runApplet(attributes, parameters, "1.6");

        4) which is so called "legacy plugin mode",
        will share all static fields between applet invocations,
        even if you navigate away form applet and then come back
        (the timeout is about 2 minutes for jvm to expire, when there are no active applets,
        but static fields are still active before jvm expires)

        5) re "The static fields are there by design"; indeed, I understand;
        I am merely asking to improve the design; what I would ideally want is:
        a) instaniate all of pivot as a single instance via spi;
        b) no static fields - based singletons inside pivot framework;
        c) pivot caches watever it wants in singletons (which are not static fields);

        Show
        Andrei Pozolotin added a comment - APPLETS: 1) re: "The issues you describe could very easily be due to the plugin implementation on Linux" 2) I verified this page: http://www.carrotgarden.com:8080/webstart-carrot-bug-pivot-applet-static-staging/index-applet.jsp?plugin=V1 on: windows 7 (6.1 b 7600) java version "1.6.0_23" Java(TM) SE Runtime Environment (build 1.6.0_23-b05) Java HotSpot(TM) 64-Bit Server VM (build 19.0-b09, mixed mode) firefox 4.0.1 internet explorer 8.0.7600 google chrome 11.0.696.68 ubuntu 10.04 2.6.32-29-generic #58-Ubuntu SMP Fri Feb 11 20:52:10 UTC 2011 x86_64 GNU/Linux java version "1.6.0_24" Java(TM) SE Runtime Environment (build 1.6.0_24-b07) Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode) firefox 3.6.17 google chrome 11.0.696.68 macosx 10.6.7 java version "1.6.0_24" Java(TM) SE Runtime Environment (build 1.6.0_24-b07-334-10M3326) Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02-334, mixed mode) firefox 3.6.6 google chrome 11.0.696.68 safari 5.0.5 3) and confirmed that "counter still goes up"; which means that the perferred way you use to start all your pivot apps: http://pivot.apache.org/demos/kitchen-sink.html var attributes = { code:"org.apache.pivot.wtk.BrowserApplicationContext$HostApplet", width:"100%", height:"100%" } ; var libraries = []; libraries.push("/lib/pivot-core-2.0.jar"); libraries.push("/lib/pivot-wtk-2.0.jar"); libraries.push("/lib/pivot-wtk-terra-2.0.jar"); libraries.push("/lib/pivot-tutorials-2.0.jar"); libraries.push("/lib/svgSalamander-tiny.jar"); attributes.archive = libraries.join(","); var parameters = { codebase_lookup:false, application_class_name:'org.apache.pivot.tutorials.KitchenSink' } ; var javaArguments = ["-Dsun.awt.noerasebackground=true","-Dsun.awt.erasebackgroundonresize=true"] ; parameters.java_arguments = javaArguments.join(" "); deployJava.runApplet(attributes, parameters, "1.6"); 4) which is so called "legacy plugin mode", will share all static fields between applet invocations, even if you navigate away form applet and then come back (the timeout is about 2 minutes for jvm to expire, when there are no active applets, but static fields are still active before jvm expires) 5) re "The static fields are there by design"; indeed, I understand; I am merely asking to improve the design; what I would ideally want is: a) instaniate all of pivot as a single instance via spi; b) no static fields - based singletons inside pivot framework; c) pivot caches watever it wants in singletons (which are not static fields);
        Hide
        Andrei Pozolotin added a comment -

        re: "Some of them, like the Display list, are used specifically to support applets"

        note that if you switch form "legacy plugin mode" (non-jnlp) into "next gen plugin mode" (yes-jnlp)
        there are no shared static fields any more. and if pivot makes assumptions about presense of shared static fields
        it is a bug.

        Show
        Andrei Pozolotin added a comment - re: "Some of them, like the Display list, are used specifically to support applets" note that if you switch form "legacy plugin mode" (non-jnlp) into "next gen plugin mode" (yes-jnlp) there are no shared static fields any more. and if pivot makes assumptions about presense of shared static fields it is a bug.
        Hide
        Greg Brown added a comment -

        > I verified this page...and confirmed that "counter still goes up"

        That is the correct behavior. As you note below, when applets share a common VM instance and classloader, all static values are also shared.

        > the perferred way you use to start all your pivot apps...which is so called "legacy plugin mode", will share all static fields between applet invocations

        There is no "preferred" way to start Pivot applets. You are free to use the separate_jvm parameter if you want.

        Also, to my knowledge, there is no such thing as "legacy" plugin mode. If you set separate_jvm to true, the plugin should create a separate JVM instance, though it may not. If you omit separate_jvm or set it to false, you get a shared VM. Both modes are supported by the plugin and by the Pivot runtime.

        Show
        Greg Brown added a comment - > I verified this page...and confirmed that "counter still goes up" That is the correct behavior. As you note below, when applets share a common VM instance and classloader, all static values are also shared. > the perferred way you use to start all your pivot apps...which is so called "legacy plugin mode", will share all static fields between applet invocations There is no "preferred" way to start Pivot applets. You are free to use the separate_jvm parameter if you want. Also, to my knowledge, there is no such thing as "legacy" plugin mode. If you set separate_jvm to true, the plugin should create a separate JVM instance, though it may not. If you omit separate_jvm or set it to false, you get a shared VM. Both modes are supported by the plugin and by the Pivot runtime.
        Hide
        Andrei Pozolotin added a comment -

        re: AP: "org.apache.pivot.wtk.ApplicationContext$DisplayHost.paintVolatileBuffered locking"
        re: GB: "due to the plugin implementation on Linux."
        yes; I verified paintVolatileBuffered locking is specific to linux

        Show
        Andrei Pozolotin added a comment - re: AP: "org.apache.pivot.wtk.ApplicationContext$DisplayHost.paintVolatileBuffered locking" re: GB: "due to the plugin implementation on Linux." yes; I verified paintVolatileBuffered locking is specific to linux
        Hide
        Andrei Pozolotin added a comment - - edited

        re: "legacy vs next gen"
        http://www.oracle.com/technetwork/java/javase/plugin2-142482.html
        sorry I meant to say "classic vs next gen"; meaning before java 1.6.0_10 and after
        there is no "separate_jvm=true" before that; and after that, if you start in jnlp mode
        still in the same instance of jvm you get different classloader;

        Show
        Andrei Pozolotin added a comment - - edited re: "legacy vs next gen" http://www.oracle.com/technetwork/java/javase/plugin2-142482.html sorry I meant to say "classic vs next gen"; meaning before java 1.6.0_10 and after there is no "separate_jvm=true" before that; and after that, if you start in jnlp mode still in the same instance of jvm you get different classloader;
        Hide
        Andrei Pozolotin added a comment -

        Greg:

        re: "There is no "preferred" way to start Pivot applets." yes, you right, good point.

        except on macosx they already "preferred" if for you: this applet: (with separate_jvm:true)
        http://www.carrotgarden.com:8080/webstart-carrot-bug-pivot-applet-static-staging/index-applet-mac.jsp
        does load new jvm instance on linux, but on mac you first need to go to control panel
        and change java plugin mode to what I call "V2 or next gen or jnlp mode";
        (else no jdk 6_10 features are available, despite you have 6_24 or watever)

        and you never want to ask your apple customers to do that, right?

        cheers!

        Andrei

        Show
        Andrei Pozolotin added a comment - Greg: re: "There is no "preferred" way to start Pivot applets." yes, you right, good point. except on macosx they already "preferred" if for you: this applet: (with separate_jvm:true) http://www.carrotgarden.com:8080/webstart-carrot-bug-pivot-applet-static-staging/index-applet-mac.jsp does load new jvm instance on linux, but on mac you first need to go to control panel and change java plugin mode to what I call "V2 or next gen or jnlp mode"; (else no jdk 6_10 features are available, despite you have 6_24 or watever) and you never want to ask your apple customers to do that, right? cheers! Andrei
        Hide
        Greg Brown added a comment -

        FWIW, this is one of the reasons we repositioned Pivot as an "IIA" platform when we released version 2. Applets are a pain!

        Show
        Greg Brown added a comment - FWIW, this is one of the reasons we repositioned Pivot as an "IIA" platform when we released version 2. Applets are a pain!
        Hide
        Andrei Pozolotin added a comment -

        oh, man, I almost have my holy applet grail!
        if only your would fix static singeltons and Sandro fix osgi...
        but you not going to to it, because you do not want to make pivot so good that it will kill javafx?

        Show
        Andrei Pozolotin added a comment - oh, man, I almost have my holy applet grail! if only your would fix static singeltons and Sandro fix osgi... but you not going to to it, because you do not want to make pivot so good that it will kill javafx?
        Hide
        Greg Brown added a comment -

        Fixing the classloader issue is probably worth doing, but I'm still not clear on what problem eliminating the use of static fields would solve.

        Show
        Greg Brown added a comment - Fixing the classloader issue is probably worth doing, but I'm still not clear on what problem eliminating the use of static fields would solve.
        Hide
        Andrei Pozolotin added a comment -

        re: "classloader issue is probably worth doing" - great, thank you!
        re: "what problem eliminating the use of static" - fine, I'll be back

        Show
        Andrei Pozolotin added a comment - re: "classloader issue is probably worth doing" - great, thank you! re: "what problem eliminating the use of static" - fine, I'll be back

          People

          • Assignee:
            Sandro Martini
            Reporter:
            Andrei Pozolotin
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:

              Development