< prev index next >

src/java.base/share/classes/jdk/internal/misc/CDS.java

Print this page

  1 /*
  2  * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  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
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any

 24  */
 25 
 26 package jdk.internal.misc;
 27 
 28 import java.io.BufferedReader;
 29 import java.io.File;
 30 import java.io.InputStreamReader;
 31 import java.io.InputStream;
 32 import java.io.IOException;
 33 import java.io.PrintStream;
 34 import java.util.Arrays;
 35 import java.util.ArrayList;
 36 import java.util.List;
 37 import java.util.Map;
 38 import java.util.Objects;
 39 import java.util.stream.Stream;
 40 
 41 import jdk.internal.access.SharedSecrets;
 42 
 43 public class CDS {
 44     private static final boolean isDumpingClassList;
 45     private static final boolean isDumpingArchive;
 46     private static final boolean isSharingEnabled;

 47     private static final boolean isDumpingStaticArchive;


 48     static {
 49         isDumpingClassList = isDumpingClassList0();
 50         isDumpingArchive = isDumpingArchive0();



 51         isSharingEnabled = isSharingEnabled0();
 52         isDumpingStaticArchive = isDumpingArchive && !isSharingEnabled;
 53     }
 54 
 55     /**
 56       * indicator for dumping class list.
 57       */
 58     public static boolean isDumpingClassList() {
 59         return isDumpingClassList;
 60     }
 61 
 62     /**
 63       * Is the VM writing to a (static or dynamic) CDS archive.
 64       */
 65     public static boolean isDumpingArchive() {
 66         return isDumpingArchive;
 67     }
 68 
 69     /**
 70       * Is sharing enabled.
 71       */
 72     public static boolean isSharingEnabled() {
 73         return isSharingEnabled;
 74     }
 75 
 76     /**
 77       * Is dumping static archive.
 78       */
 79     public static boolean isDumpingStaticArchive() {
 80         return isDumpingStaticArchive;
 81     }
 82 
 83     private static native boolean isDumpingClassList0();







 84     private static native boolean isDumpingArchive0();



 85     private static native boolean isSharingEnabled0();


 86     private static native void logLambdaFormInvoker(String line);
 87 
 88     /**
 89      * Initialize archived static fields in the given Class using archived
 90      * values from CDS dump time. Also initialize the classes of objects in
 91      * the archived graph referenced by those fields.
 92      *
 93      * Those static fields remain as uninitialized if there is no mapped CDS
 94      * java heap data or there is any error during initialization of the
 95      * object class in the archived graph.
 96      */
 97     public static native void initializeFromArchive(Class<?> c);
 98 
 99     /**
100      * Ensure that the native representation of all archived java.lang.Module objects
101      * are properly restored.
102      */
103     public static native void defineArchivedModules(ClassLoader platformLoader, ClassLoader systemLoader);
104 
105     /**

110     public static native long getRandomSeedForDumping();
111 
112     /**
113      * log lambda form invoker holder, name and method type
114      */
115     public static void traceLambdaFormInvoker(String prefix, String holder, String name, String type) {
116         if (isDumpingClassList) {
117             logLambdaFormInvoker(prefix + " " + holder + " " + name + " " + type);
118         }
119     }
120 
121     /**
122       * log species
123       */
124     public static void traceSpeciesType(String prefix, String cn) {
125         if (isDumpingClassList) {
126             logLambdaFormInvoker(prefix + " " + cn);
127         }
128     }
129 









130     static final String DIRECT_HOLDER_CLASS_NAME  = "java.lang.invoke.DirectMethodHandle$Holder";
131     static final String DELEGATING_HOLDER_CLASS_NAME = "java.lang.invoke.DelegatingMethodHandle$Holder";
132     static final String BASIC_FORMS_HOLDER_CLASS_NAME = "java.lang.invoke.LambdaForm$Holder";
133     static final String INVOKERS_HOLDER_CLASS_NAME = "java.lang.invoke.Invokers$Holder";
134 
135     private static boolean isValidHolderName(String name) {
136         return name.equals(DIRECT_HOLDER_CLASS_NAME)      ||
137                name.equals(DELEGATING_HOLDER_CLASS_NAME)  ||
138                name.equals(BASIC_FORMS_HOLDER_CLASS_NAME) ||
139                name.equals(INVOKERS_HOLDER_CLASS_NAME);
140     }
141 
142     private static boolean isBasicTypeChar(char c) {
143          return "LIJFDV".indexOf(c) >= 0;
144     }
145 
146     private static boolean isValidMethodType(String type) {
147         String[] typeParts = type.split("_");
148         // check return type (second part)
149         if (typeParts.length != 2 || typeParts[1].length() != 1

  1 /*
  2  * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  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
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any

 24  */
 25 
 26 package jdk.internal.misc;
 27 
 28 import java.io.BufferedReader;
 29 import java.io.File;
 30 import java.io.InputStreamReader;
 31 import java.io.InputStream;
 32 import java.io.IOException;
 33 import java.io.PrintStream;
 34 import java.util.Arrays;
 35 import java.util.ArrayList;
 36 import java.util.List;
 37 import java.util.Map;
 38 import java.util.Objects;
 39 import java.util.stream.Stream;
 40 
 41 import jdk.internal.access.SharedSecrets;
 42 
 43 public class CDS {

 44     private static final boolean isDumpingArchive;
 45     private static final boolean isDumpingClassList;
 46     private static final boolean isDumpingHeap;
 47     private static final boolean isDumpingStaticArchive;
 48     private static final boolean isSharingEnabled;
 49     private static final boolean isTracingDynamicProxy;
 50     static {

 51         isDumpingArchive = isDumpingArchive0();
 52         isDumpingClassList = isDumpingClassList0();
 53         isDumpingHeap = isDumpingHeap0();
 54         isDumpingStaticArchive = isDumpingStaticArchive0();
 55         isSharingEnabled = isSharingEnabled0();
 56         isTracingDynamicProxy = isTracingDynamicProxy0();
 57     }
 58 
 59     /**
 60       * indicator for dumping class list.
 61       */
 62     public static boolean isDumpingClassList() {
 63         return isDumpingClassList;
 64     }
 65 
 66     /**
 67       * Is the VM writing to a (static or dynamic) CDS archive.
 68       */
 69     public static boolean isDumpingArchive() {
 70         return isDumpingArchive;
 71     }
 72 
 73     /**
 74       * Is sharing enabled.
 75       */
 76     public static boolean isSharingEnabled() {
 77         return isSharingEnabled;
 78     }
 79 
 80     /**
 81       * Is dumping static archive.
 82       */
 83     public static boolean isDumpingStaticArchive() {
 84         return isDumpingStaticArchive;
 85     }
 86 
 87     public static boolean isDumpingHeap() {
 88         return isDumpingHeap;
 89     }
 90 
 91     public static boolean isTracingDynamicProxy() {
 92         return isTracingDynamicProxy;
 93     }
 94 
 95     private static native boolean isDumpingArchive0();
 96     private static native boolean isDumpingClassList0();
 97     private static native boolean isDumpingHeap0();
 98     private static native boolean isDumpingStaticArchive0();
 99     private static native boolean isSharingEnabled0();
100     private static native boolean isTracingDynamicProxy0();
101 
102     private static native void logLambdaFormInvoker(String line);
103 
104     /**
105      * Initialize archived static fields in the given Class using archived
106      * values from CDS dump time. Also initialize the classes of objects in
107      * the archived graph referenced by those fields.
108      *
109      * Those static fields remain as uninitialized if there is no mapped CDS
110      * java heap data or there is any error during initialization of the
111      * object class in the archived graph.
112      */
113     public static native void initializeFromArchive(Class<?> c);
114 
115     /**
116      * Ensure that the native representation of all archived java.lang.Module objects
117      * are properly restored.
118      */
119     public static native void defineArchivedModules(ClassLoader platformLoader, ClassLoader systemLoader);
120 
121     /**

126     public static native long getRandomSeedForDumping();
127 
128     /**
129      * log lambda form invoker holder, name and method type
130      */
131     public static void traceLambdaFormInvoker(String prefix, String holder, String name, String type) {
132         if (isDumpingClassList) {
133             logLambdaFormInvoker(prefix + " " + holder + " " + name + " " + type);
134         }
135     }
136 
137     /**
138       * log species
139       */
140     public static void traceSpeciesType(String prefix, String cn) {
141         if (isDumpingClassList) {
142             logLambdaFormInvoker(prefix + " " + cn);
143         }
144     }
145 
146     public static void traceDynamicProxy(ClassLoader loader, String proxyName,
147                                          Class<?>[] interfaces, int accessFlags) {
148         Objects.requireNonNull(proxyName);
149         Objects.requireNonNull(interfaces);
150         logDynamicProxy(loader, proxyName, interfaces, accessFlags);
151     }
152     private static native void logDynamicProxy(ClassLoader loader, String proxyName,
153                                                Class<?>[] interfaces, int accessFlags);
154 
155     static final String DIRECT_HOLDER_CLASS_NAME  = "java.lang.invoke.DirectMethodHandle$Holder";
156     static final String DELEGATING_HOLDER_CLASS_NAME = "java.lang.invoke.DelegatingMethodHandle$Holder";
157     static final String BASIC_FORMS_HOLDER_CLASS_NAME = "java.lang.invoke.LambdaForm$Holder";
158     static final String INVOKERS_HOLDER_CLASS_NAME = "java.lang.invoke.Invokers$Holder";
159 
160     private static boolean isValidHolderName(String name) {
161         return name.equals(DIRECT_HOLDER_CLASS_NAME)      ||
162                name.equals(DELEGATING_HOLDER_CLASS_NAME)  ||
163                name.equals(BASIC_FORMS_HOLDER_CLASS_NAME) ||
164                name.equals(INVOKERS_HOLDER_CLASS_NAME);
165     }
166 
167     private static boolean isBasicTypeChar(char c) {
168          return "LIJFDV".indexOf(c) >= 0;
169     }
170 
171     private static boolean isValidMethodType(String type) {
172         String[] typeParts = type.split("_");
173         // check return type (second part)
174         if (typeParts.length != 2 || typeParts[1].length() != 1
< prev index next >