Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/jdk.internal.jvmstat/share/classes/sun/jvmstat/PlatformSupport.java
41153 views
1
/*
2
* Copyright (c) 2018, 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
23
* questions.
24
*/
25
package sun.jvmstat;
26
27
import java.io.File;
28
import java.lang.reflect.Constructor;
29
import java.util.List;
30
import jdk.internal.vm.VMSupport;
31
32
/*
33
* Support routines handling temp directory locating
34
* and process ID extraction.
35
*/
36
public class PlatformSupport {
37
private static final String tmpDirName;
38
static {
39
/*
40
* For this to work, the target VM and this code need to use
41
* the same directory. Instead of guessing which directory the
42
* VM is using, we will ask.
43
*/
44
String tmpdir = VMSupport.getVMTemporaryDirectory();
45
46
/*
47
* Assure that the string returned has a trailing File.separator
48
* character. This check was added because the Linux implementation
49
* changed such that the java.io.tmpdir string no longer terminates
50
* with a File.separator character.
51
*/
52
if (tmpdir.lastIndexOf(File.separator) != (tmpdir.length()-1)) {
53
tmpdir = tmpdir + File.separator;
54
}
55
tmpDirName = tmpdir;
56
}
57
58
public static PlatformSupport getInstance() {
59
try {
60
Class<?> c = Class.forName("sun.jvmstat.PlatformSupportImpl");
61
@SuppressWarnings("unchecked")
62
Constructor<PlatformSupport> cntr = (Constructor<PlatformSupport>) c.getConstructor();
63
return cntr.newInstance();
64
} catch (ClassNotFoundException e) {
65
return new PlatformSupport();
66
} catch (ReflectiveOperationException e) {
67
throw new InternalError(e);
68
}
69
}
70
71
// package-private
72
PlatformSupport() {}
73
74
/*
75
* Return the OS specific temporary directory
76
*/
77
public static String getTemporaryDirectory() {
78
return tmpDirName;
79
}
80
81
/*
82
* Return a list of the temporary directories that the VM uses
83
* for the attach and perf data files. This function returns
84
* the traditional temp directory in addition to any paths
85
* accessible by the host which map to temp directories used
86
* by containers. The container functionality is only currently
87
* supported on Linux platforms.
88
*
89
* It is important that this directory is well-known and the
90
* same for all VM instances. It cannot be affected by configuration
91
* variables such as java.io.tmpdir.
92
*/
93
public List<String> getTemporaryDirectories(int vmid) {
94
// Add the default temporary directory only
95
return List.of(tmpDirName);
96
}
97
98
/*
99
* Extract the host PID from a file path.
100
*/
101
public int getLocalVmId(File file) throws NumberFormatException {
102
return Integer.parseInt(file.getName());
103
}
104
105
106
/*
107
* Return the inner most namespaced PID if there is one,
108
* otherwise return the original PID.
109
*/
110
public int getNamespaceVmId(int pid) {
111
return pid;
112
}
113
}
114
115