Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4276441

Classic VM smashs Thread.threadLocals

XMLWordPrintable

    • kestrel
    • generic, sparc
    • generic, solaris_1, solaris_2.6

      The package private field "threadLocals" of java.lang.Thread
      appears to be getting smashed to null by the classic VM.

      This field is used by java.lang.ThreadLocal to implement
      thread local variables.

      -----
      class Oops {
          static public void main(String[] args) {
              new ThreadLocal().get();
          }
      }
      -----
      % /usr/local/java/jdk1.3/solaris/bin/java -classic Oops
      Exception in thread "main" java.lang.NullPointerException
              at java.lang.ThreadLocal.get(ThreadLocal.java:83)
              at Oops.main(Oops.java:3)
      -----

      This will effect many things including some String constructors:

      class Oops {
          static public void main(String[] args) {
              try {
                  new String(new byte[5], 0, 5, "UTF8");
              } catch(java.io.UnsupportedEncodingException e) {
                  System.err.println(e);
              }
          }
      }
      -----
      % /usr/local/java/jdk1.3/solaris/bin/java -classic Oops
      Exception in thread "main" java.lang.NullPointerException
              at java.lang.ThreadLocal.get(ThreadLocal.java:83)
              at java.lang.String.getBTCConverter(String.java:124)
              at java.lang.String.<init>(String.java:403)
              at Oops.main(Oops.java:4)
      -----

      Does not fail under HotSpot. Only tested under Solaris.

      % /usr/local/java/jdk1.3/solaris/bin/java -hotspot Oops
      %
      % /usr/local/java/jdk1.3/solaris/bin/java -classic -version
      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-H)
      Classic VM (build 1.3.0-H, green threads, nojit)
      -----

      VM is deemed at fault since this field is initialized to a map:

      Thread.java:159: Map threadLocals = Collections.EMPTY_MAP;

      And only set in two places (both to maps):

      ThreadLocal.java:86: map = ourThread.threadLocals = new HashMap(INITIAL_CAPACITY);
      ThreadLocal.java:106: map = ourThread.threadLocals = new HashMap(INITIAL_CAPACITY);

      Also Thread has definitely been initialized, in fact it is
      the current Thread.

      robert.field@Eng 1999-09-28

            hongzh Hong Zhang
            rfield Robert Field (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: