src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZPageTable.java
changeset 53815 46ce458df412
parent 50525 767cdb97f103
child 54095 8b4a1177202d
equal deleted inserted replaced
53814:eff915f3d3f2 53815:46ce458df412
     1 /*
     1 /*
     2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    21  * questions.
    21  * questions.
    22  *
    22  *
    23  */
    23  */
    24 
    24 
    25 package sun.jvm.hotspot.gc.z;
    25 package sun.jvm.hotspot.gc.z;
       
    26 
       
    27 import java.util.Iterator;
    26 
    28 
    27 import sun.jvm.hotspot.debugger.Address;
    29 import sun.jvm.hotspot.debugger.Address;
    28 import sun.jvm.hotspot.runtime.VM;
    30 import sun.jvm.hotspot.runtime.VM;
    29 import sun.jvm.hotspot.runtime.VMObject;
    31 import sun.jvm.hotspot.runtime.VMObject;
    30 import sun.jvm.hotspot.runtime.VMObjectFactory;
    32 import sun.jvm.hotspot.runtime.VMObjectFactory;
    61     }
    63     }
    62 
    64 
    63     boolean is_relocating(Address o) {
    65     boolean is_relocating(Address o) {
    64         return getEntry(o).relocating();
    66         return getEntry(o).relocating();
    65     }
    67     }
       
    68 
       
    69     private class ZPagesIterator implements Iterator<ZPage> {
       
    70         private ZAddressRangeMapForPageTable.Iterator mapIter;
       
    71         private ZPage next;
       
    72 
       
    73         ZPagesIterator() {
       
    74             mapIter = map().new Iterator();
       
    75             positionToNext();
       
    76         }
       
    77 
       
    78         private ZPage positionToNext() {
       
    79             ZPage current = next;
       
    80 
       
    81             // Find next
       
    82             ZPage found = null;
       
    83             while (mapIter.hasNext()) {
       
    84                 ZPageTableEntry entry = new ZPageTableEntry(mapIter.next());
       
    85                 if (!entry.isEmpty()) {
       
    86                     ZPage page = entry.page();
       
    87                     // Medium pages have repeated entries for all covered slots,
       
    88                     // therefore we need to compare against the current page.
       
    89                     if (page != null && !page.equals(current)) {
       
    90                         found = page;
       
    91                         break;
       
    92                     }
       
    93                 }
       
    94             }
       
    95 
       
    96             next = found;
       
    97 
       
    98             return current;
       
    99         }
       
   100 
       
   101         @Override
       
   102         public boolean hasNext() {
       
   103             return next != null;
       
   104         }
       
   105 
       
   106         @Override
       
   107         public ZPage next() {
       
   108             return positionToNext();
       
   109         }
       
   110 
       
   111         @Override
       
   112         public void remove() {
       
   113             /* not supported */
       
   114         }
       
   115     }
       
   116 
       
   117     abstract class ZPageFilter {
       
   118         public abstract boolean accept(ZPage page);
       
   119     }
       
   120 
       
   121     class ZPagesFilteredIterator implements Iterator<ZPage> {
       
   122         private ZPage next;
       
   123         private ZPagesIterator iter = new ZPagesIterator();
       
   124         private ZPageFilter filter;
       
   125 
       
   126         ZPagesFilteredIterator(ZPageFilter filter) {
       
   127             this.filter = filter;
       
   128             positionToNext();
       
   129         }
       
   130 
       
   131         public ZPage positionToNext() {
       
   132             ZPage current = next;
       
   133 
       
   134             // Find next
       
   135             ZPage found = null;
       
   136             while (iter.hasNext()) {
       
   137                 ZPage page = iter.next();
       
   138                 if (filter.accept(page)) {
       
   139                     found = page;
       
   140                     break;
       
   141                 }
       
   142             }
       
   143 
       
   144             next = found;
       
   145 
       
   146             return current;
       
   147         }
       
   148 
       
   149         @Override
       
   150         public boolean hasNext() {
       
   151             return next != null;
       
   152         }
       
   153 
       
   154         @Override
       
   155         public ZPage next() {
       
   156             return positionToNext();
       
   157         }
       
   158 
       
   159         @Override
       
   160         public void remove() {
       
   161             /* not supported */
       
   162         }
       
   163     }
       
   164 
       
   165     public Iterator<ZPage> iterator() {
       
   166         return new ZPagesIterator();
       
   167     }
       
   168 
       
   169     public Iterator<ZPage> activePagesIterator() {
       
   170         return new ZPagesFilteredIterator(new ZPageFilter() {
       
   171             public boolean accept(ZPage page) {
       
   172                 return page.is_active();
       
   173             }
       
   174         });
       
   175     }
    66 }
   176 }