8266391: Replace use of reflection in jdk.internal.platform.Metrics

Reviewed-by: redestad
This commit is contained in:
Mandy Chung 2021-05-03 21:58:37 +00:00
parent 020236cb98
commit 3544a9d0e4
4 changed files with 95 additions and 10 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -55,15 +55,7 @@ public interface Metrics {
* @return Metrics object or null if not supported on this platform.
*/
public static Metrics systemMetrics() {
try {
Class<?> c = Class.forName("jdk.internal.platform.CgroupMetrics");
Method m = c.getMethod("getInstance");
return (Metrics) m.invoke(null);
} catch (ClassNotFoundException e) {
return null;
} catch (ReflectiveOperationException e) {
throw new InternalError(e);
}
return SystemMetrics.instance();
}
/**