Path: blob/master/jcl/src/java.base/share/classes/java/lang/System.java
12513 views
/*[INCLUDE-IF Sidecar18-SE]*/1/*******************************************************************************2* Copyright (c) 1998, 2022 IBM Corp. and others3*4* This program and the accompanying materials are made available under5* the terms of the Eclipse Public License 2.0 which accompanies this6* distribution and is available at https://www.eclipse.org/legal/epl-2.0/7* or the Apache License, Version 2.0 which accompanies this distribution and8* is available at https://www.apache.org/licenses/LICENSE-2.0.9*10* This Source Code may also be made available under the following11* Secondary Licenses when the conditions for such availability set12* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU13* General Public License, version 2 with the GNU Classpath14* Exception [1] and GNU General Public License, version 2 with the15* OpenJDK Assembly Exception [2].16*17* [1] https://www.gnu.org/software/classpath/license.html18* [2] http://openjdk.java.net/legal/assembly-exception.html19*20* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception21*******************************************************************************/22package java.lang;2324import java.io.*;25/*[IF Sidecar18-SE-OpenJ9 | JAVA_SPEC_VERSION >= 11]*/26import java.nio.charset.Charset;27/*[ENDIF] Sidecar18-SE-OpenJ9 | JAVA_SPEC_VERSION >= 11 */28import java.util.Map;29import java.util.Properties;30import java.util.PropertyPermission;31import java.security.*;32import java.lang.reflect.Method;33import java.lang.reflect.Constructor;3435/*[IF Sidecar19-SE]*/36import jdk.internal.misc.Unsafe;37/*[IF JAVA_SPEC_VERSION >= 12]*/38import jdk.internal.access.SharedSecrets;39/*[ELSE] JAVA_SPEC_VERSION >= 1240import jdk.internal.misc.SharedSecrets;41/*[ENDIF] JAVA_SPEC_VERSION >= 12 */42import jdk.internal.misc.VM;43import java.lang.StackWalker.Option;44import jdk.internal.reflect.Reflection;45import jdk.internal.reflect.CallerSensitive;46import java.util.*;47import java.util.function.*;48/*[ELSE]49import sun.misc.Unsafe;50import sun.misc.SharedSecrets;51import sun.misc.VM;52import sun.reflect.CallerSensitive;53/*[ENDIF]*/54/*[IF Sidecar19-SE]*/55import com.ibm.gpu.spi.GPUAssist;56import com.ibm.gpu.spi.GPUAssistHolder;57/*[ENDIF] Sidecar19-SE */58/*[IF PLATFORM-mz31 | PLATFORM-mz64 | !Sidecar18-SE-OpenJ9]*/59import com.ibm.jvm.io.ConsolePrintStream;60/*[ENDIF] PLATFORM-mz31 | PLATFORM-mz64 | !Sidecar18-SE-OpenJ9 */6162/**63* Class System provides a standard place for programs64* to find system related information. All System API65* is static.66*67* @author OTI68* @version initial69*/70public final class System {7172// The standard input, output, and error streams.73// Typically, these are connected to the shell which74// ran the Java program.75/**76* Default input stream77*/78public static final InputStream in = null;79/**80* Default output stream81*/82public static final PrintStream out = null;83/**84* Default error output stream85*/86public static final PrintStream err = null;87/*[IF JAVA_SPEC_VERSION >= 17] */88// The initial err to print SecurityManager related warning messages89static PrintStream initialErr;90// Show only one setSecurityManager() warning message for each caller91private static Map<Class<?>, Object> setSMCallers;92/*[ENDIF] JAVA_SPEC_VERSION >= 17 */9394/*[IF JAVA_SPEC_VERSION > 11] */95/**96* setSecurityManager() should throw UnsupportedOperationException97* if throwUOEFromSetSM is set to true.98*/99private static boolean throwUOEFromSetSM;100/*[ENDIF] JAVA_SPEC_VERSION > 11 */101102//Get a ref to the Runtime instance for faster lookup103private static final Runtime RUNTIME = Runtime.getRuntime();104/**105* The System Properties table.106*/107private static Properties systemProperties;108109/**110* The System default SecurityManager.111*/112private static SecurityManager security;113114private static volatile Console console;115private static volatile boolean consoleInitialized;116117private static String lineSeparator;118119private static boolean propertiesInitialized;120121private static String platformEncoding;122private static String fileEncoding;123private static String osEncoding;124125private static final int sysPropID_PlatformEncoding = 1;126private static final int sysPropID_FileEncoding = 2;127private static final int sysPropID_OSEncoding = 3;128/*[IF JAVA_SPEC_VERSION >= 17]*/129private static final int sysPropID_OSVersion = 0;130private static final String sysPropOSVersion;131/*[ENDIF] JAVA_SPEC_VERSION >= 17 */132133/*[IF JAVA_SPEC_VERSION >= 11]*/134private static boolean hasSetErrEncoding;135private static boolean hasSetOutEncoding;136private static String consoleDefaultEncoding;137/* The consoleDefaultCharset is different from the default console encoding when the encoding138* doesn't exist, or isn't available at startup. Some Charset's are not available in the139* java.base module and so are not used at startup.140*/141private static Charset consoleDefaultCharset;142/*[ENDIF] JAVA_SPEC_VERSION >= 11 */143144/*[IF Sidecar19-SE]*/145static java.lang.ModuleLayer bootLayer;146/*[ENDIF]*/147148// Initialize all the slots in System on first use.149static {150/* Get following system properties in clinit and make it available via static variables151* at early boot stage in which System is not fully initialized152* os.version, os.encoding, ibm.system.encoding/sun.jnu.encoding, file.encoding153*/154/*[IF JAVA_SPEC_VERSION >= 17]*/155sysPropOSVersion = getSysPropBeforePropertiesInitialized(sysPropID_OSVersion);156/*[ENDIF] JAVA_SPEC_VERSION >= 17 */157platformEncoding = getSysPropBeforePropertiesInitialized(sysPropID_PlatformEncoding);158String definedOSEncoding = getSysPropBeforePropertiesInitialized(sysPropID_OSEncoding);159/*[IF JAVA_SPEC_VERSION >= 18]*/160/* -Dfile.encoding=COMPAT is mapped to platform encoding within getSysPropBeforePropertiesInitialized.161* During early VM boot stage, JITHelpers hasn't been initialized yet, COMPACT_STRINGS related APIs162* might not work properly.163*/164/*[ENDIF] JAVA_SPEC_VERSION >= 18 */165String definedFileEncoding = getSysPropBeforePropertiesInitialized(sysPropID_FileEncoding);166if (definedFileEncoding != null) {167fileEncoding = definedFileEncoding;168// if file.encoding is defined, and os.encoding is not, use the detected169// platform encoding for os.encoding170if (definedOSEncoding == null) {171osEncoding = platformEncoding;172}173} else {174fileEncoding = platformEncoding;175}176// if os.encoding is not defined, file.encoding will be used177if (osEncoding == null) {178osEncoding = definedOSEncoding;179}180}181182/*[IF JAVA_SPEC_VERSION >= 11]*/183/*184* Return the Charset of the primary or when fallback is true, the default console encoding,185* if different from the default console Charset.186*187* consoleDefaultCharset must be initialized before calling.188* consoleDefaultEncoding must be initialized before calling with fallback set to true.189*/190static Charset getCharset(String primary, boolean fallback) {191if (primary != null) {192try {193Charset newCharset = Charset.forName(primary);194if (newCharset.equals(consoleDefaultCharset)) {195return null;196} else {197return newCharset;198}199} catch (IllegalArgumentException e) {200// ignore unsupported or invalid encodings201}202}203if (fallback && (consoleDefaultEncoding != null)) {204try {205Charset newCharset = Charset.forName(consoleDefaultEncoding);206if (newCharset.equals(consoleDefaultCharset)) {207return null;208} else {209return newCharset;210}211} catch (IllegalArgumentException e) {212// ignore unsupported or invalid encodings213}214}215return null;216}217218/*219* Return if sun.stderr.encoding was used.220*/221static boolean hasSetErrEncoding() {222return hasSetErrEncoding;223}224225/*226* Return if sun.stdout.encoding was used.227*/228static boolean hasSetOutEncoding() {229return hasSetOutEncoding;230}231232/*233* Return the appropriate System console using the requested Charset.234* If the Charset is null use the default console Charset.235*236* consoleDefaultCharset must be initialized before calling.237*/238static PrintStream createConsole(FileDescriptor desc, Charset charset) {239BufferedOutputStream bufStream = new BufferedOutputStream(new FileOutputStream(desc));240Charset consoleCharset = charset == null ? consoleDefaultCharset : charset;241/*[IF PLATFORM-mz31 | PLATFORM-mz64]*/242return ConsolePrintStream.localize(bufStream, true, consoleCharset);243/*[ELSE]*/244return new PrintStream(bufStream, true, consoleCharset);245/*[ENDIF] PLATFORM-mz31 | PLATFORM-mz64 */246}247/*[ELSE]*/248/*[IF Sidecar18-SE-OpenJ9]*/249/*250* Return the Charset name of the primary encoding, if different from the default.251*/252private static String getCharsetName(String primary, Charset defaultCharset) {253if (primary != null) {254try {255Charset newCharset = Charset.forName(primary);256if (newCharset.equals(defaultCharset)) {257return null;258} else {259return newCharset.name();260}261} catch (IllegalArgumentException e) {262// ignore unsupported or invalid encodings263}264}265return null;266}267268/*269* Return the appropriate System console using the pre-validated encoding.270*/271private static PrintStream createConsole(FileDescriptor desc, String encoding) {272BufferedOutputStream bufStream = new BufferedOutputStream(new FileOutputStream(desc));273if (encoding == null) {274return new PrintStream(bufStream, true);275} else {276try {277return new PrintStream(bufStream, true, encoding);278} catch (UnsupportedEncodingException e) {279// not possible when the Charset name is validated first280throw new InternalError("For encoding " + encoding, e); //$NON-NLS-1$281}282}283}284/*[ELSE]*/285/*286* Return the appropriate System console.287*/288private static PrintStream createConsole(FileDescriptor desc) {289return ConsolePrintStream.localize(new BufferedOutputStream(new FileOutputStream(desc)), true);290}291/*[ENDIF] Sidecar18-SE-OpenJ9 */292/*[ENDIF] JAVA_SPEC_VERSION >= 11 */293294static void afterClinitInitialization() {295/*[PR CMVC 189091] Perf: EnumSet.allOf() is slow */296/*[PR CMVC 191554] Provide access to ClassLoader methods to improve performance */297/* Multitenancy change: only initialize VMLangAccess once as it's non-isolated */298if (null == com.ibm.oti.vm.VM.getVMLangAccess()) {299com.ibm.oti.vm.VM.setVMLangAccess(new VMAccess());300}301302// Fill in the properties from the VM information.303ensureProperties(true);304305/*[PR CMVC 150472] sun.misc.SharedSecrets needs access to java.lang. */306SharedSecrets.setJavaLangAccess(new Access());307308/*[IF JAVA_SPEC_VERSION >= 11]*/309initJCLPlatformEncoding();310/*[ENDIF] JAVA_SPEC_VERSION >= 11 */311312/*[REM] Initialize the JITHelpers needed in J9VMInternals since the class can't do it itself */313try {314java.lang.reflect.Field f1 = J9VMInternals.class.getDeclaredField("jitHelpers"); //$NON-NLS-1$315java.lang.reflect.Field f2 = String.class.getDeclaredField("helpers"); //$NON-NLS-1$316317Unsafe unsafe = Unsafe.getUnsafe();318319unsafe.putObject(unsafe.staticFieldBase(f1), unsafe.staticFieldOffset(f1), com.ibm.jit.JITHelpers.getHelpers());320unsafe.putObject(unsafe.staticFieldBase(f2), unsafe.staticFieldOffset(f2), com.ibm.jit.JITHelpers.getHelpers());321} catch (NoSuchFieldException e) { }322323/*[IF JAVA_SPEC_VERSION < 17]*/324/**325* When the System Property == true, then disable sharing (i.e. arraycopy the underlying value array) in326* String.substring(int) and String.substring(int, int) methods whenever offset is zero. Otherwise, enable327* sharing of the underlying value array.328*/329String enableSharingInSubstringWhenOffsetIsZeroProperty = internalGetProperties().getProperty("java.lang.string.substring.nocopy"); //$NON-NLS-1$330String.enableSharingInSubstringWhenOffsetIsZero = enableSharingInSubstringWhenOffsetIsZeroProperty == null || enableSharingInSubstringWhenOffsetIsZeroProperty.equalsIgnoreCase("false"); //$NON-NLS-1$331332// Set up standard in, out, and err.333/*[PR CMVC 193070] - OTT:Java 8 Test_JITHelpers test_getSuperclass NoSuchMet*/334/*[PR JAZZ 58297] - continue with the rules defined by JAZZ 57070 - Build a Java 8 J9 JCL using the SIDECAR18 preprocessor configuration */335// Check the default encoding336/*[Bug 102075] J2SE Setting -Dfile.encoding=junk fails to run*/337/*[IF JAVA_SPEC_VERSION >= 11]*/338StringCoding.encode(String.LATIN1, new byte[1]);339/*[ELSE]*/340StringCoding.encode(new char[1], 0, 1);341/*[ENDIF] JAVA_SPEC_VERSION >= 11 */342/*[ENDIF] JAVA_SPEC_VERSION < 17 */343344/*[IF Sidecar18-SE-OpenJ9]*/345Properties props = internalGetProperties();346/*[IF JAVA_SPEC_VERSION >= 11]*/347/*[IF JAVA_SPEC_VERSION >= 18]*/348consoleDefaultCharset = Charset.forName(props.getProperty("native.encoding"), sun.nio.cs.US_ASCII.INSTANCE);349/*[ELSE] JAVA_SPEC_VERSION >= 18 */350consoleDefaultCharset = Charset.defaultCharset();351/*[ENDIF] JAVA_SPEC_VERSION >= 18 */352/*[IF PLATFORM-mz31|PLATFORM-mz64]*/353try {354consoleDefaultEncoding = props.getProperty("console.encoding"); //$NON-NLS-1$355if (consoleDefaultEncoding == null) {356consoleDefaultEncoding = props.getProperty("ibm.system.encoding"); //$NON-NLS-1$357}358consoleDefaultCharset = Charset.forName(consoleDefaultEncoding); //$NON-NLS-1$359} catch (IllegalArgumentException e) {360// use the defaultCharset()361}362/*[ELSE] PLATFORM-mz31|PLATFORM-mz64 */363/*[IF JAVA_SPEC_VERSION >= 18]*/364consoleDefaultEncoding = props.getProperty("native.encoding"); //$NON-NLS-1$365/*[ELSE] JAVA_SPEC_VERSION >= 18 */366consoleDefaultEncoding = props.getProperty("file.encoding"); //$NON-NLS-1$367/*[ENDIF] JAVA_SPEC_VERSION >= 18 */368/*[ENDIF] PLATFORM-mz31|PLATFORM-mz64 */369/* consoleDefaultCharset must be initialized before calling getCharset() */370Charset stdoutCharset = getCharset(props.getProperty("sun.stdout.encoding"), false); //$NON-NLS-1$371Charset stderrCharset = getCharset(props.getProperty("sun.stderr.encoding"), false); //$NON-NLS-1$372/*[ELSE] JAVA_SPEC_VERSION >= 11 */373Charset consoleCharset = Charset.defaultCharset();374String stdoutCharset = getCharsetName(props.getProperty("sun.stdout.encoding"), consoleCharset); //$NON-NLS-1$375String stderrCharset = getCharsetName(props.getProperty("sun.stderr.encoding"), consoleCharset); //$NON-NLS-1$376/*[ENDIF] JAVA_SPEC_VERSION >= 11 */377/*[ENDIF] Sidecar18-SE-OpenJ9 */378379/*[IF Sidecar18-SE-OpenJ9]*/380/*[IF JAVA_SPEC_VERSION >= 11]*/381if (stderrCharset != null) {382hasSetErrEncoding = true;383}384if (stdoutCharset != null) {385hasSetOutEncoding = true;386}387/* consoleDefaultCharset must be initialized before calling createConsole() */388/*[ENDIF] JAVA_SPEC_VERSION >= 11 */389/*[IF JAVA_SPEC_VERSION >= 17] */390initialErr = createConsole(FileDescriptor.err, stderrCharset);391setErr(initialErr);392/*[ELSE] JAVA_SPEC_VERSION >= 17 */393setErr(createConsole(FileDescriptor.err, stderrCharset));394/*[ENDIF] JAVA_SPEC_VERSION >= 17 */395setOut(createConsole(FileDescriptor.out, stdoutCharset));396/*[IF Sidecar19-SE_RAWPLUSJ9]*/397setIn(new BufferedInputStream(new FileInputStream(FileDescriptor.in)));398/*[ENDIF] Sidecar19-SE_RAWPLUSJ9 */399/*[ELSE]*/400/*[PR s66168] - ConsoleInputStream initialization may write to System.err */401/*[PR s73550, s74314] ConsolePrintStream incorrectly initialized */402setErr(createConsole(FileDescriptor.err));403setOut(createConsole(FileDescriptor.out));404/*[ENDIF] Sidecar18-SE-OpenJ9 */405406/*[IF JAVA_SPEC_VERSION >= 17] */407setSMCallers = Collections.synchronizedMap(new WeakHashMap<>());408/*[ENDIF] JAVA_SPEC_VERSION >= 17 */409}410411native static void startSNMPAgent();412413static void completeInitialization() {414/*[IF !Sidecar19-SE_RAWPLUSJ9]*/415/*[IF !Sidecar18-SE-OpenJ9]*/416Class<?> systemInitialization = null;417Method hook;418try {419/*[PR 167854] - Please note the incorrect name of the class is correct - somewhere the spelling was wrong and we just need to use the incorrect spelling */420/*[IF Sidecar19-SE]*/421systemInitialization = Class.forName("com.ibm.utils.SystemIntialization"); //$NON-NLS-1$422/*[ELSE]*/423systemInitialization = Class.forName("com.ibm.misc.SystemIntialization"); //$NON-NLS-1$424/*[ENDIF]*/425} catch (ClassNotFoundException e) {426// Assume this is a raw configuration and suppress the exception427} catch (Exception e) {428throw new InternalError(e.toString());429}430try {431if (null != systemInitialization) {432hook = systemInitialization.getMethod("firstChanceHook"); //$NON-NLS-1$433hook.invoke(null);434}435} catch (Exception e) {436throw new InternalError(e.toString());437}438/*[ENDIF]*/ // Sidecar18-SE-OpenJ9439440/*[IF (Sidecar18-SE-OpenJ9|Sidecar19-SE)&!(PLATFORM-mz31|PLATFORM-mz64)]*/441setIn(new BufferedInputStream(new FileInputStream(FileDescriptor.in)));442/*[ELSE]*/443/*[PR 100718] Initialize System.in after the main thread*/444setIn(com.ibm.jvm.io.ConsoleInputStream.localize(new BufferedInputStream(new FileInputStream(FileDescriptor.in))));445/*[ENDIF]*/ //Sidecar18-SE-OpenJ9|Sidecar19-SE446/*[ENDIF]*/ //!Sidecar19-SE_RAWPLUSJ9447448/*[PR 102344] call Terminator.setup() after Thread init */449Terminator.setup();450451/*[IF !Sidecar19-SE_RAWPLUSJ9&!Sidecar18-SE-OpenJ9]*/452try {453if (null != systemInitialization) {454hook = systemInitialization.getMethod("lastChanceHook"); //$NON-NLS-1$455hook.invoke(null);456}457} catch (Exception e) {458throw new InternalError(e.toString());459}460/*[ENDIF]*/ //!Sidecar19-SE_RAWPLUSJ9&!Sidecar18-SE-OpenJ9461}462463/*[IF Sidecar19-SE]*/464static void initGPUAssist() {465Properties props = internalGetProperties();466467if ((props.getProperty("com.ibm.gpu.enable") == null) //$NON-NLS-1$468&& (props.getProperty("com.ibm.gpu.enforce") == null) //$NON-NLS-1$469) {470/*471* The CUDA implementation of GPUAssist is not enabled by default:472* one of the above properties must be set.473*/474return;475}476477PrivilegedAction<GPUAssist> finder = new PrivilegedAction<GPUAssist>() {478@Override479public GPUAssist run() {480ServiceLoader<GPUAssist.Provider> loaded = ServiceLoader.load(GPUAssist.Provider.class);481482for (GPUAssist.Provider provider : loaded) {483GPUAssist assist = provider.getGPUAssist();484485if (assist != null) {486return assist;487}488}489490return GPUAssist.NONE;491}492};493494GPUAssistHolder.instance = AccessController.doPrivileged(finder);495}496/*[ENDIF] Sidecar19-SE */497498/**499* Sets the value of the static slot "in" in the receiver500* to the passed in argument.501*502* @param newIn the new value for in.503*/504public static void setIn(InputStream newIn) {505@SuppressWarnings("removal")506SecurityManager security = System.getSecurityManager();507if (security != null) {508security.checkPermission(com.ibm.oti.util.RuntimePermissions.permissionSetIO);509}510511setFieldImpl("in", newIn); //$NON-NLS-1$512}513514/**515* Sets the value of the static slot "out" in the receiver516* to the passed in argument.517*518* @param newOut the new value for out.519*/520public static void setOut(java.io.PrintStream newOut) {521@SuppressWarnings("removal")522SecurityManager security = System.getSecurityManager();523if (security != null) {524security.checkPermission(com.ibm.oti.util.RuntimePermissions.permissionSetIO);525}526setFieldImpl("out", newOut); //$NON-NLS-1$527}528529/**530* Sets the value of the static slot "err" in the receiver531* to the passed in argument.532*533* @param newErr the new value for err.534*/535public static void setErr(java.io.PrintStream newErr) {536@SuppressWarnings("removal")537SecurityManager security = System.getSecurityManager();538if (security != null) {539security.checkPermission(com.ibm.oti.util.RuntimePermissions.permissionSetIO);540}541542setFieldImpl("err", newErr); //$NON-NLS-1$543}544545/**546* Prevents this class from being instantiated.547*/548private System() {549}550551/**552* Copies the contents of <code>array1</code> starting at offset <code>start1</code>553* into <code>array2</code> starting at offset <code>start2</code> for554* <code>length</code> elements.555*556* @param array1 the array to copy out of557* @param start1 the starting index in array1558* @param array2 the array to copy into559* @param start2 the starting index in array2560* @param length the number of elements in the array to copy561*/562public static native void arraycopy(Object array1, int start1, Object array2, int start2, int length);563564/**565* Private version of the arraycopy method used by the jit for reference arraycopies566*/567private static void arraycopy(Object[] A1, int offset1, Object[] A2, int offset2, int length) {568if (A1 == null || A2 == null) throw new NullPointerException();569if (offset1 >= 0 && offset2 >= 0 && length >= 0 &&570length <= A1.length - offset1 && length <= A2.length - offset2)571{572// Check if this is a forward or backwards arraycopy573if (A1 != A2 || offset1 > offset2 || offset1+length <= offset2) {574for (int i = 0; i < length; ++i) {575A2[offset2+i] = A1[offset1+i];576}577} else {578for (int i = length-1; i >= 0; --i) {579A2[offset2+i] = A1[offset1+i];580}581}582} else throw new ArrayIndexOutOfBoundsException();583}584585586/**587* Answers the current time expressed as milliseconds since588* the time 00:00:00 UTC on January 1, 1970.589*590* @return the time in milliseconds.591*/592public static native long currentTimeMillis();593594/*[IF OpenJ9-RawBuild]*/595/* This is a JCL native required only by OpenJ9 raw build.596* OpenJ9 raw build is a combination of OpenJ9 and OpenJDK binaries without JCL patches within extension repo.597* Currently OpenJ9 depends on a JCL patch to initialize platform encoding which is not available to raw build.598* A workaround for raw build is to invoke this JCL native which initializes platform encoding.599* This workaround can be removed if that JCL patch is not required.600*/601private static native Properties initProperties(Properties props);602/*[ENDIF] OpenJ9-RawBuild */603604/**605* If systemProperties is unset, then create a new one based on the values606* provided by the virtual machine.607*/608@SuppressWarnings("nls")609private static void ensureProperties(boolean isInitialization) {610/*[IF OpenJ9-RawBuild]*/611// invoke JCL native to initialize platform encoding612initProperties(new Properties());613/*[ENDIF] OpenJ9-RawBuild */614615/*[IF JAVA_SPEC_VERSION >= 12]*/616Map<String, String> initializedProperties = new Hashtable<String, String>();617/*[ELSE] JAVA_SPEC_VERSION >= 12618Properties initializedProperties = new Properties();619/*[ENDIF] JAVA_SPEC_VERSION >= 12 */620621/*[IF JAVA_SPEC_VERSION >= 17]*/622initializedProperties.put("os.version", sysPropOSVersion); //$NON-NLS-1$623/*[ENDIF] JAVA_SPEC_VERSION >= 17 */624625if (osEncoding != null) {626initializedProperties.put("os.encoding", osEncoding); //$NON-NLS-1$627}628/*[PR The launcher apparently needs sun.jnu.encoding property or it does not work]*/629initializedProperties.put("ibm.system.encoding", platformEncoding); //$NON-NLS-1$630initializedProperties.put("sun.jnu.encoding", platformEncoding); //$NON-NLS-1$631initializedProperties.put("file.encoding.pkg", "sun.io"); //$NON-NLS-1$ //$NON-NLS-2$632/*[IF JAVA_SPEC_VERSION < 12]*/633/* System property java.specification.vendor is set via VersionProps.init(systemProperties) since JDK12 */634initializedProperties.put("java.specification.vendor", "Oracle Corporation"); //$NON-NLS-1$ //$NON-NLS-2$635/*[ENDIF] JAVA_SPEC_VERSION < 12 */636initializedProperties.put("java.specification.name", "Java Platform API Specification"); //$NON-NLS-1$ //$NON-NLS-2$637initializedProperties.put("com.ibm.oti.configuration", "scar"); //$NON-NLS-1$638639/*[IF CRIU_SUPPORT]*/640initializedProperties.put("org.eclipse.openj9.criu.isCRIUCapable", "true"); //$NON-NLS-1$ //$NON-NLS-2$641/*[ENDIF] CRIU_SUPPORT*/642643String[] list = getPropertyList();644for (int i = 0; i < list.length; i += 2) {645String key = list[i];646/*[PR 100209] getPropertyList should use fewer local refs */647if (key == null) {648break;649}650initializedProperties.put(key, list[i+1]);651}652initializedProperties.put("file.encoding", fileEncoding); //$NON-NLS-1$653654/*[IF JAVA_SPEC_VERSION >= 17]*/655/* Set native.encoding after setting all the defined properties, it can't be modified by using -D on the command line */656initializedProperties.put("native.encoding", platformEncoding); //$NON-NLS-1$657/*[ENDIF] JAVA_SPEC_VERSION >= 17 */658659/* java.lang.VersionProps.init() eventually calls into System.setProperty() where propertiesInitialized needs to be true */660propertiesInitialized = true;661662/*[IF JAVA_SPEC_VERSION >= 12]*/663java.lang.VersionProps.init(initializedProperties);664/*[ELSE] JAVA_SPEC_VERSION >= 12665/* VersionProps.init requires systemProperties to be set */666systemProperties = initializedProperties;667668/*[IF Sidecar19-SE]*/669java.lang.VersionProps.init();670/*[ELSE]671sun.misc.Version.init();672673StringBuffer.initFromSystemProperties(systemProperties);674StringBuilder.initFromSystemProperties(systemProperties);675/*[ENDIF] Sidecar19-SE */676/*[ENDIF] JAVA_SPEC_VERSION >= 12 */677678/*[IF JAVA_SPEC_VERSION >= 12]*/679String javaRuntimeVersion = initializedProperties.get("java.runtime.version"); //$NON-NLS-1$680/*[ELSE] JAVA_SPEC_VERSION >= 12681String javaRuntimeVersion = initializedProperties.getProperty("java.runtime.version"); //$NON-NLS-1$682/*[ENDIF] JAVA_SPEC_VERSION >= 12 */683if (null != javaRuntimeVersion) {684/*[IF JAVA_SPEC_VERSION >= 12]*/685String fullVersion = initializedProperties.get("java.fullversion"); //$NON-NLS-1$686/*[ELSE] JAVA_SPEC_VERSION >= 12687String fullVersion = initializedProperties.getProperty("java.fullversion"); //$NON-NLS-1$688/*[ENDIF] JAVA_SPEC_VERSION >= 12 */689if (null != fullVersion) {690initializedProperties.put("java.fullversion", (javaRuntimeVersion + "\n" + fullVersion)); //$NON-NLS-1$ //$NON-NLS-2$691}692rasInitializeVersion(javaRuntimeVersion);693}694695/*[IF JAVA_SPEC_VERSION >= 12]*/696lineSeparator = initializedProperties.getOrDefault("line.separator", "\n"); //$NON-NLS-1$697/*[ELSE] JAVA_SPEC_VERSION >= 12698lineSeparator = initializedProperties.getProperty("line.separator", "\n"); //$NON-NLS-1$699/*[ENDIF] JAVA_SPEC_VERSION >= 12 */700701if (isInitialization) {702/*[PR CMVC 179976] System.setProperties(null) throws IllegalStateException */703/*[IF JAVA_SPEC_VERSION >= 12]*/704VM.saveProperties(initializedProperties);705/*[ELSE] JAVA_SPEC_VERSION >= 12706VM.saveAndRemoveProperties(initializedProperties);707/*[ENDIF] JAVA_SPEC_VERSION >= 12 */708}709710/* create systemProperties from properties Map */711/*[IF JAVA_SPEC_VERSION >= 12]*/712initializeSystemProperties(initializedProperties);713/*[ELSE] JAVA_SPEC_VERSION >= 12714systemProperties = initializedProperties;715/*[ENDIF] JAVA_SPEC_VERSION >= 12 */716717/* Preload system property jdk.serialFilter to prevent later modification */718jdk.internal.util.StaticProperty.jdkSerialFilter();719}720721/* Converts a Map<String, String> to a properties object.722*723* The system properties will be initialized as a Map<String, String> type to be compatible724* with jdk.internal.misc.VM and java.lang.VersionProps APIs.725*/726private static void initializeSystemProperties(Map<String, String> mapProperties) {727systemProperties = new Properties();728for (Map.Entry<String, String> property : mapProperties.entrySet()) {729systemProperties.put(property.getKey(), property.getValue());730}731}732733private static native void rasInitializeVersion(String javaRuntimeVersion);734735/**736* Causes the virtual machine to stop running, and the737* program to exit. If runFinalizersOnExit(true) has been738* invoked, then all finalizers will be run first.739*740* @param code the return code.741*742* @throws SecurityException if the running thread is not allowed to cause the vm to exit.743*744* @see SecurityManager#checkExit745*/746public static void exit(int code) {747RUNTIME.exit(code);748}749750/**751* Indicate to the virtual machine that it would be a752* good time to collect available memory. Note that, this753* is a hint only.754*/755public static void gc() {756RUNTIME.gc();757}758759/*[PR 127013] [JCL Desktop]VM throws runtime exception(no such method signature) when calling System.getenv() function (SPR MXZU76W5R5)*/760/**761* Returns an environment variable.762*763* @param var the name of the environment variable764* @return the value of the specified environment variable765*/766@SuppressWarnings("dep-ann")767public static String getenv(String var) {768if (var == null) throw new NullPointerException();769@SuppressWarnings("removal")770SecurityManager security = System.getSecurityManager();771if (security != null)772security.checkPermission(new RuntimePermission("getenv." + var)); //$NON-NLS-1$773774return ProcessEnvironment.getenv(var);775}776777/**778* Answers the system properties. Note that this is779* not a copy, so that changes made to the returned780* Properties object will be reflected in subsequent781* calls to {@code getProperty()} and {@code getProperties()}.782* <p>783* Security managers should restrict access to this784* API if possible.785*786* @return the system properties787*/788public static Properties getProperties() {789if (!propertiesInitialized) throw new Error("bootstrap error, system property access before init"); //$NON-NLS-1$790@SuppressWarnings("removal")791SecurityManager security = System.getSecurityManager();792if (security != null)793security.checkPropertiesAccess();794795return systemProperties;796}797798/**799* Answers the system properties without any security800* checks. This is used for access from within java.lang.801*802* @return the system properties803*/804static Properties internalGetProperties() {805if (!propertiesInitialized) throw new Error("bootstrap error, system property access before init"); //$NON-NLS-1$806807return systemProperties;808}809/**810* Answers the value of a particular system property.811* Answers null if no such property exists.812* <p>813* The properties currently provided by the virtual814* machine are:815* <pre>816* file.separator817* java.class.path818* java.class.version819* java.home820/*[IF JAVA_SPEC_VERSION < 12]821* java.vendor822* java.vendor.url823/*[ENDIF] JAVA_SPEC_VERSION < 12824* java.version825* line.separator826* os.arch827* os.name828* os.version829* path.separator830* user.dir831* user.home832* user.name833* user.timezone834* </pre>835*836* @param prop the system property to look up837* @return the value of the specified system property, or null if the property doesn't exist838*/839@SuppressWarnings("nls")840public static String getProperty(String prop) {841return getProperty(prop, null);842}843844/**845* Answers the value of a particular system property.846* If no such property is found, answers the defaultValue.847*848* @param prop the system property to look up849* @param defaultValue return value if system property is not found850* @return the value of the specified system property, or defaultValue if the property doesn't exist851*/852public static String getProperty(String prop, String defaultValue) {853if (prop.length() == 0) throw new IllegalArgumentException();854855@SuppressWarnings("removal")856SecurityManager security = System.getSecurityManager();857if (security != null)858security.checkPropertyAccess(prop);859860if (!propertiesInitialized861&& !prop.equals("com.ibm.IgnoreMalformedInput") //$NON-NLS-1$862&& !prop.equals("file.encoding.pkg") //$NON-NLS-1$863&& !prop.equals("sun.nio.cs.map") //$NON-NLS-1$864) {865/*[IF JAVA_SPEC_VERSION >= 17]*/866if (prop.equals("os.version")) { //$NON-NLS-1$867return sysPropOSVersion;868} else869/*[ENDIF] JAVA_SPEC_VERSION >= 17 */870if (prop.equals("os.encoding")) { //$NON-NLS-1$871return osEncoding;872} else if (prop.equals("ibm.system.encoding")) { //$NON-NLS-1$873return platformEncoding;874} else if (prop.equals("file.encoding")) { //$NON-NLS-1$875return fileEncoding;876}877throw new Error("bootstrap error, system property access before init: " + prop); //$NON-NLS-1$878}879880return systemProperties.getProperty(prop, defaultValue);881}882883/**884* Sets the value of a particular system property.885*886* @param prop the system property to change887* @param value the value to associate with prop888* @return the old value of the property, or null889*/890public static String setProperty(String prop, String value) {891if (!propertiesInitialized) throw new Error("bootstrap error, system property access before init: " + prop); //$NON-NLS-1$892893/*[PR CMVC 80288] should check for empty key */894if (prop.length() == 0) throw new IllegalArgumentException();895896@SuppressWarnings("removal")897SecurityManager security = System.getSecurityManager();898if (security != null)899security.checkPermission(900new PropertyPermission(prop, "write")); //$NON-NLS-1$901902return (String)systemProperties.setProperty(prop, value);903}904905/**906* Answers an array of Strings containing key..value pairs907* (in consecutive array elements) which represent the908* starting values for the system properties as provided909* by the virtual machine.910*911* @return the default values for the system properties.912*/913private static native String [] getPropertyList();914915/*[IF JAVA_SPEC_VERSION >= 11]*/916/**917* Invoke JCL native to initialize platform encoding explicitly.918*/919private static native void initJCLPlatformEncoding();920/*[ENDIF] JAVA_SPEC_VERSION >= 11 */921922/**923* Before propertiesInitialized is set to true,924* this returns the requested system property according to sysPropID:925* 0 - os.version926* 1 - platform encoding927* 2 - file.encoding928* 3 - os.encoding929* Reserved for future930*/931private static native String getSysPropBeforePropertiesInitialized(int sysPropID);932933/**934* Answers the active security manager.935*936* @return the system security manager object.937*/938/*[IF (JAVA_SPEC_VERSION >= 17) & OPENJDK_METHODHANDLES] */939@Deprecated(since="17", forRemoval=true)940/*[ENDIF] (JAVA_SPEC_VERSION >= 17) & OPENJDK_METHODHANDLES */941public static SecurityManager getSecurityManager() {942return security;943}944945/**946* Answers an integer hash code for the parameter.947* The hash code returned is the same one that would948* be returned by java.lang.Object.hashCode(), whether949* or not the object's class has overridden hashCode().950* The hash code for null is 0.951*952* @param anObject the object953* @return the hash code for the object954*955* @see java.lang.Object#hashCode956*/957public static int identityHashCode(Object anObject) {958if (anObject == null) {959return 0;960}961return J9VMInternals.fastIdentityHashCode(anObject);962}963964/**965* Loads the specified file as a dynamic library.966*967* @param pathName the path of the file to be loaded968*/969@CallerSensitive970public static void load(String pathName) {971@SuppressWarnings("removal")972SecurityManager smngr = System.getSecurityManager();973if (smngr != null) {974smngr.checkLink(pathName);975}976/*[IF JAVA_SPEC_VERSION >= 15]*/977File fileName = new File(pathName);978if (fileName.isAbsolute()) {979ClassLoader.loadLibrary(getCallerClass(), fileName);980} else {981/*[MSG "K0648", "Not an absolute path: {0}"]*/982throw new UnsatisfiedLinkError(com.ibm.oti.util.Msg.getString("K0648", pathName));//$NON-NLS-1$983}984/*[ELSE]985ClassLoader.loadLibraryWithPath(pathName, ClassLoader.callerClassLoader(), null);986/*[ENDIF] JAVA_SPEC_VERSION >= 15 */987}988989/**990* Loads and links the library specified by the argument.991*992* @param libName the name of the library to load993*994* @throws UnsatisfiedLinkError if the library could not be loaded995* @throws SecurityException if the library was not allowed to be loaded996*/997@CallerSensitive998public static void loadLibrary(String libName) {999@SuppressWarnings("removal")1000SecurityManager smngr = System.getSecurityManager();1001if (smngr != null) {1002smngr.checkLink(libName);1003}1004/*[IF JAVA_SPEC_VERSION >= 15]*/1005ClassLoader.loadLibrary(getCallerClass(), libName);1006/*[ELSE]*/1007ClassLoader.loadLibraryWithClassLoader(libName, ClassLoader.callerClassLoader());1008/*[ENDIF] JAVA_SPEC_VERSION >= 15 */1009}10101011/**1012* Provides a hint to the virtual machine that it would1013* be useful to attempt to perform any outstanding1014* object finalizations.1015*/1016/*[IF JAVA_SPEC_VERSION >= 18] */1017@Deprecated(forRemoval=true, since="18")1018/*[ENDIF] JAVA_SPEC_VERSION >= 18 */1019public static void runFinalization() {1020RUNTIME.runFinalization();1021}10221023/*[IF JAVA_SPEC_VERSION < 11]*/1024/**1025* Ensure that, when the virtual machine is about to exit,1026* all objects are finalized. Note that all finalization1027* which occurs when the system is exiting is performed1028* after all running threads have been terminated.1029*1030* @param flag true means finalize all on exit.1031*1032* @deprecated This method is unsafe.1033*/1034@Deprecated1035public static void runFinalizersOnExit(boolean flag) {1036Runtime.runFinalizersOnExit(flag);1037}1038/*[ENDIF] JAVA_SPEC_VERSION < 11 */10391040/**1041* Sets the system properties. Note that the object which is passed in1042* is not copied, so that subsequent changes made to it will be reflected1043* in calls to {@code getProperty()} and {@code getProperties()}.1044* <p>1045* Security managers should restrict access to this1046* API if possible.1047*1048* @param p the properties to set1049*/1050public static void setProperties(Properties p) {1051@SuppressWarnings("removal")1052SecurityManager security = System.getSecurityManager();1053if (security != null)1054security.checkPropertiesAccess();1055if (p == null) {1056ensureProperties(false);1057} else {1058systemProperties = p;1059}1060}10611062static void initSecurityManager(ClassLoader applicationClassLoader) {1063String javaSecurityManager = internalGetProperties().getProperty("java.security.manager"); //$NON-NLS-1$1064/*[IF JAVA_SPEC_VERSION > 11]*/1065if ("allow".equals(javaSecurityManager)) {1066/* Do nothing. */1067} else if ("disallow".equals(javaSecurityManager) //$NON-NLS-1$1068/*[IF JAVA_SPEC_VERSION >= 18]*/1069|| (null == javaSecurityManager)1070/*[ENDIF] JAVA_SPEC_VERSION >= 18 */1071) {1072throwUOEFromSetSM = true;1073} else1074/*[ENDIF] JAVA_SPEC_VERSION > 11 */1075if (null != javaSecurityManager) {1076/*[IF JAVA_SPEC_VERSION >= 17]*/1077initialErr.println("WARNING: A command line option has enabled the Security Manager"); //$NON-NLS-1$1078initialErr.println("WARNING: The Security Manager is deprecated and will be removed in a future release"); //$NON-NLS-1$1079/*[ENDIF] JAVA_SPEC_VERSION >= 17 */1080if (javaSecurityManager.isEmpty() || "default".equals(javaSecurityManager)) { //$NON-NLS-1$1081setSecurityManager(new SecurityManager());1082} else {1083try {1084Constructor<?> constructor = Class.forName(javaSecurityManager, true, applicationClassLoader).getConstructor();1085constructor.setAccessible(true);1086setSecurityManager((SecurityManager)constructor.newInstance());1087} catch (Throwable e) {1088/*[MSG "K0631", "JVM can't set custom SecurityManager due to {0}"]*/1089throw new Error(com.ibm.oti.util.Msg.getString("K0631", e.toString()), e); //$NON-NLS-1$1090}1091}1092}1093}10941095/**1096* Sets the active security manager. Note that once1097* the security manager has been set, it can not be1098* changed. Attempts to do so will cause a security1099* exception.1100*1101* @param s the new security manager1102*1103* @throws SecurityException if the security manager has already been set and its checkPermission method doesn't allow it to be replaced.1104/*[IF JAVA_SPEC_VERSION >= 12]1105* @throws UnsupportedOperationException if s is non-null and a special token "disallow" has been set for system property "java.security.manager"1106* which indicates that a security manager is not allowed to be set dynamically.1107/*[ENDIF] JAVA_SPEC_VERSION >= 121108*/1109/*[IF JAVA_SPEC_VERSION >= 17] */1110/*[IF OPENJDK_METHODHANDLES] */1111@Deprecated(since="17", forRemoval=true)1112/*[ENDIF] OPENJDK_METHODHANDLES */1113@CallerSensitive1114/*[ENDIF] JAVA_SPEC_VERSION >= 17 */1115public static void setSecurityManager(final SecurityManager s) {1116/*[PR 113606] security field could be modified by another Thread */1117@SuppressWarnings("removal")1118final SecurityManager currentSecurity = security;11191120/*[IF JAVA_SPEC_VERSION > 11]*/1121if (throwUOEFromSetSM) {1122/* The security manager is not allowed to be set dynamically. Return if the1123* argument is null. UnsupportedOperationException should only be thrown for1124* a non-null argument.1125*/1126if (s == null) {1127return;1128}1129/*[MSG "K0B00", "The Security Manager is deprecated and will be removed in a future release"]*/1130throw new UnsupportedOperationException(com.ibm.oti.util.Msg.getString("K0B00")); //$NON-NLS-1$1131}1132/*[ENDIF] JAVA_SPEC_VERSION > 11 */11331134/*[IF JAVA_SPEC_VERSION >= 17] */1135Class<?> callerClz = getCallerClass();1136if (setSMCallers.putIfAbsent(callerClz, Boolean.TRUE) == null) {1137String callerName = callerClz.getName();1138CodeSource cs = callerClz.getProtectionDomainInternal().getCodeSource();1139String codeSource = (cs == null) ? callerName : callerName + " (" + cs.getLocation() + ")"; //$NON-NLS-1$ //$NON-NLS-2$1140initialErr.println("WARNING: A terminally deprecated method in java.lang.System has been called"); //$NON-NLS-1$1141initialErr.printf("WARNING: System::setSecurityManager has been called by %s" + lineSeparator(), codeSource); //$NON-NLS-1$1142initialErr.printf("WARNING: Please consider reporting this to the maintainers of %s" + lineSeparator(), callerName); //$NON-NLS-1$1143initialErr.println("WARNING: System::setSecurityManager will be removed in a future release"); //$NON-NLS-1$1144}1145/*[ENDIF] JAVA_SPEC_VERSION >= 17 */11461147if (s != null) {1148if (currentSecurity == null) {1149// only preload classes when current security manager is null1150// not adding an extra static field to preload only once1151try {1152/*[PR 95057] preload classes required for checkPackageAccess() */1153// Preload classes used for checkPackageAccess(),1154// otherwise we could go recursive1155s.checkPackageAccess("java.lang"); //$NON-NLS-1$1156} catch (Exception e) {1157// ignore any potential exceptions1158}1159}11601161try {1162/*[PR 97686] Preload the policy permission */1163AccessController.doPrivileged(new PrivilegedAction<Void>() {1164@Override1165public Void run() {1166if (currentSecurity == null) {1167// initialize external messages and1168// also load security sensitive classes1169com.ibm.oti.util.Msg.getString("K002c"); //$NON-NLS-1$1170}1171ProtectionDomain pd = s.getClass().getPDImpl();1172if (pd != null) {1173// initialize the protection domain, which may include preloading the1174// dynamic permissions from the policy before installing1175pd.implies(sun.security.util.SecurityConstants.ALL_PERMISSION);1176}1177return null;1178}});1179} catch (Exception e) {1180// ignore any potential exceptions1181}1182}1183if (currentSecurity != null) {1184currentSecurity.checkPermission(com.ibm.oti.util.RuntimePermissions.permissionSetSecurityManager);1185}1186security = s;1187}11881189/**1190* Answers the platform-specific filename for the shared1191* library named by the argument.1192*1193* @param userLibName the name of the library to look up.1194* @return the platform-specific filename for the library1195*/1196public static native String mapLibraryName(String userLibName);11971198/**1199* Sets the value of the named static field in the receiver1200* to the passed in argument.1201*1202* @param fieldName the name of the field to set, one of in, out, or err1203* @param stream the new value of the field1204*/1205private static native void setFieldImpl(String fieldName, Object stream);12061207@CallerSensitive1208static Class getCallerClass() {1209return Class.getStackClass(2);1210}12111212/**1213* Return the channel inherited by the invocation of the running vm. The channel is1214* obtained by calling SelectorProvider.inheritedChannel().1215*1216* @return the inherited channel or null1217*1218* @throws IOException if an IO error occurs getting the inherited channel1219*/1220public static java.nio.channels.Channel inheritedChannel() throws IOException {1221return java.nio.channels.spi.SelectorProvider.provider().inheritedChannel();1222}12231224/**1225* Returns the current tick count in nanoseconds. The tick count1226* only reflects elapsed time.1227*1228* @return the current nanosecond tick count, which may be negative1229*/1230public static native long nanoTime();12311232/**1233* Removes the property.1234*1235* @param prop the name of the property to remove1236* @return the value of the property removed1237*/1238public static String clearProperty(String prop) {1239if (!propertiesInitialized) throw new Error("bootstrap error, system property access before init: " + prop); //$NON-NLS-1$12401241if (prop.length() == 0) throw new IllegalArgumentException();1242@SuppressWarnings("removal")1243SecurityManager security = System.getSecurityManager();1244if (security != null)1245security.checkPermission(new PropertyPermission(prop, "write")); //$NON-NLS-1$1246return (String)systemProperties.remove(prop);1247}12481249/**1250* Returns all of the system environment variables in an unmodifiable Map.1251*1252* @return an unmodifiable Map containing all of the system environment variables.1253*/1254public static Map<String, String> getenv() {1255@SuppressWarnings("removal")1256SecurityManager security = System.getSecurityManager();1257if (security != null)1258security.checkPermission(new RuntimePermission("getenv.*")); //$NON-NLS-1$12591260return ProcessEnvironment.getenv();1261}12621263/**1264* Return the Console or null.1265*1266* @return the Console or null1267*/1268public static Console console() {1269/*[PR CMVC 114090] System.console does not return null in subprocess */1270/*[PR CMVC 114119] Console exists when stdin, stdout are redirected */1271if (consoleInitialized) return console;1272synchronized(System.class) {1273if (consoleInitialized) return console;1274console = SharedSecrets.getJavaIOAccess().console();1275consoleInitialized = true;1276}1277return console;1278}12791280/**1281* JIT Helper method1282*/1283private static void longMultiLeafArrayCopy(Object src, int srcPos,1284Object dest, int destPos, int length, int elementSize, int leafSize) {12851286// Check if this is a forward or backwards arraycopy1287boolean isFwd;1288if (src != dest || srcPos > destPos || srcPos+length <= destPos)1289isFwd = true;1290else1291isFwd = false;12921293int newSrcPos;1294int newDestPos;1295int numOfElemsPerLeaf = leafSize / elementSize;1296int srcLeafPos;1297int destLeafPos;1298int L1, L2, L3;1299int offset;13001301if (isFwd)1302{1303newSrcPos = srcPos;1304newDestPos = destPos;1305}1306else1307{1308newSrcPos = srcPos + length - 1;1309newDestPos = destPos + length - 1;1310}13111312srcLeafPos = newSrcPos % numOfElemsPerLeaf;1313destLeafPos = newDestPos % numOfElemsPerLeaf;1314if (srcLeafPos < destLeafPos)1315{1316if (isFwd)1317{1318// align dst to leaf boundary first1319L1 = numOfElemsPerLeaf - destLeafPos;1320L2 = numOfElemsPerLeaf - (srcLeafPos + L1);1321}1322else1323{1324L1 = srcLeafPos + 1;1325L2 = destLeafPos - srcLeafPos;1326}1327}1328else1329{1330if (isFwd)1331{1332// align src to leaf boundary first1333L1 = numOfElemsPerLeaf - srcLeafPos;1334L2 = numOfElemsPerLeaf - (destLeafPos + L1);1335}1336else1337{1338L1 = destLeafPos + 1;1339L2 = srcLeafPos - destLeafPos;1340}1341}13421343L3 = numOfElemsPerLeaf - L2;13441345// begin copying1346offset = isFwd ? 0 : L1 - 1;1347System.arraycopy(src, newSrcPos - offset, dest, newDestPos - offset, L1);1348newSrcPos = isFwd ? newSrcPos + L1 : newSrcPos - L1;1349newDestPos = isFwd ? newDestPos + L1 : newDestPos - L1;1350length -= L1;13511352// now one of newSrcPos and newDestPos is aligned on an arraylet1353// leaf boundary, so copies of L2 and L3 can be repeated until there1354// is less than a full leaf left to copy1355while (length >= numOfElemsPerLeaf) {1356offset = isFwd ? 0 : L2 - 1;1357System.arraycopy(src, newSrcPos - offset, dest, newDestPos - offset, L2);1358newSrcPos = isFwd ? newSrcPos + L2 : newSrcPos - L2;1359newDestPos = isFwd ? newDestPos + L2 : newDestPos - L2;13601361offset = isFwd ? 0 : L3 - 1;1362System.arraycopy(src, newSrcPos - offset, dest, newDestPos - offset, L3);1363newSrcPos = isFwd ? newSrcPos + L3 : newSrcPos - L3;1364newDestPos = isFwd ? newDestPos + L3 : newDestPos - L3;13651366length -= numOfElemsPerLeaf;1367}13681369// next L2 elements of each array must be on same leaf1370if (length > L2) {1371offset = isFwd ? 0 : L2 - 1;1372System.arraycopy(src, newSrcPos - offset, dest, newDestPos - offset, L2);1373newSrcPos = isFwd ? newSrcPos + L2 : newSrcPos - L2;1374newDestPos = isFwd ? newDestPos + L2 : newDestPos - L2;1375length -= L2;1376}13771378// whatever is left of each array must be on the same leaf1379if (length > 0) {1380offset = isFwd ? 0 : length - 1;1381System.arraycopy(src, newSrcPos - offset, dest, newDestPos - offset, length);1382}1383}13841385/**1386* JIT Helper method1387*/1388private static void simpleMultiLeafArrayCopy(Object src, int srcPos,1389Object dest, int destPos, int length, int elementSize, int leafSize)1390{1391int count = 0;13921393// Check if this is a forward or backwards arraycopy1394boolean isFwd;1395if (src != dest || srcPos > destPos || srcPos+length <= destPos)1396isFwd = true;1397else1398isFwd = false;13991400int newSrcPos;1401int newDestPos;1402int numOfElemsPerLeaf = leafSize / elementSize;1403int srcLeafPos;1404int destLeafPos;1405int iterLength;14061407if (isFwd)1408{1409newSrcPos = srcPos;1410newDestPos = destPos;1411}1412else1413{1414newSrcPos = srcPos + length - 1;1415newDestPos = destPos + length - 1;1416}14171418for (count = 0; count < length; count += iterLength)1419{1420srcLeafPos = (newSrcPos % numOfElemsPerLeaf);1421destLeafPos = newDestPos % numOfElemsPerLeaf;1422int offset;1423if ((isFwd && (srcLeafPos >= destLeafPos)) ||1424(!isFwd && (srcLeafPos < destLeafPos)))1425{1426if (isFwd)1427iterLength = numOfElemsPerLeaf - srcLeafPos;1428else1429iterLength = srcLeafPos + 1;1430}1431else1432{1433if (isFwd)1434iterLength = numOfElemsPerLeaf - destLeafPos;1435else1436iterLength = destLeafPos + 1;1437}14381439if (length - count < iterLength)1440iterLength = length - count;14411442if (isFwd)1443offset = 0;1444else1445offset = iterLength - 1;14461447System.arraycopy(src, newSrcPos - offset, dest, newDestPos - offset, iterLength);14481449if (isFwd)1450{1451newSrcPos += iterLength;1452newDestPos += iterLength;1453}1454else1455{1456newSrcPos -= iterLength;1457newDestPos -= iterLength;1458}1459}1460}14611462/**1463* JIT Helper method1464*/1465private static void multiLeafArrayCopy(Object src, int srcPos, Object dest,1466int destPos, int length, int elementSize, int leafSize) {1467int count = 0;14681469// Check if this is a forward or backwards arraycopy1470boolean isFwd;1471if (src != dest || srcPos > destPos || srcPos+length <= destPos)1472isFwd = true;1473else1474isFwd = false;14751476int newSrcPos;1477int newDestPos;1478int numOfElemsPerLeaf = leafSize / elementSize;1479int srcLeafPos;1480int destLeafPos;14811482if (isFwd)1483{1484newSrcPos = srcPos;1485newDestPos = destPos;1486}1487else1488{1489newSrcPos = srcPos + length - 1;1490newDestPos = destPos + length - 1;1491}14921493int iterLength1 = 0;1494int iterLength2 = 0;1495while (count < length)1496{1497srcLeafPos = (newSrcPos % numOfElemsPerLeaf);1498destLeafPos = (newDestPos % numOfElemsPerLeaf);14991500int firstPos, secondPos;15011502if ((isFwd && (srcLeafPos >= destLeafPos)) ||1503(!isFwd && (srcLeafPos < destLeafPos)))1504{1505firstPos = srcLeafPos;1506secondPos = newDestPos;1507}1508else1509{1510firstPos = destLeafPos;1511secondPos = newSrcPos;1512}15131514int offset = 0;1515if (isFwd)1516iterLength1 = numOfElemsPerLeaf - firstPos;1517else1518iterLength1 = firstPos + 1;15191520if (length - count < iterLength1)1521iterLength1 = length - count;15221523if (isFwd)1524iterLength2 = numOfElemsPerLeaf - ((secondPos + iterLength1) % numOfElemsPerLeaf);1525else1526{1527iterLength2 = ((secondPos - iterLength1) % numOfElemsPerLeaf) + 1;1528offset = iterLength1 - 1;1529}15301531if (length - count - iterLength1 < iterLength2)1532iterLength2 = length - count - iterLength1;15331534System.arraycopy(src, newSrcPos - offset, dest, newDestPos - offset, iterLength1);15351536offset = 0;1537if (isFwd)1538{1539newSrcPos += iterLength1;1540newDestPos += iterLength1;1541}1542else1543{1544newSrcPos -= iterLength1;1545newDestPos -= iterLength1;1546offset = iterLength2 - 1;1547}15481549if (iterLength2 <= 0) break;15501551System.arraycopy(src, newSrcPos - offset, dest, newDestPos - offset, iterLength2);15521553if (isFwd)1554{1555newSrcPos += iterLength2;1556newDestPos += iterLength2;1557}1558else1559{1560newSrcPos -= iterLength2;1561newDestPos -= iterLength2;1562}15631564count += iterLength1 + iterLength2;1565}1566}156715681569/**1570* Return platform specific line separator character(s).1571* Unix is \n while Windows is \r\n as per the prop set by the VM.1572*1573* @return platform specific line separator string1574*/1575// Refer to Jazz 308751576public static String lineSeparator() {1577return lineSeparator;1578}15791580/*[IF Sidecar19-SE]*/1581/**1582* Return an instance of Logger.1583*1584* @param loggerName The name of the logger to return1585* @return An instance of the logger.1586* @throws NullPointerException if the loggerName is null1587*/1588@CallerSensitive1589public static Logger getLogger(String loggerName) {1590Objects.requireNonNull(loggerName);1591Class<?> caller = Reflection.getCallerClass();1592return jdk.internal.logger.LazyLoggers.getLogger(loggerName, caller.getModule());1593}15941595/**1596* Return an instance of Logger that is localized based on the ResourceBundle.1597*1598* @param loggerName The name of the logger to return1599* @param bundle The ResourceBundle to use for localization1600* @return An instance of the logger localized to 'bundle'1601* @throws NullPointerException if the loggerName or bundle is null1602*/1603@CallerSensitive1604public static Logger getLogger(String loggerName, ResourceBundle bundle) {1605Objects.requireNonNull(loggerName);1606Objects.requireNonNull(bundle);1607Class<?> caller = Reflection.getCallerClass();1608return LoggerFinder.getLoggerFinder().getLocalizedLogger(loggerName, bundle, caller.getModule());1609}16101611/**1612* The LoggerFinder service creates, manages and configures loggers1613* to the underlying framework it uses.1614*/1615public abstract static class LoggerFinder {1616private static volatile LoggerFinder loggerFinder;16171618/**1619* Checks needed runtime permissions1620*1621* @throws SecurityException if RuntimePermission("loggerFinder") is not allowed1622*/1623protected LoggerFinder() {1624verifyPermissions();1625}16261627/**1628* Returns a localizable instance of Logger for the given module1629*1630* @param loggerName The name of the logger1631* @param bundle A resource bundle; can be null1632* @param callerModule The module for which the logger is being requested1633* @return an instance of Logger1634* @throws NullPointerException if loggerName or callerModule is null1635* @throws SecurityException if RuntimePermission("loggerFinder") is not allowed1636*/1637public Logger getLocalizedLogger(String loggerName, ResourceBundle bundle, Module callerModule) {1638verifyPermissions();1639Objects.requireNonNull(loggerName);1640Objects.requireNonNull(callerModule);1641Logger logger = this.getLogger(loggerName, callerModule);1642Logger localizedLogger = new jdk.internal.logger.LocalizedLoggerWrapper(logger, bundle);1643return localizedLogger;1644}16451646/**1647* Returns an instance of Logger for the given module1648*1649* @param loggerName The name of the logger1650* @param callerModule The module for which the logger is being requested1651* @return a Logger suitable for use within the given module1652* @throws NullPointerException if loggerName or callerModule is null1653* @throws SecurityException if RuntimePermission("loggerFinder") is not allowed1654*/1655public abstract Logger getLogger(String loggerName, Module callerModule);16561657/**1658* Returns the LoggerFinder instance1659*1660* @return the LoggerFinder instance.1661* @throws SecurityException if RuntimePermission("loggerFinder") is not allowed1662*/1663public static LoggerFinder getLoggerFinder() {1664verifyPermissions();1665if (loggerFinder == null) {1666loggerFinder = AccessController.doPrivileged(1667(PrivilegedAction<LoggerFinder>) () -> jdk.internal.logger.LoggerFinderLoader.getLoggerFinder(),1668AccessController.getContext(),1669com.ibm.oti.util.RuntimePermissions.permissionLoggerFinder);1670}1671return loggerFinder;1672}16731674private static void verifyPermissions() {1675@SuppressWarnings("removal")1676SecurityManager securityManager = System.getSecurityManager();1677if (securityManager != null) {1678securityManager.checkPermission(com.ibm.oti.util.RuntimePermissions.permissionLoggerFinder);1679}1680}1681}16821683/**1684* Logger logs messages that will be routed to the underlying logging framework1685* that LoggerFinder uses.1686*/1687public interface Logger {1688/**1689* System loggers levels1690*/1691public enum Level {1692/**1693* Enable all logging level messages1694*/1695ALL(Integer.MIN_VALUE),1696/**1697* Enable TRACE level messages1698*/1699TRACE(400),1700/**1701* Enable DEBUG level messages1702*/1703DEBUG(500),1704/**1705* Enable INFO level messages1706*/1707INFO(800),1708/**1709* Enable WARNING level messages1710*/1711WARNING(900),1712/**1713* Enable ERROR level messages1714*/1715ERROR(1000),1716/**1717*1718* Disable logging1719*/1720OFF(Integer.MAX_VALUE);17211722final int severity;1723Level(int value) {1724severity = value;1725}17261727/**1728* Returns the name of this level1729*1730* @return name of this level1731*/1732public final java.lang.String getName() {1733return name();1734}17351736/**1737* Returns severity of this level1738*1739* @return severity of this level1740*/1741public final int getSeverity() {1742return severity;1743}1744}17451746/**1747* Returns the name of this logger1748*1749* @return the logger name1750*/1751public String getName();17521753/**1754* Checks if a message of the given level will be logged1755*1756* @param level The log message level1757* @return true if the given log message level is currently being logged1758* @throws NullPointerException if level is null1759*/1760public boolean isLoggable(Level level);17611762/**1763* Logs a message1764*1765* @param level The log message level1766* @param msg The log message1767* @throws NullPointerException if level is null1768*/1769public default void log(Level level, String msg) {1770Objects.requireNonNull(level);1771log(level, (ResourceBundle)null, msg, (Object[])null);1772}17731774/**1775* Logs a lazily supplied message1776*1777* @param level The log message level1778* @param supplier Supplier function that produces a message1779* @throws NullPointerException if level or supplier is null1780*/1781public default void log(Level level, Supplier<String> supplier) {1782Objects.requireNonNull(level);1783Objects.requireNonNull(supplier);1784if (isLoggable(level)) {1785log(level, (ResourceBundle)null, supplier.get(), (Object[])null);1786}1787}17881789/**1790* Logs a message produced from the give object1791*1792* @param level The log message level1793* @param value The object to log1794* @throws NullPointerException if level or value is null1795*/1796public default void log(Level level, Object value) {1797Objects.requireNonNull(level);1798Objects.requireNonNull(value);1799if (isLoggable(level)) {1800log(level, (ResourceBundle)null, value.toString(), (Object[])null);1801}1802}18031804/**1805* Log a message associated with a given throwable1806*1807* @param level The log message level1808* @param msg The log message1809* @param throwable Throwable associated with the log message1810* @throws NullPointerException if level is null1811*/1812public default void log(Level level, String msg, Throwable throwable) {1813Objects.requireNonNull(level);1814log(level, (ResourceBundle)null, msg, throwable);1815}18161817/**1818* Logs a lazily supplied message associated with a given throwable1819*1820* @param level The log message level1821* @param supplier Supplier function that produces a message1822* @param throwable Throwable associated with the log message1823* @throws NullPointerException if level or supplier is null1824*/1825public default void log(Level level, Supplier<String> supplier, Throwable throwable) {1826Objects.requireNonNull(level);1827Objects.requireNonNull(supplier);1828if (isLoggable(level)) {1829log(level, (ResourceBundle)null, supplier.get(), throwable);1830}1831}18321833/**1834* Logs a message with an optional list of parameters1835*1836* @param level The log message level1837* @param msg The log message1838* @param values Optional list of parameters1839* @throws NullPointerException if level is null1840*/1841public default void log(Level level, String msg, Object... values) {1842Objects.requireNonNull(level);1843log(level, (ResourceBundle)null, msg, values);1844}18451846/**1847* Logs a localized message associated with a given throwable1848*1849* @param level The log message level1850* @param bundle A resource bundle to localize msg1851* @param msg The log message1852* @param throwable Throwable associated with the log message1853* @throws NullPointerException if level is null1854*/1855public void log(Level level, ResourceBundle bundle, String msg, Throwable throwable);18561857/**1858* Logs a message with resource bundle and an optional list of parameters1859*1860* @param level The log message level1861* @param bundle A resource bundle to localize msg1862* @param msg The log message1863* @param values Optional list of parameters1864* @throws NullPointerException if level is null1865*/1866public void log(Level level, ResourceBundle bundle, String msg, Object... values);1867}1868/*[ENDIF]*/1869}187018711872