Prepared test (attached).

Thanks,
Dmytro

> Subject: Re: 6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has 
> incorrect value
> From: [email protected]
> Date: Thu, 30 Aug 2012 12:06:09 +0200
> CC: [email protected]; [email protected]; 
> [email protected]
> To: [email protected]
> 
> 
> On 30 aug 2012, at 11:31, David Holmes <[email protected]> wrote:
> 
> > On 30/08/2012 5:50 PM, Staffan Larsen wrote:
> >> The patch looks good to me and I can sponsor the push to JDK8-TL.
> >> However, you need a review from an official Reviewer as well.
> > 
> > Reviewed.
> > 
> > Any way we can get a regression test too?
> 
> That would be great - I wonder what the test would check, though? That the 
> value returned is not -1? And hope that sometimes the test will be run on a 
> machine with > 4GB ram.
> 
> /Staffan
> 
> > 
> > David
> > -----
> > 
> >> BTW, I suggest we remove the confusing comment in
> >> Java_com_sun_management_OperatingSystem_getTotalPhysicalMemorySize()
> >> while we are at it.
> >> 
> >> /Staffan
> >> 
> >> On 30 aug 2012, at 09:18, Dmytro Sheyko <[email protected]
> >> <mailto:[email protected]>> wrote:
> >> 
> >>> Hi,
> >>> 
> >>> Could you please review the patch and apply it if it's correct?
> >>> https://bugs.openjdk.java.net/show_bug.cgi?id=100077
> >>> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6853676
> >>> 
> >>> Thanks,
> >>> Dmytro
> >>> 
> >>> > Date: Wed, 2 Feb 2011 20:09:59 +1000
> >>> > From:[email protected] <mailto:[email protected]>
> >>> > To:[email protected] <mailto:[email protected]>
> >>> > CC:[email protected] <mailto:[email protected]>;
> >>> [email protected]
> >>> <mailto:[email protected]>;[email protected]
> >>> <mailto:[email protected]>;[email protected]
> >>> <mailto:[email protected]>;[email protected]
> >>> <mailto:[email protected]>
> >>> > Subject: Re: 6853676: OperatingSystemMXBean.TotalPhysicalMemorySize
> >>> has incorrect value
> >>> >
> >>> > Alan Bateman said the following on 02/02/11 20:05:
> >>> > > David Holmes wrote:
> >>> > >> It looks like this was actually fixed under 6840305 back in July
> >>> 2009:
> >>> > >>
> >>> > >> http://hg.openjdk.java.net/jdk7/hotspot-rt/hotspot/rev/8c79517a9300
> >>> > >>
> >>> > >> This CR was not updated however.
> >>> > >>
> >>> > >> Does the problem still exist?
> >>> > >>
> >>> > >> David Holmes
> >>> > > I think this is separate and 6853676 is about
> >>> > > com.sun.management.OperatingSystemMXBean. The code for that is in jdk
> >>> > > repo in src/windows/native/com/sun/management. It should be using
> >>> > > GlobalMemoryStatusEx rather than GlobalMemoryStatus.
> >>> >
> >>> > Thanks Alan, the comments in 6853676 led me astray.
> >>> >
> >>> > As a P4 it looks like this has just slipped through the cracks.
> >>> >
> >>> > David
> >>> >
> >>> >
> >>> > > Dmytro - to your question, serviceability-dev is the right place to
> >>> > > bring it.
> >>> > >
> >>> > > -Alan
> >> 
> 
                                          
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.lang.management.ManagementFactory;
import com.sun.management.OperatingSystemMXBean;

/*
 * @bug     6853676
 * @summary On computers with more than 4 GB of memory, the GlobalMemoryStatus 
function can return incorrect information, reporting a value of –1 to indicate 
an overflow.
 */
public class MemoryStatusOverflow {
        static final long MEMORYSTATUS_OVERFLOW = (1L << 32) - 1; // (DWORD) -1

        public static void main(String... args) throws Exception {
                OperatingSystemMXBean bean = (OperatingSystemMXBean) 
ManagementFactory.getOperatingSystemMXBean();
                List<String> failed = new ArrayList<String>();
                for (String prop : Arrays.asList("getTotalSwapSpaceSize", 
"getFreeSwapSpaceSize", "getTotalPhysicalMemorySize", 
"getFreePhysicalMemorySize")) {
                        Method getter = 
OperatingSystemMXBean.class.getMethod(prop);
                        long value = (Long) getter.invoke(bean);
                        if (value == MEMORYSTATUS_OVERFLOW) {
                                failed.add(prop);
                        }
                }
                if (!failed.isEmpty()) {
                        throw new AssertionError(failed);
                }
                System.out.println("Test passed.");
        }
}

Reply via email to