src/os/linux/vm/os_linux.cpp

changeset 2520
63d374c54045
parent 2509
9cd8a2c2d584
child 2584
da091bb67459
     1.1 --- a/src/os/linux/vm/os_linux.cpp	Tue Feb 08 22:27:57 2011 -0800
     1.2 +++ b/src/os/linux/vm/os_linux.cpp	Wed Feb 09 11:08:10 2011 +0100
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -131,6 +131,7 @@
    1.11  #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
    1.12  #define SEC_IN_NANOSECS  1000000000LL
    1.13  
    1.14 +#define LARGEPAGES_BIT (1 << 6)
    1.15  ////////////////////////////////////////////////////////////////////////////////
    1.16  // global variables
    1.17  julong os::Linux::_physical_memory = 0;
    1.18 @@ -2817,6 +2818,43 @@
    1.19    return linux_mprotect(addr, size, PROT_READ|PROT_WRITE);
    1.20  }
    1.21  
    1.22 +/*
    1.23 +* Set the coredump_filter bits to include largepages in core dump (bit 6)
    1.24 +*
    1.25 +* From the coredump_filter documentation:
    1.26 +*
    1.27 +* - (bit 0) anonymous private memory
    1.28 +* - (bit 1) anonymous shared memory
    1.29 +* - (bit 2) file-backed private memory
    1.30 +* - (bit 3) file-backed shared memory
    1.31 +* - (bit 4) ELF header pages in file-backed private memory areas (it is
    1.32 +*           effective only if the bit 2 is cleared)
    1.33 +* - (bit 5) hugetlb private memory
    1.34 +* - (bit 6) hugetlb shared memory
    1.35 +*/
    1.36 +static void set_coredump_filter(void) {
    1.37 +  FILE *f;
    1.38 +  long cdm;
    1.39 +
    1.40 +  if ((f = fopen("/proc/self/coredump_filter", "r+")) == NULL) {
    1.41 +    return;
    1.42 +  }
    1.43 +
    1.44 +  if (fscanf(f, "%lx", &cdm) != 1) {
    1.45 +    fclose(f);
    1.46 +    return;
    1.47 +  }
    1.48 +
    1.49 +  rewind(f);
    1.50 +
    1.51 +  if ((cdm & LARGEPAGES_BIT) == 0) {
    1.52 +    cdm |= LARGEPAGES_BIT;
    1.53 +    fprintf(f, "%#lx", cdm);
    1.54 +  }
    1.55 +
    1.56 +  fclose(f);
    1.57 +}
    1.58 +
    1.59  // Large page support
    1.60  
    1.61  static size_t _large_page_size = 0;
    1.62 @@ -2874,6 +2912,8 @@
    1.63      _page_sizes[2] = 0;
    1.64    }
    1.65  
    1.66 +  set_coredump_filter();
    1.67 +
    1.68    // Large page support is available on 2.6 or newer kernel, some vendors
    1.69    // (e.g. Redhat) have backported it to their 2.4 based distributions.
    1.70    // We optimistically assume the support is available. If later it turns out

mercurial