597
598 static int pageSize() {
599 if (pageSize == -1)
600 pageSize = unsafe().pageSize();
601 return pageSize;
602 }
603
604 static int pageCount(long size) {
605 return (int)(size + (long)pageSize() - 1L) / pageSize();
606 }
607
608 private static boolean unaligned;
609 private static boolean unalignedKnown = false;
610
611 static boolean unaligned() {
612 if (unalignedKnown)
613 return unaligned;
614 String arch = AccessController.doPrivileged(
615 new sun.security.action.GetPropertyAction("os.arch"));
616 unaligned = arch.equals("i386") || arch.equals("x86")
617 || arch.equals("amd64") || arch.equals("x86_64");
618 unalignedKnown = true;
619 return unaligned;
620 }
621
622
623 // -- Direct memory management --
624
625 // A user-settable upper limit on the maximum amount of allocatable
626 // direct buffer memory. This value may be changed during VM
627 // initialization if it is launched with "-XX:MaxDirectMemorySize=<size>".
628 private static volatile long maxMemory = VM.maxDirectMemory();
629 private static final AtomicLong reservedMemory = new AtomicLong();
630 private static final AtomicLong totalCapacity = new AtomicLong();
631 private static final AtomicLong count = new AtomicLong();
632 private static volatile boolean memoryLimitSet = false;
633 // max. number of sleeps during try-reserving with exponentially
634 // increasing delay before throwing OutOfMemoryError:
635 // 1, 2, 4, 8, 16, 32, 64, 128, 256 (total 511 ms ~ 0.5 s)
636 // which means that OOME will be thrown after 0.5 s of trying
637 private static final int MAX_SLEEPS = 9;
|
597
598 static int pageSize() {
599 if (pageSize == -1)
600 pageSize = unsafe().pageSize();
601 return pageSize;
602 }
603
604 static int pageCount(long size) {
605 return (int)(size + (long)pageSize() - 1L) / pageSize();
606 }
607
608 private static boolean unaligned;
609 private static boolean unalignedKnown = false;
610
611 static boolean unaligned() {
612 if (unalignedKnown)
613 return unaligned;
614 String arch = AccessController.doPrivileged(
615 new sun.security.action.GetPropertyAction("os.arch"));
616 unaligned = arch.equals("i386") || arch.equals("x86")
617 || arch.equals("amd64") || arch.equals("x86_64")
618 || arch.equals("aarch64");
619 unalignedKnown = true;
620 return unaligned;
621 }
622
623
624 // -- Direct memory management --
625
626 // A user-settable upper limit on the maximum amount of allocatable
627 // direct buffer memory. This value may be changed during VM
628 // initialization if it is launched with "-XX:MaxDirectMemorySize=<size>".
629 private static volatile long maxMemory = VM.maxDirectMemory();
630 private static final AtomicLong reservedMemory = new AtomicLong();
631 private static final AtomicLong totalCapacity = new AtomicLong();
632 private static final AtomicLong count = new AtomicLong();
633 private static volatile boolean memoryLimitSet = false;
634 // max. number of sleeps during try-reserving with exponentially
635 // increasing delay before throwing OutOfMemoryError:
636 // 1, 2, 4, 8, 16, 32, 64, 128, 256 (total 511 ms ~ 0.5 s)
637 // which means that OOME will be thrown after 0.5 s of trying
638 private static final int MAX_SLEEPS = 9;
|