2
* Copyright 2003-2010 Terracotta, Inc.
2
* Copyright Terracotta, Inc.
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
125
125
* @return true if agent was loaded (which could have happened thought the -javaagent switch)
127
127
static boolean loadAgent() {
128
if (!agentIsAvailable() && VIRTUAL_MACHINE_LOAD_AGENT != null) {
130
String name = ManagementFactory.getRuntimeMXBean().getName();
131
Object vm = VIRTUAL_MACHINE_ATTACH.invoke(null, name.substring(0, name.indexOf('@')));
128
synchronized (AgentLoader.class.getName().intern()) {
129
if (!agentIsAvailable() && VIRTUAL_MACHINE_LOAD_AGENT != null) {
133
File agent = getAgentFile();
134
LOGGER.info("Trying to load agent @ {}", agent);
136
VIRTUAL_MACHINE_LOAD_AGENT.invoke(vm, agent.getAbsolutePath());
132
String name = ManagementFactory.getRuntimeMXBean().getName();
133
Object vm = VIRTUAL_MACHINE_ATTACH.invoke(null, name.substring(0, name.indexOf('@')));
135
File agent = getAgentFile();
136
LOGGER.info("Trying to load agent @ {}", agent);
138
VIRTUAL_MACHINE_LOAD_AGENT.invoke(vm, agent.getAbsolutePath());
141
VIRTUAL_MACHINE_DETACH.invoke(vm);
139
VIRTUAL_MACHINE_DETACH.invoke(vm);
143
} catch (Throwable e) {
144
LOGGER.info("Failed to attach to VM and load the agent: {}: {}", e.getClass(), e.getMessage());
141
} catch (Throwable e) {
142
LOGGER.info("Failed to attach to VM and load the agent: {}: {}", e.getClass(), e.getMessage());
146
return agentIsAvailable();
148
return agentIsAvailable();
152
private static void warnIfOSX() {
153
if (JvmInformation.isOSX() && System.getProperty("java.io.tmpdir") != null) {
154
LOGGER.warn("Loading the SizeOfAgent will probably fail, as you are running on Apple OS X and have a value set for java.io.tmpdir\n" +
155
"They both result in a bug, not yet fixed by Apple, that won't let us attach to the VM and load the agent.\n" +
156
"Most probably, you'll also get a full thread-dump after this because of the failure... Nothing to worry about!\n" +
157
"You can bypass trying to load the Agent entirely by setting the System property '"
158
+ net.sf.ehcache.pool.sizeof.AgentSizeOf.BYPASS_LOADING + "' to true");
149
162
private static File getAgentFile() throws IOException {
197
210
instrumentation = (Instrumentation)getInstrumentationMethod.invoke(sizeOfAgentClass);
199
212
return instrumentation != null;
213
} catch (SecurityException e) {
214
LOGGER.warn("Couldn't access the system classloader because of the security policies applied by " +
215
"the security manager. You either want to loosen these, so ClassLoader.getSystemClassLoader() and " +
216
"reflection API calls are permitted or the sizing will be done using some other mechanism.\n" +
217
"Alternatively, set the system property net.sf.ehcache.sizeof.agent.instrumentationSystemProperty to true " +
218
"to have the agent put the required instances in the System Properties for the loader to access.");
200
220
} catch (Throwable e) {