Пример #1
0
 static boolean atBugLevel(String bl) { // package-private
   if (bugLevel == null) {
     if (!sun.misc.VM.isBooted()) return false;
     String value = AccessController.doPrivileged(new GetPropertyAction("sun.nio.ch.bugLevel"));
     bugLevel = (value != null) ? value : "";
   }
   return bugLevel.equals(bl);
 }
Пример #2
0
 /**
  * Invoke at VM initialization time to disable the critical error message box.
  *
  * <p>The critial error message box is disabled unless the system property
  * <tt>sun.io.allowCriticalErrorMessageBox</tt> is set to something other than <code>false</code>.
  * This includes the empty string.
  *
  * <p>This method does nothing if invoked after VM and class library initialization has completed.
  */
 public static void initialize() {
   if (!sun.misc.VM.isBooted()) {
     String s = (String) System.getProperty("sun.io.allowCriticalErrorMessageBox");
     if (s == null || s.equals(Boolean.FALSE.toString())) {
       long mode = setErrorMode(0);
       mode |= SEM_FAILCRITICALERRORS;
       setErrorMode(mode);
     }
   }
 }
 /*     */ private Reference<? extends T> reallyPoll() {
   /*  75 */ if (this.head != null) {
     /*  76 */ Reference localReference = this.head;
     /*  77 */ this.head = (localReference.next == localReference ? null : localReference.next);
     /*  78 */ localReference.queue = NULL;
     /*  79 */ localReference.next = localReference;
     /*  80 */ this.queueLength -= 1L;
     /*  81 */ if ((localReference instanceof FinalReference)) {
       /*  82 */ VM.addFinalRefCount(-1);
       /*     */ }
     /*  84 */ return localReference;
     /*     */ }
   /*  86 */ return null;
   /*     */ }
 /*     */ boolean enqueue(Reference<? extends T> paramReference) {
   /*  58 */ synchronized (paramReference) {
     /*  59 */ if (paramReference.queue == ENQUEUED) return false;
     /*  60 */ synchronized (this.lock) {
       /*  61 */ paramReference.queue = ENQUEUED;
       /*  62 */ paramReference.next = (this.head == null ? paramReference : this.head);
       /*  63 */ this.head = paramReference;
       /*  64 */ this.queueLength += 1L;
       /*  65 */ if ((paramReference instanceof FinalReference)) {
         /*  66 */ VM.addFinalRefCount(1);
         /*     */ }
       /*  68 */ this.lock.notifyAll();
       /*  69 */ return true;
       /*     */ }
     /*     */ }
   /*     */ }
Пример #5
0
  /**
   * Rehashes the contents of this map into a new array with a larger capacity. This method is
   * called automatically when the number of keys in this map reaches its threshold.
   *
   * <p>If current capacity is MAXIMUM_CAPACITY, this method does not resize the map, but sets
   * threshold to Integer.MAX_VALUE. This has the effect of preventing future calls.
   *
   * @param newCapacity the new capacity, MUST be a power of two; must be greater than current
   *     capacity unless current capacity is MAXIMUM_CAPACITY (in which case value is irrelevant).
   */
  void resize(int newCapacity) {
    Entry[] oldTable = table;
    int oldCapacity = oldTable.length;
    if (oldCapacity == MAXIMUM_CAPACITY) {
      threshold = Integer.MAX_VALUE;
      return;
    }

    Entry[] newTable = new Entry[newCapacity];
    boolean oldAltHashing = useAltHashing;
    useAltHashing |=
        sun.misc.VM.isBooted() && (newCapacity >= Holder.ALTERNATIVE_HASHING_THRESHOLD);
    boolean rehash = oldAltHashing ^ useAltHashing;
    transfer(newTable, rehash);
    table = newTable;
    threshold = (int) Math.min(newCapacity * loadFactor, MAXIMUM_CAPACITY + 1);
  }
Пример #6
0
  /**
   * Constructs an empty <tt>HashMap</tt> with the specified initial capacity and load factor.
   *
   * @param initialCapacity the initial capacity
   * @param loadFactor the load factor
   * @throws IllegalArgumentException if the initial capacity is negative or the load factor is
   *     nonpositive
   */
  public HashMap(int initialCapacity, float loadFactor) {
    if (initialCapacity < 0)
      throw new IllegalArgumentException("Illegal initial capacity: " + initialCapacity);
    if (initialCapacity > MAXIMUM_CAPACITY) initialCapacity = MAXIMUM_CAPACITY;
    if (loadFactor <= 0 || Float.isNaN(loadFactor))
      throw new IllegalArgumentException("Illegal load factor: " + loadFactor);

    // Find a power of 2 >= initialCapacity
    int capacity = 1;
    while (capacity < initialCapacity) capacity <<= 1;

    this.loadFactor = loadFactor;
    threshold = (int) Math.min(capacity * loadFactor, MAXIMUM_CAPACITY + 1);
    table = new Entry[capacity];
    useAltHashing = sun.misc.VM.isBooted() && (capacity >= Holder.ALTERNATIVE_HASHING_THRESHOLD);
    init();
  }
Пример #7
0
  /** Reconstitute the {@code HashMap} instance from a stream (i.e., deserialize it). */
  private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException {
    // Read in the threshold (ignored), loadfactor, and any hidden stuff
    s.defaultReadObject();
    if (loadFactor <= 0 || Float.isNaN(loadFactor))
      throw new InvalidObjectException("Illegal load factor: " + loadFactor);

    // set hashSeed (can only happen after VM boot)
    Holder.UNSAFE.putIntVolatile(
        this, Holder.HASHSEED_OFFSET, sun.misc.Hashing.randomHashSeed(this));

    // Read in number of buckets and allocate the bucket array;
    s.readInt(); // ignored

    // Read number of mappings
    int mappings = s.readInt();
    if (mappings < 0) throw new InvalidObjectException("Illegal mappings count: " + mappings);

    int initialCapacity =
        (int)
            Math.min(
                // capacity chosen by number of mappings
                // and desired load (if >= 0.25)
                mappings * Math.min(1 / loadFactor, 4.0f),
                // we have limits...
                HashMap.MAXIMUM_CAPACITY);
    int capacity = 1;
    // find smallest power of two which holds all mappings
    while (capacity < initialCapacity) {
      capacity <<= 1;
    }

    table = new Entry[capacity];
    threshold = (int) Math.min(capacity * loadFactor, MAXIMUM_CAPACITY + 1);
    useAltHashing = sun.misc.VM.isBooted() && (capacity >= Holder.ALTERNATIVE_HASHING_THRESHOLD);

    init(); // Give subclass a chance to do its thing.

    // Read the keys and values, and put the mappings in the HashMap
    for (int i = 0; i < mappings; i++) {
      K key = (K) s.readObject();
      V value = (V) s.readObject();
      putForCreate(key, value);
    }
  }
Пример #8
0
  /** Initialize the system class. Called after thread initialization. */
  private static void initializeSystemClass() {

    // VM might invoke JNU_NewStringPlatform() to set those encoding
    // sensitive properties (user.home, user.name, boot.class.path, etc.)
    // during "props" initialization, in which it may need access, via
    // System.getProperty(), to the related system encoding property that
    // have been initialized (put into "props") at early stage of the
    // initialization. So make sure the "props" is available at the
    // very beginning of the initialization and all system properties to
    // be put into it directly.
    props = new Properties();
    initProperties(props); // initialized by the VM

    // There are certain system configurations that may be controlled by
    // VM options such as the maximum amount of direct memory and
    // Integer cache size used to support the object identity semantics
    // of autoboxing.  Typically, the library will obtain these values
    // from the properties set by the VM.  If the properties are for
    // internal implementation use only, these properties should be
    // removed from the system properties.
    //
    // See java.lang.Integer.IntegerCache and the
    // sun.misc.VM.saveAndRemoveProperties method for example.
    //
    // Save a private copy of the system properties object that
    // can only be accessed by the internal implementation.  Remove
    // certain system properties that are not intended for public access.
    sun.misc.VM.saveAndRemoveProperties(props);

    lineSeparator = props.getProperty("line.separator");
    sun.misc.Version.init();

    FileInputStream fdIn = new FileInputStream(FileDescriptor.in);
    FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
    FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err);
    setIn0(new BufferedInputStream(fdIn));
    setOut0(new PrintStream(new BufferedOutputStream(fdOut, 128), true));
    setErr0(new PrintStream(new BufferedOutputStream(fdErr, 128), true));
    // Load the zip library now in order to keep java.util.zip.ZipFile
    // from trying to use itself to load this library later.
    loadLibrary("zip");

    // Setup Java signal handlers for HUP, TERM, and INT (where available).
    Terminator.setup();

    // Initialize any miscellenous operating system settings that need to be
    // set for the class libraries. Currently this is no-op everywhere except
    // for Windows where the process-wide error mode is set before the java.io
    // classes are used.
    sun.misc.VM.initializeOSEnvironment();

    // The main thread is not added to its thread group in the same
    // way as other threads; we must do it ourselves here.
    Thread current = Thread.currentThread();
    current.getThreadGroup().add(current);

    // register shared secrets
    setJavaLangAccess();

    // Subsystems that are invoked during initialization can invoke
    // sun.misc.VM.isBooted() in order to avoid doing things that should
    // wait until the application class loader has been set up.
    // IMPORTANT: Ensure that this remains the last initialization action!
    sun.misc.VM.booted();
  }
  private synchronized String getStackTrace() {
    if (stackTrace == null) {
      boolean gotoSourceAvailable =
          heapFragmentWalker.getHeapDumpProject() != null && GoToSource.isAvailable();
      StringBuilder sb = new StringBuilder();
      Heap h = heapFragmentWalker.getHeapFragment();
      Collection<GCRoot> roots = h.getGCRoots();
      Map<ThreadObjectGCRoot, Map<Integer, List<JavaFrameGCRoot>>> javaFrameMap =
          computeJavaFrameMap(roots);
      // Use this to enable VisualVM color scheme for threads dumps:
      // sw.append("<pre style='color: #cc3300;'>"); // NOI18N
      sb.append("<pre>"); // NOI18N
      for (GCRoot root : roots) {
        if (root.getKind().equals(GCRoot.THREAD_OBJECT)) {
          ThreadObjectGCRoot threadRoot = (ThreadObjectGCRoot) root;
          Instance threadInstance = threadRoot.getInstance();
          if (threadInstance != null) {
            String threadName = getThreadName(threadInstance);
            Boolean daemon = (Boolean) threadInstance.getValueOfField("daemon"); // NOI18N
            Integer priority = (Integer) threadInstance.getValueOfField("priority"); // NOI18N
            Long threadId = (Long) threadInstance.getValueOfField("tid"); // NOI18N
            Integer threadStatus =
                (Integer) threadInstance.getValueOfField("threadStatus"); // NOI18N
            StackTraceElement stack[] = threadRoot.getStackTrace();
            Map<Integer, List<JavaFrameGCRoot>> localsMap = javaFrameMap.get(threadRoot);
            String style = "";

            if (threadRoot.equals(oome)) {
              style = "style=\"color: #FF0000\"";
            }
            // --- Use this to enable VisualVM color scheme for threads dumps: ---
            // sw.append("&nbsp;&nbsp;<span style=\"color: #0033CC\">"); // NOI18N
            sb.append("&nbsp;&nbsp;<a name=")
                .append(threadInstance.getInstanceId())
                .append("></a><b ")
                .append(style)
                .append(">"); // NOI18N
            // -------------------------------------------------------------------
            sb.append("\"")
                .append(htmlize(threadName))
                .append("\"")
                .append(daemon.booleanValue() ? " daemon" : "")
                .append(" prio=")
                .append(priority); // NOI18N
            if (threadId != null) {
              sb.append(" tid=").append(threadId); // NOI18N
            }
            if (threadStatus != null) {
              State tState = sun.misc.VM.toThreadState(threadStatus.intValue());
              sb.append(" ").append(tState); // NOI18N
            }
            // --- Use this to enable VisualVM color scheme for threads dumps: ---
            // sw.append("</span><br>"); // NOI18N
            sb.append("</b><br>"); // NOI18N
            // -------------------------------------------------------------------
            if (stack != null) {
              for (int i = 0; i < stack.length; i++) {
                String stackElHref;
                StackTraceElement stackElement = stack[i];
                String stackElementText = htmlize(stackElement.toString());

                if (gotoSourceAvailable) {
                  String className = stackElement.getClassName();
                  String method = stackElement.getMethodName();
                  int lineNo = stackElement.getLineNumber();
                  String stackUrl =
                      OPEN_THREADS_URL + className + "|" + method + "|" + lineNo; // NOI18N

                  // --- Use this to enable VisualVM color scheme for threads dumps: ---
                  // stackElHref = "&nbsp;&nbsp;<a style=\"color: #CC3300;\"
                  // href=\""+stackUrl+"\">"+stackElement+"</a>"; // NOI18N
                  stackElHref =
                      "<a href=\"" + stackUrl + "\">" + stackElementText + "</a>"; // NOI18N
                  // -------------------------------------------------------------------
                } else {
                  stackElHref = stackElementText;
                }
                sb.append("\tat ").append(stackElHref).append("<br>"); // NOI18N
                if (localsMap != null) {
                  List<JavaFrameGCRoot> locals = localsMap.get(Integer.valueOf(i));

                  if (locals != null) {
                    for (JavaFrameGCRoot localVar : locals) {
                      Instance localInstance = localVar.getInstance();

                      if (localInstance != null) {
                        sb.append("\t   Local Variable: ")
                            .append(printInstance(localInstance))
                            .append("<br>"); // NOI18N
                      } else {
                        sb.append(
                            "\t   Unknown Local Variable<br>"); // NOI18N
                      }
                    }
                  }
                }
              }
            }
          } else {
            sb.append("&nbsp;&nbsp;Unknown thread"); // NOI18N
          }
          sb.append("<br>"); // NOI18N
        }
      }
      sb.append("</pre>"); // NOI18N
      stackTrace = sb.toString();
    }
    return stackTrace;
  }