Merge
diff --git a/.hgtags-top-repo b/.hgtags-top-repo
index 5dd7b62..9a304e0 100644
--- a/.hgtags-top-repo
+++ b/.hgtags-top-repo
@@ -1062,3 +1062,4 @@
 26920b304bf9a6383cfa2c618580d418fd98915f jdk8u302-b07
 f7f1e6a9ee97dde65500352e0ae618d28e2cf708 jdk8u302-b08
 f7f1e6a9ee97dde65500352e0ae618d28e2cf708 jdk8u302-ga
+dc82fdcc8c4d0f3b82ce0ca61be2ffdc689dea22 jdk8u312-b01
diff --git a/corba/.hgtags b/corba/.hgtags
index 13105d2..cc6b31f 100644
--- a/corba/.hgtags
+++ b/corba/.hgtags
@@ -1135,3 +1135,4 @@
 c9effa70be0a6507c1f32730adc9d819ad8a68cc jdk8u302-b07
 78fc946c11547e477446c1c825ce5ec053034508 jdk8u302-b08
 78fc946c11547e477446c1c825ce5ec053034508 jdk8u302-ga
+0c131269504a0d2f36563d4d869177e1272dcead jdk8u312-b01
diff --git a/hotspot/.hgtags b/hotspot/.hgtags
index 0dae12f..b16c38b 100644
--- a/hotspot/.hgtags
+++ b/hotspot/.hgtags
@@ -1368,3 +1368,4 @@
 78dfe32cac588b01e28792d42e761fa35a80e8f9 jdk8u302-b07
 a209b6f5b09af88bae12ffeebd382f3ef804b99f jdk8u302-b08
 a209b6f5b09af88bae12ffeebd382f3ef804b99f jdk8u302-ga
+2f7a380c9a0ac0cf20fdb17d7b6a135da05b5d04 jdk8u312-b01
diff --git a/jaxp/.hgtags b/jaxp/.hgtags
index 957c5f8..2180b84 100644
--- a/jaxp/.hgtags
+++ b/jaxp/.hgtags
@@ -1099,3 +1099,4 @@
 5f019dc37164bc2615d4c3d04411b26da8f7f260 jdk8u302-b07
 41f3654e3404e5524dcbf1136acc5e6c09ffffab jdk8u302-b08
 41f3654e3404e5524dcbf1136acc5e6c09ffffab jdk8u302-ga
+211ac8fe58f622ea94613323ea945a72c65b675f jdk8u312-b01
diff --git a/jaxws/.hgtags b/jaxws/.hgtags
index 35b1683..783a3df 100644
--- a/jaxws/.hgtags
+++ b/jaxws/.hgtags
@@ -1093,3 +1093,4 @@
 29ad7b1330146fcf1a0ee60a9a82995d2f324f9a jdk8u302-b07
 eae73754c31e3109b5e8fdd9a83e6e090b5a36b9 jdk8u302-b08
 eae73754c31e3109b5e8fdd9a83e6e090b5a36b9 jdk8u302-ga
+396d9b5a44b58632fbaab0d88c598349129ca1d2 jdk8u312-b01
diff --git a/jdk/.hgtags b/jdk/.hgtags
index 9007461..93ab095 100644
--- a/jdk/.hgtags
+++ b/jdk/.hgtags
@@ -1094,3 +1094,4 @@
 7762468ad65060d9445413975cd7142f89792bbd jdk8u302-b07
 06b4012edc724ba45b1c1a8593d00ca989baa284 jdk8u302-b08
 06b4012edc724ba45b1c1a8593d00ca989baa284 jdk8u302-ga
+52d602b87c1d0ff8325e2e8b58fcdca1d8c302a5 jdk8u312-b01
diff --git a/jdk/make/mapfiles/libmanagement/mapfile-vers b/jdk/make/mapfiles/libmanagement/mapfile-vers
index 3a7b9f2..f2ba4aa 100644
--- a/jdk/make/mapfiles/libmanagement/mapfile-vers
+++ b/jdk/make/mapfiles/libmanagement/mapfile-vers
@@ -39,6 +39,8 @@
 	    Java_sun_management_OperatingSystemImpl_getTotalSwapSpaceSize0;
 	    Java_sun_management_OperatingSystemImpl_getSingleCpuLoad0;
 	    Java_sun_management_OperatingSystemImpl_getHostConfiguredCpuCount0;
+	    Java_sun_management_OperatingSystemImpl_getHostOnlineCpuCount0;
+	    Java_sun_management_OperatingSystemImpl_getHostTotalCpuTicks0;
 	    Java_sun_management_OperatingSystemImpl_initialize;
 	    Java_sun_management_ClassLoadingImpl_setVerboseClass;
             Java_sun_management_DiagnosticCommandImpl_executeDiagnosticCommand;
diff --git a/jdk/src/solaris/classes/sun/management/OperatingSystemImpl.java b/jdk/src/solaris/classes/sun/management/OperatingSystemImpl.java
index 565712b..e2bbd61 100644
--- a/jdk/src/solaris/classes/sun/management/OperatingSystemImpl.java
+++ b/jdk/src/solaris/classes/sun/management/OperatingSystemImpl.java
@@ -40,6 +40,8 @@
 
     private static final int MAX_ATTEMPTS_NUMBER = 10;
     private final Metrics containerMetrics;
+    private long usageTicks = 0; // used for cpu load calculation
+    private long totalTicks = 0; // used for cpu load calculation
 
     OperatingSystemImpl(VMManagement vm) {
         super(vm);
@@ -114,24 +116,56 @@
         return getTotalPhysicalMemorySize0();
     }
 
+    private double getUsageDividesTotal(long usageTicks, long totalTicks) {
+        // If cpu quota or cpu shares are in effect calculate the cpu load
+        // based on the following formula (similar to how
+        // getCpuLoad0() is being calculated):
+        //
+        //   | usageTicks - usageTicks' |
+        //  ------------------------------
+        //   | totalTicks - totalTicks' |
+        //
+        // where usageTicks' and totalTicks' are historical values
+        // retrieved via an earlier call of this method.
+        //
+        // Total ticks should be scaled to the container effective number
+        // of cpus, if cpu shares are in effect.
+        if (usageTicks < 0 || totalTicks <= 0) {
+            return -1;
+        }
+        long distance = usageTicks - this.usageTicks;
+        this.usageTicks = usageTicks;
+        long totalDistance = totalTicks - this.totalTicks;
+        this.totalTicks = totalTicks;
+
+        double systemLoad = 0.0;
+        if (distance > 0 && totalDistance > 0) {
+            systemLoad = ((double)distance) / totalDistance;
+        }
+        // Ensure the return value is in the range 0.0 -> 1.0
+        systemLoad = Math.max(0.0, systemLoad);
+        systemLoad = Math.min(1.0, systemLoad);
+        return systemLoad;
+    }
+
     public double getSystemCpuLoad() {
         if (containerMetrics != null) {
             long quota = containerMetrics.getCpuQuota();
+            long share = containerMetrics.getCpuShares();
+            long usageNanos = containerMetrics.getCpuUsage();
             if (quota > 0) {
-                long periodLength = containerMetrics.getCpuPeriod();
                 long numPeriods = containerMetrics.getCpuNumPeriods();
-                long usageNanos = containerMetrics.getCpuUsage();
-                if (periodLength > 0 && numPeriods > 0 && usageNanos > 0) {
-                    long elapsedNanos = TimeUnit.MICROSECONDS.toNanos(periodLength * numPeriods);
-                    double systemLoad = (double) usageNanos / elapsedNanos;
-                    // Ensure the return value is in the range 0.0 -> 1.0
-                    systemLoad = Math.max(0.0, systemLoad);
-                    systemLoad = Math.min(1.0, systemLoad);
-                    return systemLoad;
-                }
-                return -1;
+                long quotaNanos = TimeUnit.MICROSECONDS.toNanos(quota * numPeriods);
+                return getUsageDividesTotal(usageNanos, quotaNanos);
+            } else if (share > 0) {
+                long hostTicks = getHostTotalCpuTicks0();
+                int totalCPUs = getHostOnlineCpuCount0();
+                int containerCPUs = getAvailableProcessors();
+                // scale the total host load to the actual container cpus
+                hostTicks = hostTicks * containerCPUs / totalCPUs;
+                return getUsageDividesTotal(usageNanos, hostTicks);
             } else {
-                // If CPU quotas are not active then find the average system load for
+                // If CPU quotas and shares are not active then find the average system load for
                 // all online CPUs that are allowed to run this container.
 
                 // If the cpuset is the same as the host's one there is no need to iterate over each CPU
@@ -139,6 +173,10 @@
                     return getSystemCpuLoad0();
                 } else {
                     int[] cpuSet = containerMetrics.getEffectiveCpuSetCpus();
+                    // in case the effectiveCPUSetCpus are not available, attempt to use just cpusets.cpus
+                    if (cpuSet == null || cpuSet.length <= 0) {
+                        cpuSet = containerMetrics.getCpuSetCpus();
+                    }
                     if (cpuSet != null && cpuSet.length > 0) {
                         double systemLoad = 0.0;
                         for (int cpu : cpuSet) {
@@ -159,7 +197,7 @@
 
     private boolean isCpuSetSameAsHostCpuSet() {
         if (containerMetrics != null) {
-            return containerMetrics.getCpuSetCpus().length == getHostConfiguredCpuCount0();
+            return containerMetrics.getCpuSetCpus().length == getHostOnlineCpuCount0();
         }
         return false;
     }
@@ -176,6 +214,9 @@
     public native double getProcessCpuLoad();
     private native double getSingleCpuLoad0(int cpuNum);
     private native int getHostConfiguredCpuCount0();
+    private native int getHostOnlineCpuCount0();
+    // CPU ticks since boot in nanoseconds
+    private native long getHostTotalCpuTicks0();
 
     static {
         initialize();
diff --git a/jdk/src/solaris/native/sun/management/LinuxOperatingSystem.c b/jdk/src/solaris/native/sun/management/LinuxOperatingSystem.c
index bca051d..a2cb8fa 100644
--- a/jdk/src/solaris/native/sun/management/LinuxOperatingSystem.c
+++ b/jdk/src/solaris/native/sun/management/LinuxOperatingSystem.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2020, 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
@@ -59,6 +59,7 @@
 } counters;
 
 #define DEC_64 "%"SCNd64
+#define NS_PER_SEC 1000000000
 
 static void next_line(FILE *f) {
     while (fgetc(f) != '\n');
@@ -365,3 +366,39 @@
        return -1;
     }
 }
+
+// Return the host cpu ticks since boot in nanoseconds
+JNIEXPORT jlong JNICALL
+Java_sun_management_OperatingSystemImpl_getHostTotalCpuTicks0
+(JNIEnv *env, jobject mbean)
+{
+    if (perfInit() == 0) {
+        if (get_totalticks(-1, &counters.cpuTicks) < 0) {
+            return -1;
+        } else {
+            long ticks_per_sec = sysconf(_SC_CLK_TCK);
+            jlong result = (jlong)counters.cpuTicks.total;
+            if (ticks_per_sec <= NS_PER_SEC) {
+                long scale_factor = NS_PER_SEC/ticks_per_sec;
+                result = result * scale_factor;
+            } else {
+                long scale_factor = ticks_per_sec/NS_PER_SEC;
+                result = result / scale_factor;
+            }
+            return result;
+        }
+    } else {
+        return -1;
+    }
+}
+
+JNIEXPORT jint JNICALL
+Java_sun_management_OperatingSystemImpl_getHostOnlineCpuCount0
+(JNIEnv *env, jobject mbean)
+{
+    int n = sysconf(_SC_NPROCESSORS_ONLN);
+    if (n <= 0) {
+        n = 1;
+    }
+    return n;
+}
diff --git a/jdk/src/solaris/native/sun/management/OperatingSystemImpl.c b/jdk/src/solaris/native/sun/management/OperatingSystemImpl.c
index ec5de2f..2f30009 100644
--- a/jdk/src/solaris/native/sun/management/OperatingSystemImpl.c
+++ b/jdk/src/solaris/native/sun/management/OperatingSystemImpl.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2020, 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
@@ -476,6 +476,20 @@
 {
     return -1;
 }
+
+JNIEXPORT jint JNICALL
+Java_sun_management_OperatingSystemImpl_getHostOnlineCpuCount0
+(JNIEnv *env, jobject mbean)
+{
+    return -1;
+}
+
+JNIEXPORT jlong JNICALL
+Java_sun_management_OperatingSystemImpl_getHostTotalCpuTicks0
+(JNIEnv *env, jobject mbean)
+{
+    return -1.0;
+}
 #endif
 
 JNIEXPORT jlong JNICALL
diff --git a/langtools/.hgtags b/langtools/.hgtags
index 7de7404..4a18cbc 100644
--- a/langtools/.hgtags
+++ b/langtools/.hgtags
@@ -1100,3 +1100,4 @@
 dccbf90608ebab1f656e53846774e436a9cd5d00 jdk8u302-b07
 361a561709af891da4bf5e9ad2f469afd602c3df jdk8u302-b08
 361a561709af891da4bf5e9ad2f469afd602c3df jdk8u302-ga
+c2908eb7d16d7899ac98cefead3993948f2d932a jdk8u312-b01
diff --git a/nashorn/.hgtags b/nashorn/.hgtags
index 0c04d30..7fcee81 100644
--- a/nashorn/.hgtags
+++ b/nashorn/.hgtags
@@ -1134,3 +1134,4 @@
 1a5a89139fa02e15a5b65735037542929e942e9f jdk8u302-b07
 a69c36cf0f4f8e235bf7f4775049daab56976bc4 jdk8u302-b08
 a69c36cf0f4f8e235bf7f4775049daab56976bc4 jdk8u302-ga
+4e3edd6a47342279f864d979a168972caa01b76e jdk8u312-b01