Skip to content

Commit

Permalink
Merge pull request #61 from dugiahuy/support-macos
Browse files Browse the repository at this point in the history
Support MacOS for running MMTk Ruby binding
  • Loading branch information
wks authored Apr 11, 2024
2 parents 5ed7951 + 52ac798 commit d64eda9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions mmtk_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#include "vm_sync.h"
#include "stdatomic.h"

#ifdef __APPLE__
#include <sys/sysctl.h>
#endif

#ifdef __GNUC__
#define PREFETCH(addr, write_p) __builtin_prefetch(addr, write_p)
#define EXPECT(expr, val) __builtin_expect(expr, val)
Expand Down Expand Up @@ -218,6 +222,17 @@ rb_mmtk_system_physical_memory(void)
rb_bug("failed to get system physical memory size");
}
return (size_t) physical_pages * (size_t) page_size;
#elif defined(__APPLE__)
int mib[2];
mib[0] = CTL_HW;
mib[1] = HW_MEMSIZE; // total physical memory
int64_t physical_memory;
size_t length = sizeof(int64_t);
if (sysctl(mib, 2, &physical_memory, &length, NULL, 0) == -1)
{
rb_bug("failed to get system physical memory size");
}
return (size_t) physical_memory;
#else
#error no implementation of rb_mmtk_system_physical_memory on this platform
#endif
Expand Down
4 changes: 2 additions & 2 deletions tool/m4/mmtk_ruby.m4
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
dnl -*- Autoconf -*-
AC_DEFUN([MMTK_RUBY], [
[MMTK_RUBY_SO_NAME=libmmtk_ruby.so]
[MMTK_RUBY_SO_NAME=libmmtk_ruby.$SOEXT]
AC_ARG_WITH(mmtk-ruby,
AS_HELP_STRING([--with-mmtk-ruby=DIR],
Expand Down Expand Up @@ -31,7 +31,7 @@ AS_IF([test -n "$with_mmtk_ruby"], [
AC_MSG_NOTICE([User specified the path to $MMTK_RUBY_SO_NAME: $with_mmtk_ruby_so])
mmtk_ruby_so_basename=$(basename $with_mmtk_ruby_so)
AS_IF([test "x$mmtk_ruby_so_basename" != "x$MMTK_RUBY_SO_NAME"],[
AC_MSG_ERROR([The base name must be $MMTK_RUBY_SO_NAME Found: $mmtk_ruby_so_basename])
AC_MSG_ERROR([The base name must be $MMTK_RUBY_SO_NAME. Found: $mmtk_ruby_so_basename])
])
mmtk_ruby_so_path="$with_mmtk_ruby_so"
mmtk_ruby_build_suggestion="Please build it first"
Expand Down

0 comments on commit d64eda9

Please sign in to comment.