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

(gc) allocator should disallow creation of arrays with more than 2^27-1 elements

XMLWordPrintable

    • 1.2beta4
    • sparc
    • solaris_2.6
    • Not verified

      Jdk1.2, jdk1.1.5

      The problem:

      I allocate a byte array of size 483183813, later I try to access
      element 483183812 and I get:

      java.lang.ArrayIndexOutOfBoundsException: 483183812
      at memtest.main(memtest.java:14)

      This also happened for a byte array of size 536870904.

      It did not happen for a byte array of size 104857592 and 1048568.

      The Program:

      import java.lang.*;

      class memtest {
            public static void main(String args[]) {
               byte buf[];
      long max;
      int maxmem;
      Runtime rt = Runtime.getRuntime();
      max = rt.totalMemory();
               System.out.println("max " + max);
      maxmem = (int) (max * .9);
               System.out.println("maxmem " + maxmem);
               buf = new byte[maxmem];
               buf[maxmem - 1] = 3;
               System.out.println("maxmem " + maxmem);
            }
      }
                      

      The run:

      illium% javac -O memtest.java
      illium% !/bin
      /bin/time java -Xms512M -Xmx1024M memtest
      max 536870904
      maxmem 483183813
      java.lang.ArrayIndexOutOfBoundsException: 483183812
      at memtest.main(memtest.java:14)

      real 7:15.2
      user 9.4
      sys 11.0

      The second program:

      import java.lang.*;

      class memtest1 {
            public static void main(String args[]) {
               byte buf[];
      long max;
      int maxmem;
      Runtime rt = Runtime.getRuntime();
      max = rt.totalMemory();
               System.out.println("max " + max);
      maxmem = (int) max;
               System.out.println("maxmem " + maxmem);
               buf = new byte[maxmem];
      for (int i = 0; i < maxmem;i++) {
                buf[i] = (byte) 3;
      }
               System.out.println("maxmem " + maxmem);
            }
      }
                      
      Runs of the second program:

      illium% !!
      /bin/time java -Xms256M -Xmx1024M memtest1
      max 268435448
      maxmem 268435448
      java.lang.ArrayIndexOutOfBoundsException: 134217720
      at memtest1.main(memtest1.java:15)

      real 7:01.2
      user 2:03.2
      sys 6.9
      [1] + Done hotjava
      illium% ^256^130
      /bin/time java -Xms130M -Xmx1024M memtest1
      max 136314872
      maxmem 136314872
      java.lang.ArrayIndexOutOfBoundsException: 2097144
      at memtest1.main(memtest1.java:15)

      real 37.7
      user 3.7
      sys 2.2

      The environment:

      illium% which java
      /usr/local/java/jdk1.2/solaris/bin/java
      illium% which javac
      /usr/local/java/jdk1.2/solaris/bin/javac


      Machine hardware: sun4u
      OS version: 5.6
      Processor type: sparc
      Hardware: SUNW,Ultra-1

      illium% ls /var/sadm/patch
      105214-01 105223-01 105375-03 105397-01 105416-01 105492-01 105529-01
      105216-01 105356-01 105379-01 105405-01 105464-01 105516-01
      105222-01 105357-01 105393-01 105407-01 105472-01 105528-01

      MANPATH=/usr/man:/usr/openwin/share/man:/usr/dt/man
      DTDATABASESEARCHPATH=/home/jstampfl/.dt/types/fp_dynamic,/home/jstampfl/.dt/types,/etc/dt/appconfig/types/%L,/etc/dt/appconfig/types/C,/usr/dist/pkgs/cue/menus/std/cde/actions/types/%L,/usr/dist/pkgs/cue/menus/std/cde/actions/types/C,/usr/dt/appconfig/types/%L,/usr/dt/appconfig/types/C
      DTXSERVERLOCATION=local
      LANG=C
      HELPPATH=/usr/openwin/lib/locale:/usr/openwin/lib/help
      DTSOURCEPROFILE=true
      PATH=.:/usr/ccs/bin:/usr/openwin/bin:/jstampfl/slidetool/bin:/jstampfl/bin:/jstampfl/java/HotJava1.1/bin:/usr/local/java/jdk1.2/solaris/bin:/usr/bin:/usr/dist/share/devpro,v4.2/5.x-sparc/bin:.:/usr/ccs/bin:/usr/openwin/bin:/jstampfl/slidetool/bin:/jstampfl/bin:/jstampfl/java/HotJava1.1/bin:/usr/local/java/jdk1.2/solaris/bin:/usr/bin:/usr/dist/share/devpro,v4.2/5.x-sparc/bin:/home/jstampfl/bin:/usr/dt/bin:/usr/openwin/bin:/usr/lib/lp/postscript:/usr/bin:/usr/sbin:/sbin:/usr/dist/local/exe:/usr/dist/exe:/usr/ucb:/usr/local/bin:.
      AB_CARDCATALOG=/usr/dt/share/answerbooks/C/ab_cardcatalog
      DTUSERSESSION=jstampfl-illium-0
      XMICONBMSEARCHPATH=/home/jstampfl/.dt/icons/%B%M.bm:/home/jstampfl/.dt/icons/%B%M.pm:/home/jstampfl/.dt/icons/%B:/usr/dist/pkgs/cue/menus/std/cde/actions/icons/%L/%B%M.bm:/usr/dist/pkgs/cue/menus/std/cde/actions/icons/%L/%B%M.pm:/usr/dist/pkgs/cue/menus/std/cde/actions/icons/%L/%B:/usr/dist/pkgs/cue/menus/std/cde/actions/icons/C/%B%M.bm:/usr/dist/pkgs/cue/menus/std/cde/actions/icons/C/%B%M.pm:/usr/dist/pkgs/cue/menus/std/cde/actions/icons/C/%B:/usr/dt/appconfig/icons/%L/%B%M.bm:/usr/dt/appconfig/icons/%L/%B%M.pm:/usr/dt/appconfig/icons/%L/%B:/usr/dt/appconfig/icons/C/%B%M.bm:/usr/dt/appconfig/icons/C/%B%M.pm:/usr/dt/appconfig/icons/C/%B
      SESSION_SVR=illium
      OPENWINHOME=/usr/openwin
      EDITOR=vi
      LOGNAME=jstampfl
      DTSCREENSAVERLIST=StartDtscreenSwarm StartDtscreenQix StartDtscreenFlame StartDtscreenHop StartDtscreenImage StartDtscreenLife StartDtscreenRotor StartDtscreenPyro StartDtscreenWorm StartDtscreenBlank
      MAIL=/var/mail/jstampfl
      USER=jstampfl
      DISPLAY=:0.0
      SHELL=/bin/csh
      FROM_CUE=1
      DTAPPSEARCHPATH=/home/jstampfl/.dt/appmanager:/etc/dt/appconfig/appmanager/%L:/etc/dt/appconfig/appmanager/C:/usr/dist/pkgs/cue/menus/std/cde/actions/appmanager/%L:/usr/dist/pkgs/cue/menus/std/cde/actions/appmanager/C:/usr/dt/appconfig/appmanager/%L:/usr/dt/appconfig/appmanager/C
      HOME=/home/jstampfl
      XFILESEARCHPATH=/usr/openwin/lib/locale/%L/%T/%N%S:/usr/openwin/lib/%T/%N%S:/usr/dist/local/lib/%T/%N%S
      XMICONSEARCHPATH=/home/jstampfl/.dt/icons/%B%M.pm:/home/jstampfl/.dt/icons/%B%M.bm:/home/jstampfl/.dt/icons/%B:/usr/dist/pkgs/cue/menus/std/cde/actions/icons/%L/%B%M.pm:/usr/dist/pkgs/cue/menus/std/cde/actions/icons/%L/%B%M.bm:/usr/dist/pkgs/cue/menus/std/cde/actions/icons/%L/%B:/usr/dist/pkgs/cue/menus/std/cde/actions/icons/C/%B%M.pm:/usr/dist/pkgs/cue/menus/std/cde/actions/icons/C/%B%M.bm:/usr/dist/pkgs/cue/menus/std/cde/actions/icons/C/%B:/usr/dt/appconfig/icons/%L/%B%M.pm:/usr/dt/appconfig/icons/%L/%B%M.bm:/usr/dt/appconfig/icons/%L/%B:/usr/dt/appconfig/icons/C/%B%M.pm:/usr/dt/appconfig/icons/C/%B%M.bm:/usr/dt/appconfig/icons/C/%B
      DTSPSYSAPPHOSTS=/usr/dist/pkgs/cue/menus/std/cde/actions
      TERM=sun-cmd
      dtstart_sessionlogfile=/dev/console
      TZ=US/Pacific
      DTHELPSEARCHPATH=/home/jstampfl/.dt/help/jstampfl-illium-0/%H:/home/jstampfl/.dt/help/jstampfl-illium-0/%H.sdl:/home/jstampfl/.dt/help/jstampfl-illium-0/%H.hv:/home/jstampfl/.dt/help/%H:/home/jstampfl/.dt/help/%H.sdl:/home/jstampfl/.dt/help/%H.hv:/usr/dt/appconfig/help/%L/%H:/usr/dt/appconfig/help/%L/%H.sdl:/usr/dt/appconfig/help/%L/%H.hv:/usr/dt/appconfig/help/C/%H:/usr/dt/appconfig/help/C/%H.sdl:/usr/dt/appconfig/help/C/%H.hv
      XMBINDDIR=/usr/dt/lib/bindings
      CUE=/usr/dist/pkgs/cue,v2.0.0
      CUE_USERLEVEL=advanced
      CUE_HOSTNAME=illium
      DOMAIN=javasoft.eng.sun.com
      NNTPSERVER=engnews2
      JAVAHOME=/usr/local/java/jdk1.2/solaris
      HOTJAVAHOME=/jstampfl/java/HotJava1.1
      THREADS_FLAG=native
      CLASSPATH=.:/usr/local/java/jdk1.2/solaris/lib/classes.zip:/usr/dist/share/netscape,v4.02/java/classes/
      CUE_VERSION=2.0.0
      CUE_OSNAME=SunOS
      CUE_OSVERSION=5.6
      CUE_OSMAJVERSION=5
      CUE_ARCHTYPE=sparc
      CUE_NETLINK=1
      NPHOME=/usr/dist/pkgs/newsprint
      PATH_EXCLUDE=.
      ISOFAXHOME=/usr/dist/pkgs/isofax/solaris
      LPDEST=sangria
      CUE_SEMANTICS=POSIX
      LD_LIBRARY_PATH=/usr/dt/lib:/usr/openwin/lib:/usr/lib
      OLWMMENU=/usr/dist/pkgs/cue/menus/std/ol/Default-Menu
      XINITRC=/usr/dist/pkgs/cue/env/std/Xinitrc
      PWD=/jstampfl/java/mem
      WINDOW_TERMIOS=
      TERMCAP=sun-cmd:te=\E[>4h:ti=\E[>4l:tc=sun:

      illium% swap -l
      swapfile dev swaplo blocks free
      /dev/dsk/c0t0d0s1 32,1 16 615584 489296
      /SWAP - 16 1048560 1030240

            sliangsunw Sheng Liang (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: