changeset 511:897a4fb539b6

. Make changes to the BSD specific files analagous to the changes to the Linux specific files.
author glewis@misty.eyesbeyond.com
date Sun, 28 Dec 2008 18:19:15 -0800
parents 2551e5deace8
children 07b7530c9f18
files make/bsd/adlc_updater make/bsd/makefiles/adlc.make src/os/bsd/launcher/java.c src/os/bsd/launcher/java.h src/os/bsd/launcher/java_md.c src/os/bsd/vm/globals_bsd.hpp src/os/bsd/vm/os_bsd.cpp src/os/bsd/vm/os_bsd.hpp src/os_cpu/bsd_x86/vm/bsd_x86_32.ad src/os_cpu/bsd_x86/vm/os_bsd_x86.cpp
diffstat 10 files changed, 99 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/make/bsd/adlc_updater	Sun Dec 28 11:28:04 2008 -0800
+++ b/make/bsd/adlc_updater	Sun Dec 28 18:19:15 2008 -0800
@@ -7,5 +7,13 @@
 #
 # adlc-updater <file> <source-dir> <target-dir>
 #
-[ -f $3/$1 ] && cmp -s $2/$1 $3/$1 || \
-( [ -f $3/$1 ]; echo Updating $3/$1 ; touch $2/made-change ; mv $2/$1 $3/$1 )
+fix_lines() {
+  # repair bare #line directives in $1 to refer to $2
+  awk < $1 > $1+ '
+    /^#line 999999$/ {print "#line " (NR+1) " \"" F2 "\""; next}
+    {print}
+  ' F2=$2
+  mv $1+ $1
+}
+[ -f $3/$1 ] && (fix_lines $2/$1 $3/$1; cmp -s $2/$1 $3/$1) || \
+( [ -f $3/$1 ] && echo Updating $3/$1 ; touch $2/made-change ; mv $2/$1 $3/$1 )
--- a/make/bsd/makefiles/adlc.make	Sun Dec 28 11:28:04 2008 -0800
+++ b/make/bsd/makefiles/adlc.make	Sun Dec 28 18:19:15 2008 -0800
@@ -54,9 +54,11 @@
 Src_Dirs_I = ${Src_Dirs} $(GENERATED)
 INCLUDES += $(Src_Dirs_I:%=-I%)
 
+# set flags for adlc compilation
+CPPFLAGS = $(SYSDEFS) $(INCLUDES)
+
 # Force assertions on.
-SYSDEFS += -DASSERT
-CPPFLAGS = $(SYSDEFS) $(INCLUDES)
+CPPFLAGS += -DASSERT
 
 # CFLAGS_WARN holds compiler options to suppress/enable warnings.
 # Suppress warnings (for now)
@@ -125,7 +127,15 @@
 # Note that product files are updated via "mv", which is atomic.
 TEMPDIR := $(OUTDIR)/mktmp$(shell echo $$$$)
 
-ADLCFLAGS = -q -T
+# Pass -D flags into ADLC.
+ADLCFLAGS += $(SYSDEFS)
+
+# Note "+="; it is a hook so flags.make can add more flags, like -g or -DFOO.
+ADLCFLAGS += -q -T
+
+# Normally, debugging is done directly on the ad_<arch>*.cpp files.
+# But -g will put #line directives in those files pointing back to <arch>.ad.
+#ADLCFLAGS += -g
 
 ifdef LP64
 ADLCFLAGS += -D_LP64
@@ -140,6 +150,8 @@
 #
 ADLC_UPDATER_DIRECTORY = $(GAMMADIR)/make/$(OS)
 ADLC_UPDATER = adlc_updater
+$(ADLC_UPDATER): $(ADLC_UPDATER_DIRECTORY)/$(ADLC_UPDATER)
+	$(QUIETLY) cp $< $@; chmod +x $@
 
 # This action refreshes all generated adlc files simultaneously.
 # The way it works is this:
@@ -149,9 +161,8 @@
 # 4) call $(ADLC_UPDATER) on each generated adlc file. It will selectively update changed or missing files.
 # 5) If we actually updated any files, echo a notice.
 #
-refresh_adfiles: $(EXEC) $(SOURCE.AD)
+refresh_adfiles: $(EXEC) $(SOURCE.AD) $(ADLC_UPDATER)
 	@rm -rf $(TEMPDIR); mkdir $(TEMPDIR)
-	$(QUIETLY) [ -f $(ADLC_UPDATER) ] || ( cp $(ADLC_UPDATER_DIRECTORY)/$(ADLC_UPDATER) . ; chmod +x $(ADLC_UPDATER) )
 	$(QUIETLY) $(EXEC) $(ADLCFLAGS) $(SOURCE.AD) \
  -c$(TEMPDIR)/ad_$(Platform_arch_model).cpp -h$(TEMPDIR)/ad_$(Platform_arch_model).hpp -a$(TEMPDIR)/dfa_$(Platform_arch_model).cpp -v$(TEMPDIR)/adGlobals_$(Platform_arch_model).hpp \
 	    || { rm -rf $(TEMPDIR); exit 1; }
@@ -174,7 +185,15 @@
 # #########################################################################
 
 $(SOURCE.AD): $(SOURCES.AD)
-	$(QUIETLY) cat $(SOURCES.AD) > $(SOURCE.AD)
+	$(QUIETLY) $(PROCESS_AD_FILES) $(SOURCES.AD) > $(SOURCE.AD)
+
+#PROCESS_AD_FILES = cat
+# Pass through #line directives, in case user enables -g option above:
+PROCESS_AD_FILES = awk '{ \
+    if (CUR_FN != FILENAME) { CUR_FN=FILENAME; NR_BASE=NR-1; need_lineno=1 } \
+    if (need_lineno && $$0 !~ /\/\//) \
+      { print "\n\n\#line " (NR-NR_BASE) " \"" FILENAME "\""; need_lineno=0 }; \
+    print }'
 
 $(OUTDIR)/%.o: %.cpp
 	@echo Compiling $<
--- a/src/os/bsd/launcher/java.c	Sun Dec 28 11:28:04 2008 -0800
+++ b/src/os/bsd/launcher/java.c	Sun Dec 28 18:19:15 2008 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2006 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 1999-2008 Sun Microsystems, Inc.  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
--- a/src/os/bsd/launcher/java.h	Sun Dec 28 11:28:04 2008 -0800
+++ b/src/os/bsd/launcher/java.h	Sun Dec 28 18:19:15 2008 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2005 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 1999-2008 Sun Microsystems, Inc.  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
--- a/src/os/bsd/launcher/java_md.c	Sun Dec 28 11:28:04 2008 -0800
+++ b/src/os/bsd/launcher/java_md.c	Sun Dec 28 18:19:15 2008 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2005 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 1999-2008 Sun Microsystems, Inc.  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
--- a/src/os/bsd/vm/globals_bsd.hpp	Sun Dec 28 11:28:04 2008 -0800
+++ b/src/os/bsd/vm/globals_bsd.hpp	Sun Dec 28 18:19:15 2008 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2007 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2005-2008 Sun Microsystems, Inc.  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
--- a/src/os/bsd/vm/os_bsd.cpp	Sun Dec 28 11:28:04 2008 -0800
+++ b/src/os/bsd/vm/os_bsd.cpp	Sun Dec 28 18:19:15 2008 -0800
@@ -2579,7 +2579,9 @@
   uncommit_memory(addr, bytes);
 }
 
-void os::numa_make_global(char *addr, size_t bytes)    { }
+void os::numa_make_global(char *addr, size_t bytes) {
+  Bsd::numa_interleave_memory(addr, bytes);
+}
 
 void os::numa_make_local(char *addr, size_t bytes, int lgrp_hint) {
   Bsd::numa_tonode_memory(addr, bytes, lgrp_hint);
@@ -2621,7 +2623,7 @@
 extern "C" void numa_warn(int number, char *where, ...) { }
 extern "C" void numa_error(char *where) { }
 
-void os::Bsd::libnuma_init() {
+bool os::Bsd::libnuma_init() {
   // sched_getcpu() should be in libc.
   set_sched_getcpu(CAST_TO_FN_PTR(sched_getcpu_func_t,
                                   dlsym(RTLD_DEFAULT, "sched_getcpu")));
@@ -2637,31 +2639,51 @@
                                         dlsym(handle, "numa_available")));
       set_numa_tonode_memory(CAST_TO_FN_PTR(numa_tonode_memory_func_t,
                                             dlsym(handle, "numa_tonode_memory")));
+      set_numa_interleave_memory(CAST_TO_FN_PTR(numa_interleave_memory_func_t,
+                                            dlsym(handle, "numa_interleave_memory")));
+
+
       if (numa_available() != -1) {
+        set_numa_all_nodes((unsigned long*)dlsym(handle, "numa_all_nodes"));
         // Create a cpu -> node mapping
         _cpu_to_node = new (ResourceObj::C_HEAP) GrowableArray<int>(0, true);
         rebuild_cpu_to_node_map();
+        return true;
       }
     }
   }
+  return false;
 }
 
 // rebuild_cpu_to_node_map() constructs a table mapping cpud id to node id.
 // The table is later used in get_node_by_cpu().
 void os::Bsd::rebuild_cpu_to_node_map() {
-  int cpu_num = os::active_processor_count();
+  const size_t NCPUS = 32768; // Since the buffer size computation is very obscure
+                              // in libnuma (possible values are starting from 16,
+                              // and continuing up with every other power of 2, but less
+                              // than the maximum number of CPUs supported by kernel), and
+                              // is a subject to change (in libnuma version 2 the requirements
+                              // are more reasonable) we'll just hardcode the number they use
+                              // in the library.
+  const size_t BitsPerCLong = sizeof(long) * CHAR_BIT;
+
+  size_t cpu_num = os::active_processor_count();
+  size_t cpu_map_size = NCPUS / BitsPerCLong;
+  size_t cpu_map_valid_size =
+    MIN2((cpu_num + BitsPerCLong - 1) / BitsPerCLong, cpu_map_size);
+
   cpu_to_node()->clear();
   cpu_to_node()->at_grow(cpu_num - 1);
-  int node_num = numa_get_groups_num();
-  int cpu_map_size = (cpu_num + BitsPerLong - 1) / BitsPerLong;
+  size_t node_num = numa_get_groups_num();
+
   unsigned long *cpu_map = NEW_C_HEAP_ARRAY(unsigned long, cpu_map_size);
-  for (int i = 0; i < node_num; i++) {
+  for (size_t i = 0; i < node_num; i++) {
     if (numa_node_to_cpus(i, cpu_map, cpu_map_size * sizeof(unsigned long)) != -1) {
-      for (int j = 0; j < cpu_map_size; j++) {
+      for (size_t j = 0; j < cpu_map_valid_size; j++) {
         if (cpu_map[j] != 0) {
-          for (int k = 0; k < BitsPerLong; k++) {
+          for (size_t k = 0; k < BitsPerCLong; k++) {
             if (cpu_map[j] & (1UL << k)) {
-              cpu_to_node()->at_put(j * BitsPerLong + k, i);
+              cpu_to_node()->at_put(j * BitsPerCLong + k, i);
             }
           }
         }
@@ -2684,7 +2706,8 @@
 os::Bsd::numa_max_node_func_t os::Bsd::_numa_max_node;
 os::Bsd::numa_available_func_t os::Bsd::_numa_available;
 os::Bsd::numa_tonode_memory_func_t os::Bsd::_numa_tonode_memory;
-
+os::Bsd::numa_interleave_memory_func_t os::Bsd::_numa_interleave_memory;
+unsigned long* os::Bsd::_numa_all_nodes;
 
 bool os::uncommit_memory(char* addr, size_t size) {
 #ifdef __OpenBSD__
@@ -2789,7 +2812,7 @@
 }
 
 bool os::unguard_memory(char* addr, size_t size) {
-  return bsd_mprotect(addr, size, PROT_READ|PROT_WRITE|PROT_EXEC);
+  return bsd_mprotect(addr, size, PROT_READ|PROT_WRITE);
 }
 
 // Large page support
@@ -4117,7 +4140,17 @@
 #endif
 
   if (UseNUMA) {
-    Bsd::libnuma_init();
+    if (!Bsd::libnuma_init()) {
+      UseNUMA = false;
+    } else {
+      if ((Bsd::numa_max_node() < 1)) {
+        // There's only one node(they start from 0), disable NUMA.
+        UseNUMA = false;
+      }
+    }
+    if (!UseNUMA && ForceNUMA) {
+      UseNUMA = true;
+    }
   }
 
   if (MaxFDLimit) {
--- a/src/os/bsd/vm/os_bsd.hpp	Sun Dec 28 11:28:04 2008 -0800
+++ b/src/os/bsd/vm/os_bsd.hpp	Sun Dec 28 18:19:15 2008 -0800
@@ -191,7 +191,7 @@
 
   static void libpthread_init();
 #endif
-  static void libnuma_init();
+  static bool libnuma_init();
 
   // Minimum stack size a thread can be created with (allowing
   // the VM to completely create the thread and enter user code)
@@ -291,20 +291,23 @@
   typedef int (*numa_max_node_func_t)(void);
   typedef int (*numa_available_func_t)(void);
   typedef int (*numa_tonode_memory_func_t)(void *start, size_t size, int node);
-
+  typedef void (*numa_interleave_memory_func_t)(void *start, size_t size, unsigned long *nodemask);
 
   static sched_getcpu_func_t _sched_getcpu;
   static numa_node_to_cpus_func_t _numa_node_to_cpus;
   static numa_max_node_func_t _numa_max_node;
   static numa_available_func_t _numa_available;
   static numa_tonode_memory_func_t _numa_tonode_memory;
+  static numa_interleave_memory_func_t _numa_interleave_memory;
+  static unsigned long* _numa_all_nodes;
 
   static void set_sched_getcpu(sched_getcpu_func_t func) { _sched_getcpu = func; }
   static void set_numa_node_to_cpus(numa_node_to_cpus_func_t func) { _numa_node_to_cpus = func; }
   static void set_numa_max_node(numa_max_node_func_t func) { _numa_max_node = func; }
   static void set_numa_available(numa_available_func_t func) { _numa_available = func; }
   static void set_numa_tonode_memory(numa_tonode_memory_func_t func) { _numa_tonode_memory = func; }
-
+  static void set_numa_interleave_memory(numa_interleave_memory_func_t func) { _numa_interleave_memory = func; }
+  static void set_numa_all_nodes(unsigned long* ptr) { _numa_all_nodes = ptr; }
 public:
   static int sched_getcpu()  { return _sched_getcpu != NULL ? _sched_getcpu() : -1; }
   static int numa_node_to_cpus(int node, unsigned long *buffer, int bufferlen) {
@@ -315,6 +318,11 @@
   static int numa_tonode_memory(void *start, size_t size, int node) {
     return _numa_tonode_memory != NULL ? _numa_tonode_memory(start, size, node) : -1;
   }
+  static void numa_interleave_memory(void *start, size_t size) {
+    if (_numa_interleave_memory != NULL && _numa_all_nodes != NULL) {
+      _numa_interleave_memory(start, size, _numa_all_nodes);
+    }
+  }
   static int get_node_by_cpu(int cpu_id);
 };
 
--- a/src/os_cpu/bsd_x86/vm/bsd_x86_32.ad	Sun Dec 28 11:28:04 2008 -0800
+++ b/src/os_cpu/bsd_x86/vm/bsd_x86_32.ad	Sun Dec 28 18:19:15 2008 -0800
@@ -1,5 +1,5 @@
 //
-// Copyright 1999-2006 Sun Microsystems, Inc.  All Rights Reserved.
+// Copyright 1999-2008 Sun Microsystems, Inc.  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
--- a/src/os_cpu/bsd_x86/vm/os_bsd_x86.cpp	Sun Dec 28 11:28:04 2008 -0800
+++ b/src/os_cpu/bsd_x86/vm/os_bsd_x86.cpp	Sun Dec 28 18:19:15 2008 -0800
@@ -574,10 +574,11 @@
       if (addr != last_addr &&
           (UnguardOnExecutionViolation > 1 || os::address_is_in_vm(addr))) {
 
-        // Unguard and retry
+        // Set memory to RWX and retry
         address page_start =
           (address) align_size_down((intptr_t) addr, (intptr_t) page_size);
-        bool res = os::unguard_memory((char*) page_start, page_size);
+        bool res = os::protect_memory((char*) page_start, page_size,
+                                      os::MEM_PROT_RWX);
 
         if (PrintMiscellaneous && Verbose) {
           char buf[256];