Skip to content

Commit e708ee4

Browse files
committed
JvmFactory.getJVMFor() never returns null
1 parent 424cebf commit e708ee4

File tree

6 files changed

+45
-49
lines changed

6 files changed

+45
-49
lines changed

visualvm/application/src/org/graalvm/visualvm/application/ApplicationDescriptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ protected static String resolveApplicationName(Application application, Applicat
164164

165165
protected static String resolveCustomName(Application application) {
166166
Jvm jvm = application.getState() == Stateful.STATE_AVAILABLE ? JvmFactory.getJVMFor(application) : null;
167-
if (jvm != null && jvm.isBasicInfoSupported()) {
167+
if (jvm.isBasicInfoSupported()) {
168168
String args = jvm.getJvmArgs();
169169
int propIndex = args.indexOf(DISPLAY_NAME_PROPERTY);
170170

visualvm/applicationviews/src/org/graalvm/visualvm/application/views/monitor/ApplicationMonitorModel.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -445,25 +445,23 @@ private void initialize(Application application) {
445445
processorsCount = 1;
446446

447447
jvm = JvmFactory.getJVMFor(application);
448-
if (jvm != null) {
449-
HeapDumpSupport hds = HeapDumpSupport.getInstance();
450-
if (application.isLocalApplication()) {
451-
takeHeapDumpSupported = hds.supportsHeapDump(application);
452-
} else {
453-
takeHeapDumpSupported = hds.supportsRemoteHeapDump(application);
454-
}
455-
cpuMonitoringSupported = jvm.isCpuMonitoringSupported();
456-
gcMonitoringSupported = jvm.isCollectionTimeSupported();
457-
memoryMonitoringSupported = jvm.isMemoryMonitoringSupported();
458-
classMonitoringSupported = jvm.isClassMonitoringSupported();
459-
threadsMonitoringSupported = jvm.isThreadMonitoringSupported();
460-
if (memoryMonitoringSupported) {
461-
String[] names = jvm.getGenName();
462-
heapName = names[0];
463-
permgenName = names[1];
464-
}
465-
processorsCount = jvm.getAvailableProcessors();
448+
HeapDumpSupport hds = HeapDumpSupport.getInstance();
449+
if (application.isLocalApplication()) {
450+
takeHeapDumpSupported = hds.supportsHeapDump(application);
451+
} else {
452+
takeHeapDumpSupported = hds.supportsRemoteHeapDump(application);
453+
}
454+
cpuMonitoringSupported = jvm.isCpuMonitoringSupported();
455+
gcMonitoringSupported = jvm.isCollectionTimeSupported();
456+
memoryMonitoringSupported = jvm.isMemoryMonitoringSupported();
457+
classMonitoringSupported = jvm.isClassMonitoringSupported();
458+
threadsMonitoringSupported = jvm.isThreadMonitoringSupported();
459+
if (memoryMonitoringSupported) {
460+
String[] names = jvm.getGenName();
461+
heapName = names[0];
462+
permgenName = names[1];
466463
}
464+
processorsCount = jvm.getAvailableProcessors();
467465

468466
memoryMXBean = null;
469467
JmxModel jmxModel = JmxModelFactory.getJmxModelFor(application);

visualvm/applicationviews/src/org/graalvm/visualvm/application/views/threads/ApplicationThreadsView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ protected void willBeAdded() {
9494
if (ds instanceof Application) {
9595
Application application = (Application)ds;
9696
Jvm jvm = JvmFactory.getJVMFor(application);
97-
takeThreadDumpSupported = jvm == null ? false : jvm.isTakeThreadDumpSupported();
97+
takeThreadDumpSupported = jvm.isTakeThreadDumpSupported();
9898
threadsManager = null;
9999
JmxModel jmxModel = JmxModelFactory.getJmxModelFor(application);
100100
if (jmxModel != null && jmxModel.getConnectionState() == ConnectionState.CONNECTED) {

visualvm/graalvm/src/org/graalvm/visualvm/graalvm/libgraal/MemoryModel.java

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -284,31 +284,29 @@ private void initialize(Application application) {
284284
/ preferences.getMonitoredDataPoll();
285285

286286
jvm = JvmFactory.getJVMFor(application);
287-
if (jvm != null) {
288-
connection = getConnection(application);
289-
if (connection != null) {
290-
updateValues(System.currentTimeMillis(), getData());
291-
292-
if (live) {
293-
monitoredDataListener = new MonitoredDataListener() {
294-
long lastTimestamp = -1;
295-
296-
public void monitoredDataEvent(final MonitoredData data) {
297-
long timestamp = System.currentTimeMillis();
298-
final long timestampF = lastTimestamp < timestamp
299-
? lastTimestamp = timestamp : ++lastTimestamp;
300-
final Object[] values = getData();
301-
302-
SwingUtilities.invokeLater(new Runnable() {
303-
public void run() {
304-
updateValues(timestampF, values);
305-
fireChange();
306-
}
307-
});
308-
}
309-
};
310-
jvm.addMonitoredDataListener(monitoredDataListener);
311-
}
287+
connection = getConnection(application);
288+
if (connection != null) {
289+
updateValues(System.currentTimeMillis(), getData());
290+
291+
if (live) {
292+
monitoredDataListener = new MonitoredDataListener() {
293+
long lastTimestamp = -1;
294+
295+
public void monitoredDataEvent(final MonitoredData data) {
296+
long timestamp = System.currentTimeMillis();
297+
final long timestampF = lastTimestamp < timestamp
298+
? lastTimestamp = timestamp : ++lastTimestamp;
299+
final Object[] values = getData();
300+
301+
SwingUtilities.invokeLater(new Runnable() {
302+
public void run() {
303+
updateValues(timestampF, values);
304+
fireChange();
305+
}
306+
});
307+
}
308+
};
309+
jvm.addMonitoredDataListener(monitoredDataListener);
312310
}
313311
}
314312
}

visualvm/jfr/src/org/graalvm/visualvm/jfr/JFRSnapshotSupport.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public static void takeRemoteJfrDump(Application application, String dumpFile, b
137137
public static boolean supportsJfrDump(Application application) {
138138
if (application.getState() != Stateful.STATE_AVAILABLE) return false;
139139
Jvm jvm = JvmFactory.getJVMFor(application);
140-
if (jvm == null || !jvm.isJfrAvailable()) return false;
140+
if (!jvm.isJfrAvailable()) return false;
141141
return !jvm.jfrCheck().isEmpty();
142142
}
143143

@@ -166,7 +166,7 @@ public static void remoteJfrStartRecording(Application application) {
166166
public static boolean supportsJfrStart(Application application) {
167167
if (application.getState() != Stateful.STATE_AVAILABLE) return false;
168168
Jvm jvm = JvmFactory.getJVMFor(application);
169-
if (jvm == null || !jvm.isJfrAvailable()) return false;
169+
if (!jvm.isJfrAvailable()) return false;
170170
return jvm.jfrCheck().isEmpty();
171171
}
172172

@@ -189,7 +189,7 @@ public static void remoteJfrStopRecording(Application application) {
189189
public static boolean supportsJfrStop(Application application) {
190190
if (application.getState() != Stateful.STATE_AVAILABLE) return false;
191191
Jvm jvm = JvmFactory.getJVMFor(application);
192-
if (jvm == null || !jvm.isJfrAvailable()) return false;
192+
if (!jvm.isJfrAvailable()) return false;
193193
return !jvm.jfrCheck().isEmpty();
194194
}
195195

visualvm/jfr/src/org/graalvm/visualvm/jfr/impl/JFRRecordingProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public void run() {
169169
if (jvm != null) {
170170
recordings = jvm.jfrCheck();
171171
}
172-
if (jvm == null || recordings.isEmpty()) {
172+
if (recordings.isEmpty()) {
173173
DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(NbBundle.getMessage(JFRRecordingProvider.class,
174174
"MSG_Cannot_Take_JFR_dump", DataSourceDescriptorFactory. // NOI18N
175175
getDescriptor(application).getName()), NotifyDescriptor.ERROR_MESSAGE));

0 commit comments

Comments
 (0)