annotate agent/src/share/classes/sun/jvm/hotspot/SALauncherLoader.java @ 196:d1605aabd0a1 jdk7-b30

6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
author xdono
date Wed, 02 Jul 2008 12:55:16 -0700
parents c70a245cad3a
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
196
d1605aabd0a1 6719955: Update copyright year
xdono
parents: 152
diff changeset
2 * Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.io.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import java.net.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import java.security.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
33 * SA uses native debugger back-end library - libsaproc.so on Unix platforms.
a61af66fc99e Initial load
duke
parents:
diff changeset
34 * Starting from 5.0, in Solaris & Linux JDK "libsaproc.so" is shipped with JDK
a61af66fc99e Initial load
duke
parents:
diff changeset
35 * and is kept jre/lib/cpu directory (where all other JDK platform libraries
a61af66fc99e Initial load
duke
parents:
diff changeset
36 * are kept). This implies that always that jre copy of libsaproc.so will be
a61af66fc99e Initial load
duke
parents:
diff changeset
37 * used and the copy of libsaproc.so built from SA sources here will not
a61af66fc99e Initial load
duke
parents:
diff changeset
38 * be used at all. We can override libsaproc.so using this class loader
a61af66fc99e Initial load
duke
parents:
diff changeset
39 * as System class loader using "java.system.class.loader" property. This
a61af66fc99e Initial load
duke
parents:
diff changeset
40 * class loader loads classes paths specified paths using the System property
a61af66fc99e Initial load
duke
parents:
diff changeset
41 * "java.class.path". Because, this class loader loads SA debugger classes
a61af66fc99e Initial load
duke
parents:
diff changeset
42 * (among other classes), JVM calls findLibrary override here. In this
a61af66fc99e Initial load
duke
parents:
diff changeset
43 * findLibrary, we first check the library in the directories specified through
a61af66fc99e Initial load
duke
parents:
diff changeset
44 * "sa.library.path" System property. This way updated/latest SA native library
a61af66fc99e Initial load
duke
parents:
diff changeset
45 * can be loaded instead of the one from JDK's jre/lib directory.
a61af66fc99e Initial load
duke
parents:
diff changeset
46 */
a61af66fc99e Initial load
duke
parents:
diff changeset
47 public class SALauncherLoader extends URLClassLoader {
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
50 * Checks native libraries under directories specified using
a61af66fc99e Initial load
duke
parents:
diff changeset
51 * the System property "sa.library.path".
a61af66fc99e Initial load
duke
parents:
diff changeset
52 */
a61af66fc99e Initial load
duke
parents:
diff changeset
53 public String findLibrary(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 name = System.mapLibraryName(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
55 for (int i = 0; i < libpaths.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
56 File file = new File(new File(libpaths[i]), name);
a61af66fc99e Initial load
duke
parents:
diff changeset
57 if (file.exists()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 return file.getAbsolutePath();
a61af66fc99e Initial load
duke
parents:
diff changeset
59 }
a61af66fc99e Initial load
duke
parents:
diff changeset
60 }
a61af66fc99e Initial load
duke
parents:
diff changeset
61 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 }
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 public SALauncherLoader(ClassLoader parent) {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 super(getClassPath(), parent);
a61af66fc99e Initial load
duke
parents:
diff changeset
66 String salibpath = System.getProperty("sa.library.path");
a61af66fc99e Initial load
duke
parents:
diff changeset
67 if (salibpath != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 libpaths = salibpath.split(File.pathSeparator);
a61af66fc99e Initial load
duke
parents:
diff changeset
69 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 libpaths = new String[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72 }
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
75 * Override loadClass so we can checkPackageAccess.
a61af66fc99e Initial load
duke
parents:
diff changeset
76 */
a61af66fc99e Initial load
duke
parents:
diff changeset
77 public synchronized Class loadClass(String name, boolean resolve)
a61af66fc99e Initial load
duke
parents:
diff changeset
78 throws ClassNotFoundException {
a61af66fc99e Initial load
duke
parents:
diff changeset
79 int i = name.lastIndexOf('.');
a61af66fc99e Initial load
duke
parents:
diff changeset
80 if (i != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 SecurityManager sm = System.getSecurityManager();
a61af66fc99e Initial load
duke
parents:
diff changeset
82 if (sm != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 sm.checkPackageAccess(name.substring(0, i));
a61af66fc99e Initial load
duke
parents:
diff changeset
84 }
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 Class clazz = findLoadedClass(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
88 if (clazz != null) return clazz;
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
91 * NOTE: Unlike 'usual' class loaders, we do *not* delegate to
a61af66fc99e Initial load
duke
parents:
diff changeset
92 * the parent loader first. We attempt to load the class
a61af66fc99e Initial load
duke
parents:
diff changeset
93 * ourselves first and use parent loader only if we can't load.
a61af66fc99e Initial load
duke
parents:
diff changeset
94 * This is because the parent of this loader is 'default'
a61af66fc99e Initial load
duke
parents:
diff changeset
95 * System loader that can 'see' all SA classes in classpath and
a61af66fc99e Initial load
duke
parents:
diff changeset
96 * so will load those if delegated. And if parent loads SA classes,
a61af66fc99e Initial load
duke
parents:
diff changeset
97 * then JVM won't call findNative override in this class.
a61af66fc99e Initial load
duke
parents:
diff changeset
98 */
a61af66fc99e Initial load
duke
parents:
diff changeset
99 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 return findClass(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
101 } catch (ClassNotFoundException cnfe) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 return (super.loadClass(name, resolve));
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104 }
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
107 * allow any classes loaded from classpath to exit the VM.
a61af66fc99e Initial load
duke
parents:
diff changeset
108 */
a61af66fc99e Initial load
duke
parents:
diff changeset
109 protected PermissionCollection getPermissions(CodeSource codesource) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 PermissionCollection perms = super.getPermissions(codesource);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 perms.add(new RuntimePermission("exitVM"));
a61af66fc99e Initial load
duke
parents:
diff changeset
112 return perms;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 //-- Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 private String[] libpaths;
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 private static URL[] getClassPath() {
a61af66fc99e Initial load
duke
parents:
diff changeset
120 final String s = System.getProperty("java.class.path");
a61af66fc99e Initial load
duke
parents:
diff changeset
121 final File[] path = (s == null) ? new File[0] : getClassPath(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 return pathToURLs(path);
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 private static URL[] pathToURLs(File[] path) {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 URL[] urls = new URL[path.length];
a61af66fc99e Initial load
duke
parents:
diff changeset
128 for (int i = 0; i < path.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 urls[i] = getFileURL(path[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131 return urls;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 private static File[] getClassPath(String cp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 String[] tmp = cp.split(File.pathSeparator);
a61af66fc99e Initial load
duke
parents:
diff changeset
136 File[] paths = new File[tmp.length];
a61af66fc99e Initial load
duke
parents:
diff changeset
137 for (int i = 0; i < paths.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 paths[i] = new File(tmp[i].equals("")? "." : tmp[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140 return paths;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 private static URL getFileURL(File file) {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 file = file.getCanonicalFile();
a61af66fc99e Initial load
duke
parents:
diff changeset
146 } catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
147 e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 try {
152
c70a245cad3a 6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents: 0
diff changeset
151 return file.toURI().toURL();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
152 } catch (MalformedURLException mue) {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 throw new InternalError(mue.getMessage());
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
155 }
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }