changeset 50699:1ff7fb9125f8

Merge
author prr
date Wed, 16 May 2018 09:45:40 -0700
parents d93ae85b18c1 7db531b83661
children e2eff4dcebbd
files src/hotspot/share/runtime/vmStructs_trace.hpp src/hotspot/share/trace/noTraceBackend.hpp src/hotspot/share/trace/trace.dtd src/hotspot/share/trace/trace.xml src/hotspot/share/trace/traceBackend.cpp src/hotspot/share/trace/traceBackend.hpp src/hotspot/share/trace/traceDataTypes.hpp src/hotspot/share/trace/traceEvent.hpp src/hotspot/share/trace/traceEventClasses.xsl src/hotspot/share/trace/traceEventIds.xsl src/hotspot/share/trace/traceMacros.hpp src/hotspot/share/trace/traceStream.cpp src/hotspot/share/trace/traceStream.hpp src/hotspot/share/trace/traceTime.hpp src/hotspot/share/trace/traceTypes.xsl src/hotspot/share/trace/traceevents.xml src/hotspot/share/trace/tracerelationdecls.xml src/hotspot/share/trace/tracetypes.xml src/hotspot/share/trace/tracing.hpp src/hotspot/share/trace/tracingExport.cpp src/hotspot/share/trace/tracingExport.hpp src/hotspot/share/trace/xinclude.mod src/hotspot/share/trace/xsl_util.xsl src/hotspot/share/utilities/ticks.inline.hpp src/java.base/macosx/conf/x86_64/jvm.cfg src/java.base/unix/conf/aarch64/jvm.cfg src/java.base/unix/conf/amd64/jvm.cfg src/java.base/unix/conf/arm/jvm.cfg src/java.base/unix/conf/i586/jvm.cfg src/java.base/unix/conf/ia64/jvm.cfg src/java.base/unix/conf/ppc64/jvm.cfg src/java.base/unix/conf/ppc64le/jvm.cfg src/java.base/unix/conf/s390x/jvm.cfg src/java.base/unix/conf/sparc/jvm.cfg src/java.base/unix/conf/sparcv9/jvm.cfg src/java.base/unix/conf/zero/jvm.cfg src/java.base/windows/conf/amd64/jvm.cfg src/java.base/windows/conf/i586/jvm.cfg src/java.base/windows/conf/ia64/jvm.cfg test/jdk/ProblemList.txt test/jdk/TEST.ROOT test/jdk/TEST.groups
diffstat 1155 files changed, 122383 insertions(+), 4192 deletions(-) [+]
line wrap: on
line diff
--- a/make/CompileJavaModules.gmk	Tue May 15 10:13:52 2018 -0700
+++ b/make/CompileJavaModules.gmk	Wed May 16 09:45:40 2018 -0700
@@ -509,6 +509,15 @@
 # Exclude BreakIterator classes that are just used in compile process to generate
 # data files and shouldn't go in the product
 jdk.localedata_EXCLUDE_FILES += sun/text/resources/ext/BreakIteratorRules_th.java
+################################################################################
+
+# There is an issue in sjavac that triggers a warning in jdk.jfr that isn't
+# triggered without sjavac.
+ifeq ($(ENABLE_SJAVAC), yes)
+  jdk.jfr_SETUP := GENERATE_JDKBYTECODE_NOWARNINGS
+endif
+jdk.jfr_COPY := .xsd .xml .dtd
+jdk.jfr_ADD_JAVAC_FLAGS := -XDstringConcat=inline -Xlint:-exports
 
 ################################################################################
 # If this is an imported module that has prebuilt classes, only compile
--- a/make/autoconf/hotspot.m4	Tue May 15 10:13:52 2018 -0700
+++ b/make/autoconf/hotspot.m4	Wed May 16 09:45:40 2018 -0700
@@ -26,7 +26,7 @@
 # All valid JVM features, regardless of platform
 VALID_JVM_FEATURES="compiler1 compiler2 zero minimal dtrace jvmti jvmci \
     graal vm-structs jni-check services management cmsgc g1gc parallelgc serialgc nmt cds \
-    static-build link-time-opt aot"
+    static-build link-time-opt aot jfr"
 
 # All valid JVM variants
 VALID_JVM_VARIANTS="server client minimal core zero custom"
@@ -309,6 +309,11 @@
     AC_MSG_ERROR([Specified JVM feature 'cmsgc' requires feature 'serialgc'])
   fi
 
+  # Enable JFR by default, except on linux-sparcv9 and on minimal.
+  if test "x$OPENJDK_TARGET_OS" != xlinux || test "x$OPENJDK_TARGET_CPU" != xsparcv9; then
+    NON_MINIMAL_FEATURES="$NON_MINIMAL_FEATURES jfr"
+  fi
+
   # Turn on additional features based on other parts of configure
   if test "x$INCLUDE_DTRACE" = "xtrue"; then
     JVM_FEATURES="$JVM_FEATURES dtrace"
@@ -396,7 +401,7 @@
     NON_MINIMAL_FEATURES="$NON_MINIMAL_FEATURES cds"
   fi
 
-  # Enable default features depending on variant.
+  # Enable features depending on variant.
   JVM_FEATURES_server="compiler1 compiler2 $NON_MINIMAL_FEATURES $JVM_FEATURES $JVM_FEATURES_jvmci $JVM_FEATURES_aot $JVM_FEATURES_graal"
   JVM_FEATURES_client="compiler1 $NON_MINIMAL_FEATURES $JVM_FEATURES $JVM_FEATURES_jvmci"
   JVM_FEATURES_core="$NON_MINIMAL_FEATURES $JVM_FEATURES"
--- a/make/autoconf/libraries.m4	Tue May 15 10:13:52 2018 -0700
+++ b/make/autoconf/libraries.m4	Wed May 16 09:45:40 2018 -0700
@@ -130,7 +130,7 @@
 
   if test "x$OPENJDK_TARGET_OS" = xsolaris; then
     BASIC_JVM_LIBS="$BASIC_JVM_LIBS -lsocket -lsched -ldoor -ldemangle -lnsl \
-        -lrt"
+        -lrt -lkstat"
     BASIC_JVM_LIBS="$BASIC_JVM_LIBS $LIBCXX_JVM"
   fi
 
--- a/make/common/Modules.gmk	Tue May 15 10:13:52 2018 -0700
+++ b/make/common/Modules.gmk	Wed May 16 09:45:40 2018 -0700
@@ -59,7 +59,9 @@
     java.security.sasl \
     java.xml \
     jdk.internal.vm.ci \
+    jdk.jfr \
     jdk.management \
+    jdk.management.jfr \
     jdk.management.agent \
     jdk.net \
     jdk.sctp \
@@ -152,6 +154,7 @@
     jdk.jdeps \
     jdk.jdi \
     jdk.jdwp.agent \
+    jdk.jfr \
     jdk.jlink \
     jdk.jsobject \
     jdk.jshell \
@@ -159,6 +162,7 @@
     jdk.localedata \
     jdk.management \
     jdk.management.agent \
+    jdk.management.jfr \
     jdk.naming.dns \
     jdk.naming.rmi \
     jdk.net \
--- a/make/common/NativeCompilation.gmk	Tue May 15 10:13:52 2018 -0700
+++ b/make/common/NativeCompilation.gmk	Wed May 16 09:45:40 2018 -0700
@@ -391,6 +391,13 @@
 #   STRIPFLAGS Optionally change the flags given to the strip command
 #   PRECOMPILED_HEADER Header file to use as precompiled header
 #   PRECOMPILED_HEADER_EXCLUDE List of source files that should not use PCH
+#
+# After being called, some variables are exported from this macro, all prefixed
+# with parameter 1 followed by a '_':
+#   TARGET The library or executable created by the macro
+#   TARGET_DEPS All prerequisites for the target calculated by the macro
+#   ALL_OBJS All object files
+#   IMPORT_LIBRARY The import library created for a shared library on Windows
 SetupNativeCompilation = $(NamedParamsMacroTemplate)
 define SetupNativeCompilationBody
 
@@ -874,7 +881,9 @@
       endif
     endif
 
-    $$($1_TARGET): $$($1_ALL_OBJS) $$($1_RES) $$($1_VARDEPS_FILE) $$(STATIC_MAPFILE_DEP)
+    $1_TARGET_DEPS := $$($1_ALL_OBJS) $$($1_RES) $$($1_VARDEPS_FILE) $$(STATIC_MAPFILE_DEP)
+
+    $$($1_TARGET): $$($1_TARGET_DEPS)
 	$$(call LogInfo, Building static library $$($1_BASENAME))
 	$$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
 	    $$($1_AR) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_ALL_OBJS) \
@@ -964,8 +973,10 @@
       endif
     endif
 
-    $$($1_TARGET): $$($1_ALL_OBJS) $$($1_RES) $$($1_MANIFEST) \
+    $1_TARGET_DEPS := $$($1_ALL_OBJS) $$($1_RES) $$($1_MANIFEST) \
         $$($1_REAL_MAPFILE) $$($1_VARDEPS_FILE)
+
+    $$($1_TARGET): $$($1_TARGET_DEPS)
                 ifneq ($$($1_OBJ_FILE_LIST), )
                   ifeq ($$($1_LINK_OBJS_RELATIVE), true)
 		    $$(eval $$(call ListPathsSafely, $1_ALL_OBJS_RELATIVE, $$($1_OBJ_FILE_LIST)))
--- a/make/copy/Copy-java.base.gmk	Tue May 15 10:13:52 2018 -0700
+++ b/make/copy/Copy-java.base.gmk	Wed May 16 09:45:40 2018 -0700
@@ -79,76 +79,44 @@
 endif
 
 ################################################################################
-#
-# How to install jvm.cfg.
-#
-ifeq ($(call check-jvm-variant, zero), true)
-  JVMCFG_ARCH := zero
-else
-  JVMCFG_ARCH := $(OPENJDK_TARGET_CPU_LEGACY)
+# In jvm.cfg, the first listed KNOWN variant is the default. On most build
+# configurations, that is the server variant.
+ifeq ($(OPENJDK_TARGET_OS)-$(OPENJDK_TARGET_CPU), windows-x86)
+  DEFAULT_CFG_VARIANT ?= client
 endif
+DEFAULT_CFG_VARIANT ?= server
 
-ifeq ($(OPENJDK_TARGET_OS), macosx)
-  JVMCFG_SRC := $(TOPDIR)/src/java.base/macosx/conf/$(JVMCFG_ARCH)/jvm.cfg
-else
-  JVMCFG_SRC := $(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/conf/$(JVMCFG_ARCH)/jvm.cfg
-  # Allow override by ALT_JVMCFG_SRC if it exists
-  JVMCFG_SRC := $(if $(wildcard $(ALT_JVMCFG_SRC)),$(ALT_JVMCFG_SRC),$(JVMCFG_SRC))
-endif
+# Any variant other than server, client or minimal is represented as server in
+# the cfg file.
+VALID_CFG_VARIANTS := server client minimal
+CFG_VARIANTS := $(filter $(VALID_CFG_VARIANTS), $(JVM_VARIANTS)) \
+    $(if $(filter-out $(VALID_CFG_VARIANTS), $(JVM_VARIANTS)), server)
+
+# Change the order to put the default variant first if present.
+ORDERED_CFG_VARIANTS := \
+    $(if $(filter $(DEFAULT_CFG_VARIANT), $(CFG_VARIANTS)), $(DEFAULT_CFG_VARIANT)) \
+    $(filter-out $(DEFAULT_CFG_VARIANT), $(CFG_VARIANTS))
+
 JVMCFG := $(LIB_DST_DIR)/jvm.cfg
 
-ifeq ($(OPENJDK_TARGET_CPU_BITS), 64)
-  COPY_JVM_CFG_FILE := true
-else
-  # On 32-bit machines we have three potential VMs: client, server and minimal.
-  # Historically we usually have both client and server and so that is what the
-  # committed jvm.cfg expects (including platform specific ergonomics switches
-  # to decide whether to use client or server by default). So when we have anything
-  # other than client and server we need to define a new jvm.cfg file.
-  # The main problem is deciding whether to use aliases for the VMs that are not
-  # present and the current position is that we add aliases for client and server, but
-  # not for minimal.
-  CLIENT_AND_SERVER := $(call check-jvm-variant, client)+$(call check-jvm-variant, server)
-  ifeq ($(CLIENT_AND_SERVER), true+true)
-    COPY_JVM_CFG_FILE := true
-  else
-    # For zero, the default jvm.cfg file is sufficient
-    ifeq ($(call check-jvm-variant, zero), true)
-      COPY_JVM_CFG_FILE := true
-    endif
-  endif
-endif
+define print-cfg-line
+	$(call LogInfo, Adding -$1 $2 to jvm.cfg)
+	$(PRINTF) -- "-$1 $2\n" >> $@ $(NEWLINE)
+endef
 
-ifeq ($(COPY_JVM_CFG_FILE), true)
-  $(JVMCFG): $(JVMCFG_SRC)
-	$(call install-file)
-else
-  $(JVMCFG):
-	$(MKDIR) -p $(@D)
-	$(RM) $(@)
-        # Now check for other permutations
-        ifeq ($(call check-jvm-variant, server), true)
-	  $(PRINTF) -- "-server KNOWN\n">>$(@)
-	  $(PRINTF) -- "-client ALIASED_TO -server\n">>$(@)
-          ifeq ($(call check-jvm-variant, minimal), true)
-	    $(PRINTF) -- "-minimal KNOWN\n">>$(@)
-          endif
-        else
-          ifeq ($(call check-jvm-variant, client), true)
-	    $(PRINTF) -- "-client KNOWN\n">>$(@)
-	    $(PRINTF) -- "-server ALIASED_TO -client\n">>$(@)
-            ifeq ($(call check-jvm-variant, minimal), true)
-	      $(PRINTF) -- "-minimal KNOWN\n">>$(@)
-            endif
-          else
-            ifeq ($(call check-jvm-variant, minimal), true)
-	      $(PRINTF) -- "-minimal KNOWN\n">>$(@)
-	      $(PRINTF) -- "-server ALIASED_TO -minimal\n">>$(@)
-	      $(PRINTF) -- "-client ALIASED_TO -minimal\n">>$(@)
-            endif
-          endif
-        endif
-endif
+$(JVMCFG): $(call DependOnVariable, ORDERED_CFG_VARIANTS)
+	$(call MakeTargetDir)
+	$(RM) $@
+	$(foreach v, $(ORDERED_CFG_VARIANTS), \
+	  $(call print-cfg-line,$v,KNOWN) \
+	)
+        # If either of server or client aren't present, add IGNORE lines for
+        # them.
+	$(foreach v, server client, \
+	  $(if $(filter $v, $(ORDERED_CFG_VARIANTS)), , \
+	    $(call print-cfg-line,$v,IGNORE) \
+	  ) \
+	)
 
 TARGETS += $(JVMCFG)
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make/copy/Copy-jdk.jfr.gmk	Wed May 16 09:45:40 2018 -0700
@@ -0,0 +1,46 @@
+#
+# Copyright (c) 2014, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+include CopyCommon.gmk
+
+################################################################################
+
+$(eval $(call SetupCopyFiles, COPY_JFR_METADATA, \
+    SRC := $(TOPDIR)/src/hotspot/share/jfr/metadata, \
+    DEST := $(JDK_OUTPUTDIR)/modules/jdk.jfr/jdk/jfr/internal/types, \
+    FILES := metadata.xml \
+))
+
+TARGETS += $(COPY_JFR_METADATA)
+
+JFR_CONF_DIR := $(TOPDIR)/src/jdk.jfr/share/conf/jfr
+$(eval $(call SetupCopyFiles, COPY_JFR_CONF, \
+    DEST := $(LIB_DST_DIR)/jfr, \
+    FILES := $(wildcard $(JFR_CONF_DIR)/*.jfc), \
+    FLATTEN := true, \
+))
+TARGETS += $(COPY_JFR_CONF)
+
+################################################################################
--- a/make/hotspot/gensrc/GenerateSources.gmk	Tue May 15 10:13:52 2018 -0700
+++ b/make/hotspot/gensrc/GenerateSources.gmk	Wed May 16 09:45:40 2018 -0700
@@ -38,6 +38,7 @@
 include gensrc/GensrcAdlc.gmk
 include gensrc/GensrcDtrace.gmk
 include gensrc/GensrcJvmti.gmk
+include gensrc/GensrcJfr.gmk
 
 $(eval $(call IncludeCustomExtension, hotspot/gensrc/GenerateSources.gmk))
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make/hotspot/gensrc/GensrcJfr.gmk	Wed May 16 09:45:40 2018 -0700
@@ -0,0 +1,94 @@
+#
+# Copyright (c) 2013, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+$(eval $(call IncludeCustomExtension, hotspot/gensrc/GensrcJfr.gmk))
+
+################################################################################
+# Build tools needed for the Jfr source code generation
+
+JFR_TOOLS_SRCDIR := $(TOPDIR)/src/hotspot/share/jfr/metadata
+JFR_TOOLS_OUTPUTDIR := $(JVM_VARIANT_OUTPUTDIR)/tools/jfr
+
+$(eval $(call SetupJavaCompiler, GENERATE_JFRBYTECODE, \
+    JAVAC := $(JAVAC), \
+    FLAGS := $(DISABLE_WARNINGS), \
+    SERVER_DIR := $(SJAVAC_SERVER_DIR), \
+    SERVER_JVM := $(SJAVAC_SERVER_JAVA), \
+    DISABLE_SJAVAC := true, \
+))
+
+$(eval $(call SetupJavaCompilation, BUILD_JFR_TOOLS, \
+    SETUP := GENERATE_JFRBYTECODE, \
+    SRC := $(JFR_TOOLS_SRCDIR), \
+    INCLUDE_FILES := GenerateJfrFiles.java, \
+    BIN := $(JFR_TOOLS_OUTPUTDIR), \
+))
+
+TOOL_JFR_GEN := $(JAVA_SMALL) -cp $(JFR_TOOLS_OUTPUTDIR) GenerateJfrFiles
+
+################################################################################
+# Setup make rules for Jfr file file generation.
+#
+# Parameter 1 is the name of the rule. This name is used as variable prefix,
+# and the targets generated are listed in a variable by that name. This name is
+# also used as the name of the output file.
+#
+# Remaining parameters are named arguments. These include:
+#   XML_FILE -- The input source file to use
+#   XSD_FILE -- The input schema for validation
+#   OUTPUT_DIR -- The directory to put the generated file in
+SetupJfrGeneration = $(NamedParamsMacroTemplate)
+define SetupJfrGenerationBody
+  $$($1_OUTPUT_DIR)/$1: $$($1_XML_FILE) $$($1_XSD_FILE) $$(BUILD_JFR_TOOLS)
+	$$(call LogInfo, Generating $$(@F))
+	$$(call MakeDir, $$(@D))
+	$$(call ExecuteWithLog, $$@, $$(TOOL_JFR_GEN) $$($1_XML_FILE) $$($1_XSD_FILE) $$($1_OUTPUT_DIR))
+	test -f $$@
+
+  TARGETS += $$($1_OUTPUT_DIR)/$1
+
+endef
+
+################################################################################
+# Create files in gensrc/jfrfiles
+
+JFR_OUTPUTDIR := $(JVM_VARIANT_OUTPUTDIR)/gensrc/jfrfiles
+JFR_SRCDIR := $(TOPDIR)/src/hotspot/share/jfr/metadata
+
+METADATA_XML ?= $(JFR_SRCDIR)/metadata.xml
+METADATA_XSD ?= $(JFR_SRCDIR)/metadata.xsd
+
+# Changing these will trigger a rebuild of generated jfr files.
+JFR_DEPS += \
+    $(METADATA_XML) \
+    $(METADATA_XSD) \
+    #
+
+# our generator will generate all files in one go, so only need to setup one target rule
+$(eval $(call SetupJfrGeneration, jfrEventClasses.hpp, \
+    XML_FILE := $(METADATA_XML), \
+    XSD_FILE := $(METADATA_XSD), \
+    OUTPUT_DIR := $(JFR_OUTPUTDIR), \
+))
\ No newline at end of file
--- a/make/hotspot/gensrc/GensrcJvmti.gmk	Tue May 15 10:13:52 2018 -0700
+++ b/make/hotspot/gensrc/GensrcJvmti.gmk	Wed May 16 09:45:40 2018 -0700
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2013, 2018, 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
@@ -50,7 +50,7 @@
 TOOL_JVMTI_ENV_FILL := $(JAVA_SMALL) -cp $(JVMTI_TOOLS_OUTPUTDIR) jvmtiEnvFill
 
 ################################################################################
-# Setup make rules for an xml transform for jvmti/trace file generation.
+# Setup make rules for an xml transform for jvmti file generation.
 #
 # Parameter 1 is the name of the rule. This name is used as variable prefix,
 # and the targets generated are listed in a variable by that name. This name is
@@ -126,48 +126,3 @@
 
   TARGETS += $(COPY_JVMTI_H)
 endif
-
-################################################################################
-# Create trace files in gensrc/tracefiles
-
-TRACE_OUTPUTDIR := $(JVM_VARIANT_OUTPUTDIR)/gensrc/tracefiles
-TRACE_SRCDIR := $(TOPDIR)/src/hotspot/share/trace
-
-# Append list of XSL files to search (might have been set by custom extensions)
-TRACE_XSL_FILES += $(wildcard $(TRACE_SRCDIR)/*.xsl)
-
-TRACE_XML ?= $(TRACE_SRCDIR)/trace.xml
-
-# Changing these will trigger a rebuild of generated trace files.
-TRACE_DEPS += \
-    $(TRACE_XML) \
-    $(TRACE_SRCDIR)/tracetypes.xml \
-    $(TRACE_SRCDIR)/tracerelationdecls.xml \
-    $(TRACE_SRCDIR)/traceevents.xml \
-    $(TRACE_SRCDIR)/trace.dtd \
-    $(TRACE_SRCDIR)/xinclude.mod \
-    #
-
-# Setup rule for generating a trace file
-#
-# $1 is generated source file name in $(TRACE_OUTPUTDIR)
-define SetupTraceGeneration
-  $$(eval $$(call SetupXslTransform, $1, \
-      XML_FILE := $$(TRACE_XML), \
-      XSL_FILE := $$(firstword $$(filter %/$$(basename $1).xsl, $$(TRACE_XSL_FILES))), \
-      OUTPUT_DIR := $$(TRACE_OUTPUTDIR), \
-      DEPS := $$(TRACE_DEPS), \
-  ))
-endef
-
-# Append files to generated (might have been set by custom extensions)
-TRACE_GENSRC_FILES += \
-    traceEventClasses.hpp \
-    traceEventIds.hpp \
-    traceTypes.hpp \
-    #
-
-# Call SetupTraceGeneration for all trace gensrc files
-$(foreach tracefile, $(TRACE_GENSRC_FILES), \
-  $(eval $(call SetupTraceGeneration, $(tracefile))) \
-)
--- a/make/hotspot/lib/CompileJvm.gmk	Tue May 15 10:13:52 2018 -0700
+++ b/make/hotspot/lib/CompileJvm.gmk	Wed May 16 09:45:40 2018 -0700
@@ -177,6 +177,13 @@
     PRECOMPILED_HEADER_EXCLUDE := $(JVM_PRECOMPILED_HEADER_EXCLUDE), \
 ))
 
+# Always recompile vm_version.cpp if libjvm needs to be relinked. This ensures
+# that the internal vm version is updated as it relies on __DATE__ and __TIME__
+# macros.
+VM_VERSION_OBJ := $(JVM_OUTPUTDIR)/objs/vm_version$(OBJ_SUFFIX)
+$(VM_VERSION_OBJ): $(filter-out $(VM_VERSION_OBJ) $(JVM_MAPFILE), \
+    $(BUILD_LIBJVM_TARGET_DEPS))
+
 ifeq ($(OPENJDK_TARGET_OS), windows)
   # It doesn't matter which jvm.lib file gets exported, but we need
   # to pick just one.
--- a/make/hotspot/lib/JvmFeatures.gmk	Tue May 15 10:13:52 2018 -0700
+++ b/make/hotspot/lib/JvmFeatures.gmk	Wed May 16 09:45:40 2018 -0700
@@ -154,6 +154,12 @@
   # If serial is disabled, we cannot use serial as OldGC in parallel
   JVM_EXCLUDE_FILES += psMarkSweep.cpp psMarkSweepDecorator.cpp
 endif
+
+ifneq ($(call check-jvm-feature, jfr), true)
+  JVM_CFLAGS_FEATURES += -DINCLUDE_JFR=0
+  JVM_EXCLUDE_PATTERNS += jfr
+endif
+
 ################################################################################
 
 ifeq ($(call check-jvm-feature, link-time-opt), true)
--- a/make/hotspot/src/classes/build/tools/projectcreator/BuildConfig.java	Tue May 15 10:13:52 2018 -0700
+++ b/make/hotspot/src/classes/build/tools/projectcreator/BuildConfig.java	Wed May 16 09:45:40 2018 -0700
@@ -223,7 +223,7 @@
         sysDefines.add("_WINDOWS");
         sysDefines.add("HOTSPOT_BUILD_USER=\\\""+System.getProperty("user.name")+"\\\"");
         sysDefines.add("HOTSPOT_BUILD_TARGET=\\\""+get("Build")+"\\\"");
-        sysDefines.add("INCLUDE_TRACE=1");
+        sysDefines.add("INCLUDE_JFR=1");
         sysDefines.add("_JNI_IMPLEMENTATION_");
         if (vars.get("PlatformName").equals("Win32")) {
             sysDefines.add("HOTSPOT_LIB_ARCH=\\\"i386\\\"");
--- a/make/jprt.properties	Tue May 15 10:13:52 2018 -0700
+++ b/make/jprt.properties	Wed May 16 09:45:40 2018 -0700
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2006, 2018, 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
@@ -273,6 +273,7 @@
     ${my.test.target.set:TESTNAME=jdk_instrument},			\
     ${my.test.target.set:TESTNAME=jdk_jmx},				\
     ${my.test.target.set:TESTNAME=jdk_jdi},				\
+    ${my.test.target.set:TESTNAME=jdk_jfr},                             \
     ${my.test.target.set:TESTNAME=svc_tools},                           \
     ${my.make.rule.test.targets.svc.extra}
 
--- a/make/launcher/Launcher-jdk.pack.gmk	Tue May 15 10:13:52 2018 -0700
+++ b/make/launcher/Launcher-jdk.pack.gmk	Wed May 16 09:45:40 2018 -0700
@@ -39,6 +39,7 @@
 # On Mac, we have always exported all symbols, probably due to oversight
 # and/or misunderstanding. To emulate this, don't hide any symbols
 # by default.
+# On AIX/xlc we need at least xlc 13.1 for the symbol hiding
 # Also provide an override for non-conformant libraries.
 ifeq ($(TOOLCHAIN_TYPE), gcc)
   CXXFLAGS_JDKEXE += -fvisibility=hidden
@@ -50,7 +51,9 @@
 else ifeq ($(TOOLCHAIN_TYPE), solstudio)
   CXXFLAGS_JDKEXE += -xldscope=hidden
 else ifeq ($(TOOLCHAIN_TYPE), xlc)
-  CXXFLAGS_JDKEXE += -qvisibility=hidden
+  ifneq ($(CC_VERSION_NUMBER), 12.1)
+    CXXFLAGS_JDKEXE += -qvisibility=hidden
+  endif
 endif
 
 UNPACKEXE_SRC := $(TOPDIR)/src/jdk.pack/share/native/common-unpack \
--- a/make/launcher/LauncherCommon.gmk	Tue May 15 10:13:52 2018 -0700
+++ b/make/launcher/LauncherCommon.gmk	Wed May 16 09:45:40 2018 -0700
@@ -45,6 +45,7 @@
 # On Mac, we have always exported all symbols, probably due to oversight
 # and/or misunderstanding. To emulate this, don't hide any symbols
 # by default.
+# On AIX/xlc we need at least xlc 13.1 for the symbol hiding
 # Also provide an override for non-conformant libraries.
 ifeq ($(TOOLCHAIN_TYPE), gcc)
   LAUNCHER_CFLAGS += -fvisibility=hidden
@@ -56,7 +57,9 @@
 else ifeq ($(TOOLCHAIN_TYPE), solstudio)
   LAUNCHER_CFLAGS += -xldscope=hidden
 else ifeq ($(TOOLCHAIN_TYPE), xlc)
-  LAUNCHER_CFLAGS += -qvisibility=hidden
+  ifneq ($(CC_VERSION_NUMBER), 12.1)
+    CXXFLAGS_JDKEXE += -qvisibility=hidden
+  endif
 endif
 
 LAUNCHER_SRC := $(TOPDIR)/src/java.base/share/native/launcher
--- a/make/lib/LibCommon.gmk	Tue May 15 10:13:52 2018 -0700
+++ b/make/lib/LibCommon.gmk	Wed May 16 09:45:40 2018 -0700
@@ -41,6 +41,7 @@
 # On Mac, we have always exported all symbols, probably due to oversight
 # and/or misunderstanding. To emulate this, don't hide any symbols
 # by default.
+# On AIX/xlc we need at least xlc 13.1 for the symbol hiding
 # Also provide an override for non-conformant libraries.
 ifeq ($(TOOLCHAIN_TYPE), gcc)
   CFLAGS_JDKLIB += -fvisibility=hidden
@@ -58,9 +59,11 @@
   CXXFLAGS_JDKLIB += -xldscope=hidden
   EXPORT_ALL_SYMBOLS := -xldscope=global
 else ifeq ($(TOOLCHAIN_TYPE), xlc)
-  CFLAGS_JDKLIB += -qvisibility=hidden
-  CXXFLAGS_JDKLIB += -qvisibility=hidden
-  EXPORT_ALL_SYMBOLS := -qvisibility=default
+  ifneq ($(CC_VERSION_NUMBER), 12.1)
+    CFLAGS_JDKLIB += -qvisibility=hidden
+    CXXFLAGS_JDKLIB += -qvisibility=hidden
+    EXPORT_ALL_SYMBOLS := -qvisibility=default
+  endif
 endif
 
 ################################################################################
--- a/make/nashorn/project.properties	Tue May 15 10:13:52 2018 -0700
+++ b/make/nashorn/project.properties	Wed May 16 09:45:40 2018 -0700
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2010, 2018, 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
@@ -98,8 +98,8 @@
 dist.nashornapi.javadoc.dir=${dist.javadoc.dir}/nashornapi
 dist.dynalinkapi.javadoc.dir=${dist.javadoc.dir}/dynalinkapi
 
-# configuration for java flight recorder
-run.test.jvmargs.jfr=-XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:FlightRecorderOptions=defaultrecording=true,disk=true,dumponexit=true,dumponexitpath=${build.dir},stackdepth=128
+# configuration for flight recorder
+run.test.jvmargs.jfr=XX:StartFlightRecording=disk=true,dumponexit=true,dumponexitpath=${build.dir},stackdepth=128
 
 # test library location
 test.lib=test/nashorn/lib
@@ -354,7 +354,7 @@
 # uncomment this jfr.args to enable light recordings. the stack needs to be cranked up to 1024 frames,
 # or everything will as of the now drown in lambda forms and be cut off.
 #
-#jfr.args=-XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:FlightRecorderOptions=defaultrecording=true,disk=true,dumponexit=true,dumponexitpath="test_suite.jfr",stackdepth=1024 \
+#jfr.args=-XX:StartFlightRecording=disk=true,dumponexit=true,dumponexitpath="test_suite.jfr",stackdepth=1024
 
 jfr.args=
 
--- a/make/nb_native/nbproject/configurations.xml	Tue May 15 10:13:52 2018 -0700
+++ b/make/nb_native/nbproject/configurations.xml	Wed May 16 09:45:40 2018 -0700
@@ -2891,7 +2891,6 @@
               <in>stringUtils.hpp</in>
               <in>ticks.cpp</in>
               <in>ticks.hpp</in>
-              <in>ticks.inline.hpp</in>
               <in>utf8.cpp</in>
               <in>utf8.hpp</in>
               <in>vmError.cpp</in>
@@ -6887,7 +6886,7 @@
             <pElem>../../hotspot/src/share/vm/ci</pElem>
             <pElem>../../hotspot/src/share/vm/oops</pElem>
             <pElem>../../hotspot/src/share/vm/trace</pElem>
-            <pElem>../../build/macosx-x86_64-normal-server-release/hotspot/variant-server/gensrc/tracefiles</pElem>
+            <pElem>../../build/macosx-x86_64-normal-server-release/hotspot/variant-server/gensrc/jfrfiles</pElem>
             <pElem>../../hotspot/src/share/vm/gc/parallel</pElem>
             <pElem>../../hotspot/src/share/vm/gc/shared</pElem>
             <pElem>../../hotspot/src/share/vm/classfile</pElem>
@@ -15408,11 +15407,6 @@
             tool="3"
             flavor2="0">
       </item>
-      <item path="../../src/hotspot/share/utilities/ticks.inline.hpp"
-            ex="false"
-            tool="3"
-            flavor2="0">
-      </item>
       <item path="../../src/hotspot/share/utilities/utf8.cpp"
             ex="false"
             tool="1"
@@ -29190,11 +29184,6 @@
             tool="3"
             flavor2="0">
       </item>
-      <item path="../../src/hotspot/share/utilities/ticks.inline.hpp"
-            ex="false"
-            tool="3"
-            flavor2="0">
-      </item>
       <item path="../../src/hotspot/share/utilities/utf8.cpp"
             ex="false"
             tool="1"
--- a/src/hotspot/cpu/aarch64/stubRoutines_aarch64.cpp	Tue May 15 10:13:52 2018 -0700
+++ b/src/hotspot/cpu/aarch64/stubRoutines_aarch64.cpp	Wed May 16 09:45:40 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2014, Red Hat Inc. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -28,6 +28,7 @@
 #include "runtime/frame.inline.hpp"
 #include "runtime/stubRoutines.hpp"
 #include "runtime/thread.inline.hpp"
+#include "utilities/globalDefinitions.hpp"
 
 // Implementation of the platform-specific part of StubRoutines - for
 // a description of how to extend it, see the stubRoutines.hpp file.
@@ -52,8 +53,7 @@
 /**
  *  crc_table[] from jdk/src/share/native/java/util/zip/zlib-1.2.5/crc32.h
  */
-juint StubRoutines::aarch64::_crc_table[]
-                   __attribute__ ((aligned(4096))) =
+juint StubRoutines::aarch64::_crc_table[] ATTRIBUTE_ALIGNED(4096) =
 {
     // Table 0
     0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/cpu/aarch64/vm_version_ext_aarch64.cpp	Wed May 16 09:45:40 2018 -0700
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2016, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "memory/allocation.hpp"
+#include "memory/allocation.inline.hpp"
+#include "runtime/os.inline.hpp"
+#include "vm_version_ext_aarch64.hpp"
+
+// VM_Version_Ext statics
+int VM_Version_Ext::_no_of_threads = 0;
+int VM_Version_Ext::_no_of_cores = 0;
+int VM_Version_Ext::_no_of_sockets = 0;
+bool VM_Version_Ext::_initialized = false;
+char VM_Version_Ext::_cpu_name[CPU_TYPE_DESC_BUF_SIZE] = {0};
+char VM_Version_Ext::_cpu_desc[CPU_DETAILED_DESC_BUF_SIZE] = {0};
+
+void VM_Version_Ext::initialize_cpu_information(void) {
+  // do nothing if cpu info has been initialized
+  if (_initialized) {
+    return;
+  }
+
+  int core_id = -1;
+  int chip_id = -1;
+  int len = 0;
+  char* src_string = NULL;
+
+  _no_of_cores  = os::processor_count();
+  _no_of_threads = _no_of_cores;
+  _no_of_sockets = _no_of_cores;
+  snprintf(_cpu_name, CPU_TYPE_DESC_BUF_SIZE - 1, "AArch64");
+  snprintf(_cpu_desc, CPU_DETAILED_DESC_BUF_SIZE, "%s", _features_string);
+  _initialized = true;
+}
+
+int VM_Version_Ext::number_of_threads(void) {
+  initialize_cpu_information();
+  return _no_of_threads;
+}
+
+int VM_Version_Ext::number_of_cores(void) {
+  initialize_cpu_information();
+  return _no_of_cores;
+}
+
+int VM_Version_Ext::number_of_sockets(void) {
+  initialize_cpu_information();
+  return _no_of_sockets;
+}
+
+const char* VM_Version_Ext::cpu_name(void) {
+  initialize_cpu_information();
+  char* tmp = NEW_C_HEAP_ARRAY_RETURN_NULL(char, CPU_TYPE_DESC_BUF_SIZE, mtTracing);
+  if (NULL == tmp) {
+    return NULL;
+  }
+  strncpy(tmp, _cpu_name, CPU_TYPE_DESC_BUF_SIZE);
+  return tmp;
+}
+
+const char* VM_Version_Ext::cpu_description(void) {
+  initialize_cpu_information();
+  char* tmp = NEW_C_HEAP_ARRAY_RETURN_NULL(char, CPU_DETAILED_DESC_BUF_SIZE, mtTracing);
+  if (NULL == tmp) {
+    return NULL;
+  }
+  strncpy(tmp, _cpu_desc, CPU_DETAILED_DESC_BUF_SIZE);
+  return tmp;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/cpu/aarch64/vm_version_ext_aarch64.hpp	Wed May 16 09:45:40 2018 -0700
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2016, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef CPU_AARCH64_VM_VM_VERSION_EXT_AARCH64_HPP
+#define CPU_AARCH64_VM_VM_VERSION_EXT_AARCH64_HPP
+
+#include "utilities/macros.hpp"
+#include "vm_version_aarch64.hpp"
+
+class VM_Version_Ext : public VM_Version {
+ private:
+  static const size_t      CPU_TYPE_DESC_BUF_SIZE = 256;
+  static const size_t      CPU_DETAILED_DESC_BUF_SIZE = 4096;
+
+  static int               _no_of_threads;
+  static int               _no_of_cores;
+  static int               _no_of_sockets;
+  static bool              _initialized;
+  static char              _cpu_name[CPU_TYPE_DESC_BUF_SIZE];
+  static char              _cpu_desc[CPU_DETAILED_DESC_BUF_SIZE];
+
+ public:
+  static int number_of_threads(void);
+  static int number_of_cores(void);
+  static int number_of_sockets(void);
+
+  static const char* cpu_name(void);
+  static const char* cpu_description(void);
+  static void initialize_cpu_information(void);
+
+};
+
+#endif // CPU_AARCH64_VM_VM_VERSION_EXT_AARCH64_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/cpu/arm/vm_version_ext_arm.cpp	Wed May 16 09:45:40 2018 -0700
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2013, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "memory/allocation.hpp"
+#include "memory/allocation.inline.hpp"
+#include "runtime/os.inline.hpp"
+#include "vm_version_ext_arm.hpp"
+
+// VM_Version_Ext statics
+int VM_Version_Ext::_no_of_threads = 0;
+int VM_Version_Ext::_no_of_cores = 0;
+int VM_Version_Ext::_no_of_sockets = 0;
+bool VM_Version_Ext::_initialized = false;
+char VM_Version_Ext::_cpu_name[CPU_TYPE_DESC_BUF_SIZE] = {0};
+char VM_Version_Ext::_cpu_desc[CPU_DETAILED_DESC_BUF_SIZE] = {0};
+
+void VM_Version_Ext::initialize_cpu_information(void) {
+  // do nothing if cpu info has been initialized
+  if (_initialized) {
+    return;
+  }
+
+  int core_id = -1;
+  int chip_id = -1;
+  int len = 0;
+  char* src_string = NULL;
+
+  _no_of_cores  = os::processor_count();
+  _no_of_threads = _no_of_cores;
+  _no_of_sockets = _no_of_cores;
+#ifdef AARCH64
+  snprintf(_cpu_name, CPU_TYPE_DESC_BUF_SIZE - 1, "AArch64");
+#else
+  snprintf(_cpu_name, CPU_TYPE_DESC_BUF_SIZE - 1, "ARM%d", _arm_arch);
+#endif
+  snprintf(_cpu_desc, CPU_DETAILED_DESC_BUF_SIZE, "%s", _features_string);
+  _initialized = true;
+}
+
+int VM_Version_Ext::number_of_threads(void) {
+  initialize_cpu_information();
+  return _no_of_threads;
+}
+
+int VM_Version_Ext::number_of_cores(void) {
+  initialize_cpu_information();
+  return _no_of_cores;
+}
+
+int VM_Version_Ext::number_of_sockets(void) {
+  initialize_cpu_information();
+  return _no_of_sockets;
+}
+
+const char* VM_Version_Ext::cpu_name(void) {
+  initialize_cpu_information();
+  char* tmp = NEW_C_HEAP_ARRAY_RETURN_NULL(char, CPU_TYPE_DESC_BUF_SIZE, mtTracing);
+  if (NULL == tmp) {
+    return NULL;
+  }
+  strncpy(tmp, _cpu_name, CPU_TYPE_DESC_BUF_SIZE);
+  return tmp;
+}
+
+const char* VM_Version_Ext::cpu_description(void) {
+  initialize_cpu_information();
+  char* tmp = NEW_C_HEAP_ARRAY_RETURN_NULL(char, CPU_DETAILED_DESC_BUF_SIZE, mtTracing);
+  if (NULL == tmp) {
+    return NULL;
+  }
+  strncpy(tmp, _cpu_desc, CPU_DETAILED_DESC_BUF_SIZE);
+  return tmp;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/cpu/arm/vm_version_ext_arm.hpp	Wed May 16 09:45:40 2018 -0700
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2013, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef CPU_ARM_VM_VM_VERSION_EXT_ARM_HPP
+#define CPU_ARM_VM_VM_VERSION_EXT_ARM_HPP
+
+#include "utilities/macros.hpp"
+#include "vm_version_arm.hpp"
+
+class VM_Version_Ext : public VM_Version {
+ private:
+  static const size_t      CPU_TYPE_DESC_BUF_SIZE = 256;
+  static const size_t      CPU_DETAILED_DESC_BUF_SIZE = 4096;
+
+  static int               _no_of_threads;
+  static int               _no_of_cores;
+  static int               _no_of_sockets;
+  static bool              _initialized;
+  static char              _cpu_name[CPU_TYPE_DESC_BUF_SIZE];
+  static char              _cpu_desc[CPU_DETAILED_DESC_BUF_SIZE];
+
+ public:
+  static int number_of_threads(void);
+  static int number_of_cores(void);
+  static int number_of_sockets(void);
+
+  static const char* cpu_name(void);
+  static const char* cpu_description(void);
+  static void initialize_cpu_information(void);
+
+};
+
+#endif // CPU_ARM_VM_VM_VERSION_EXT_ARM_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/cpu/sparc/vm_version_ext_sparc.cpp	Wed May 16 09:45:40 2018 -0700
@@ -0,0 +1,185 @@
+/*
+ * Copyright (c) 2013, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "jvm.h"
+#include "memory/allocation.hpp"
+#include "memory/allocation.inline.hpp"
+#include "vm_version_ext_sparc.hpp"
+
+// VM_Version_Ext statics
+int   VM_Version_Ext::_no_of_threads = 0;
+int   VM_Version_Ext::_no_of_cores = 0;
+int   VM_Version_Ext::_no_of_sockets = 0;
+kid_t VM_Version_Ext::_kcid = -1;
+char  VM_Version_Ext::_cpu_name[CPU_TYPE_DESC_BUF_SIZE] = {0};
+char  VM_Version_Ext::_cpu_desc[CPU_DETAILED_DESC_BUF_SIZE] = {0};
+
+// get cpu information. It takes into account if the kstat chain id
+// has been changed and update the info if necessary.
+bool VM_Version_Ext::initialize_cpu_information(void) {
+
+  int core_id = -1;
+  int chip_id = -1;
+  int len = 0;
+  char* src_string = NULL;
+  kstat_ctl_t* kc = kstat_open();
+  if (!kc) {
+    return false;
+  }
+
+  // check if kstat chain has been updated
+  kid_t kcid = kstat_chain_update(kc);
+  if (kcid == -1) {
+    kstat_close(kc);
+    return false;
+  }
+
+  bool updated = ((kcid > 0) && (kcid != _kcid)) ||
+                 ((kcid == 0) && (_kcid == -1));
+  if (!updated) {
+    kstat_close(kc);
+    return true;
+  }
+
+  // update the cached _kcid
+  _kcid = kcid;
+
+  // find the number of online processors
+  // for modern processsors, it is also known as the
+  // hardware threads.
+  _no_of_threads  = sysconf(_SC_NPROCESSORS_ONLN);
+
+  if (_no_of_threads <= 0 ) {
+    kstat_close(kc);
+    return false;
+  }
+
+  _no_of_cores = 0;
+  _no_of_sockets = 0;
+
+  // loop through the kstat chain
+  kstat_t* ksp = NULL;
+  for (ksp = kc->kc_chain; ksp != NULL; ksp = ksp->ks_next) {
+    // only interested in "cpu_info"
+    if (strcmp(ksp->ks_module, (char*)CPU_INFO) == 0) {
+      if (kstat_read(kc, ksp, NULL) == -1) {
+        kstat_close(kc);
+        return false;
+      }
+      if (ksp->ks_data != NULL) {
+        kstat_named_t* knm = (kstat_named_t *)ksp->ks_data;
+        // loop through the number of fields in each record
+        for (int i = 0; i < ksp->ks_ndata; i++) {
+          // set cpu type if it hasn't been already set
+          if ((strcmp((const char*)&(knm[i].name), CPU_TYPE) == 0) &&
+                     (_cpu_name[0] == '\0')) {
+            if (knm[i].data_type == KSTAT_DATA_STRING) {
+              src_string = (char*)KSTAT_NAMED_STR_PTR(&knm[i]);
+            } else {
+              src_string = (char*)&(knm[i].value.c[0]);
+            }
+            len = strlen(src_string);
+            if (len < CPU_TYPE_DESC_BUF_SIZE) {
+              jio_snprintf(_cpu_name, CPU_TYPE_DESC_BUF_SIZE,
+                                         "%s", src_string);
+            }
+          }
+
+          // set cpu description if it hasn't been already set
+          if ((strcmp((const char*)&(knm[i].name), CPU_DESCRIPTION) == 0) &&
+                      (_cpu_desc[0] == '\0')) {
+            if (knm[i].data_type == KSTAT_DATA_STRING) {
+              src_string = (char*)KSTAT_NAMED_STR_PTR(&knm[i]);
+            } else {
+              src_string = (char*)&(knm[i].value.c[0]);
+            }
+            len = strlen(src_string);
+            if (len < CPU_DETAILED_DESC_BUF_SIZE) {
+              jio_snprintf(_cpu_desc, CPU_DETAILED_DESC_BUF_SIZE,
+                                         "%s", src_string);
+            }
+          }
+
+          // count the number of sockets based on the chip id
+          if (strcmp((const char*)&(knm[i].name), CHIP_ID) == 0) {
+            if (chip_id != knm[i].value.l) {
+              chip_id = knm[i].value.l;
+              _no_of_sockets++;
+            }
+          }
+
+          // count the number of cores based on the core id
+          if (strcmp((const char*)&(knm[i].name), CORE_ID) == 0) {
+            if (core_id != knm[i].value.l) {
+              core_id = knm[i].value.l;
+              _no_of_cores++;
+            }
+          }
+        }
+      }
+    }
+  }
+
+  kstat_close(kc);
+  return true;
+}
+
+int VM_Version_Ext::number_of_threads(void) {
+  initialize_cpu_information();
+  return _no_of_threads;
+}
+
+int VM_Version_Ext::number_of_cores(void) {
+  initialize_cpu_information();
+  return _no_of_cores;
+}
+
+int VM_Version_Ext::number_of_sockets(void) {
+  initialize_cpu_information();
+  return _no_of_sockets;
+}
+
+const char* VM_Version_Ext::cpu_name(void) {
+  if (!initialize_cpu_information()) {
+    return NULL;
+  }
+  char* tmp = NEW_C_HEAP_ARRAY_RETURN_NULL(char, CPU_TYPE_DESC_BUF_SIZE, mtTracing);
+  if (NULL == tmp) {
+    return NULL;
+  }
+  strncpy(tmp, _cpu_name, CPU_TYPE_DESC_BUF_SIZE);
+  return tmp;
+}
+
+const char* VM_Version_Ext::cpu_description(void) {
+  if (!initialize_cpu_information()) {
+    return NULL;
+  }
+  char* tmp = NEW_C_HEAP_ARRAY_RETURN_NULL(char, CPU_DETAILED_DESC_BUF_SIZE, mtTracing);
+  if (NULL == tmp) {
+    return NULL;
+  }
+  strncpy(tmp, _cpu_desc, CPU_DETAILED_DESC_BUF_SIZE);
+  return tmp;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/cpu/sparc/vm_version_ext_sparc.hpp	Wed May 16 09:45:40 2018 -0700
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2013, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef CPU_SPARC_VM_VM_VERSION_EXT_SPARC_HPP
+#define CPU_SPARC_VM_VM_VERSION_EXT_SPARC_HPP
+
+#include "utilities/macros.hpp"
+#include "vm_version_sparc.hpp"
+#include <kstat.h>
+#include <sys/processor.h>
+
+#define CPU_INFO        "cpu_info"
+#define CPU_TYPE        "fpu_type"
+#define CPU_DESCRIPTION "implementation"
+#define CHIP_ID         "chip_id"
+#define CORE_ID         "core_id"
+
+class VM_Version_Ext : public VM_Version {
+ private:
+
+  static const size_t      CPU_TYPE_DESC_BUF_SIZE = 256;
+  static const size_t      CPU_DETAILED_DESC_BUF_SIZE = 4096;
+
+  static int               _no_of_threads;
+  static int               _no_of_cores;
+  static int               _no_of_sockets;
+  static kid_t             _kcid;
+  static char              _cpu_name[CPU_TYPE_DESC_BUF_SIZE];
+  static char              _cpu_desc[CPU_DETAILED_DESC_BUF_SIZE];
+
+  static bool initialize_cpu_information(void);
+
+ public:
+
+  static int number_of_threads(void);
+  static int number_of_cores(void);
+  static int number_of_sockets(void);
+
+  static const char* cpu_name(void);
+  static const char* cpu_description(void);
+};
+
+#endif // CPU_SPARC_VM_VM_VERSION_EXT_SPARC_HPP
--- a/src/hotspot/cpu/x86/macroAssembler_x86_cos.cpp	Tue May 15 10:13:52 2018 -0700
+++ b/src/hotspot/cpu/x86/macroAssembler_x86_cos.cpp	Wed May 16 09:45:40 2018 -0700
@@ -27,14 +27,9 @@
 #include "precompiled.hpp"
 #include "asm/assembler.hpp"
 #include "asm/assembler.inline.hpp"
+#include "macroAssembler_x86.hpp"
 #include "runtime/stubRoutines.hpp"
-#include "macroAssembler_x86.hpp"
-
-#ifdef _MSC_VER
-#define ALIGNED_(x) __declspec(align(x))
-#else
-#define ALIGNED_(x) __attribute__ ((aligned(x)))
-#endif
+#include "utilities/globalDefinitions.hpp"
 
 /******************************************************************************/
 //                     ALGORITHM DESCRIPTION - COS()
@@ -181,7 +176,7 @@
 
 #ifdef _LP64
 // The 64 bit code is at most SSE2 compliant
-ALIGNED_(8) juint _ONE[] =
+ATTRIBUTE_ALIGNED(8) juint _ONE[] =
 {
     0x00000000UL, 0x3ff00000UL
 };
@@ -636,7 +631,7 @@
 #else
 // The 32 bit code is at most SSE2 compliant
 
-ALIGNED_(16) juint _static_const_table_cos[] =
+ATTRIBUTE_ALIGNED(16) juint _static_const_table_cos[] =
 {
     0x00000000UL, 0x00000000UL, 0x00000000UL, 0x00000000UL, 0x00000000UL,
     0x00000000UL, 0x00000000UL, 0x3ff00000UL, 0x176d6d31UL, 0xbf73b92eUL,
--- a/src/hotspot/cpu/x86/macroAssembler_x86_exp.cpp	Tue May 15 10:13:52 2018 -0700
+++ b/src/hotspot/cpu/x86/macroAssembler_x86_exp.cpp	Wed May 16 09:45:40 2018 -0700
@@ -27,14 +27,9 @@
 #include "precompiled.hpp"
 #include "asm/assembler.hpp"
 #include "asm/assembler.inline.hpp"
+#include "macroAssembler_x86.hpp"
 #include "runtime/stubRoutines.hpp"
-#include "macroAssembler_x86.hpp"
-
-#ifdef _MSC_VER
-#define ALIGNED_(x) __declspec(align(x))
-#else
-#define ALIGNED_(x) __attribute__ ((aligned(x)))
-#endif
+#include "utilities/globalDefinitions.hpp"
 
 /******************************************************************************/
 //                     ALGORITHM DESCRIPTION - EXP()
@@ -72,7 +67,7 @@
 
 #ifdef _LP64
 // The 64 bit code is at most SSE2 compliant
-ALIGNED_(16) juint _cv[] =
+ATTRIBUTE_ALIGNED(16) juint _cv[] =
 {
     0x652b82feUL, 0x40571547UL, 0x652b82feUL, 0x40571547UL, 0xfefa0000UL,
     0x3f862e42UL, 0xfefa0000UL, 0x3f862e42UL, 0xbc9e3b3aUL, 0x3d1cf79aUL,
@@ -81,22 +76,22 @@
     0xc090cf0fUL, 0x3f811115UL, 0x55548ba1UL, 0x3fc55555UL
 };
 
-ALIGNED_(16) juint _shifter[] =
+ATTRIBUTE_ALIGNED(16) juint _shifter[] =
 {
     0x00000000UL, 0x43380000UL, 0x00000000UL, 0x43380000UL
 };
 
-ALIGNED_(16) juint _mmask[] =
+ATTRIBUTE_ALIGNED(16) juint _mmask[] =
 {
     0xffffffc0UL, 0x00000000UL, 0xffffffc0UL, 0x00000000UL
 };
 
-ALIGNED_(16) juint _bias[] =
+ATTRIBUTE_ALIGNED(16) juint _bias[] =
 {
     0x0000ffc0UL, 0x00000000UL, 0x0000ffc0UL, 0x00000000UL
 };
 
-ALIGNED_(16) juint _Tbl_addr[] =
+ATTRIBUTE_ALIGNED(16) juint _Tbl_addr[] =
 {
     0x00000000UL, 0x00000000UL, 0x00000000UL, 0x00000000UL, 0x0e03754dUL,
     0x3cad7bbfUL, 0x3e778060UL, 0x00002c9aUL, 0x3567f613UL, 0x3c8cd252UL,
@@ -152,37 +147,37 @@
     0x000fa7c1UL
 };
 
-ALIGNED_(16) juint _ALLONES[] =
+ATTRIBUTE_ALIGNED(16) juint _ALLONES[] =
 {
     0xffffffffUL, 0xffffffffUL, 0xffffffffUL, 0xffffffffUL
 };
 
-ALIGNED_(16) juint _ebias[] =
+ATTRIBUTE_ALIGNED(16) juint _ebias[] =
 {
     0x00000000UL, 0x3ff00000UL, 0x00000000UL, 0x3ff00000UL
 };
 
-ALIGNED_(4) juint _XMAX[] =
+ATTRIBUTE_ALIGNED(4) juint _XMAX[] =
 {
     0xffffffffUL, 0x7fefffffUL
 };
 
-ALIGNED_(4) juint _XMIN[] =
+ATTRIBUTE_ALIGNED(4) juint _XMIN[] =
 {
     0x00000000UL, 0x00100000UL
 };
 
-ALIGNED_(4) juint _INF[] =
+ATTRIBUTE_ALIGNED(4) juint _INF[] =
 {
     0x00000000UL, 0x7ff00000UL
 };
 
-ALIGNED_(4) juint _ZERO[] =
+ATTRIBUTE_ALIGNED(4) juint _ZERO[] =
 {
     0x00000000UL, 0x00000000UL
 };
 
-ALIGNED_(4) juint _ONE_val[] =
+ATTRIBUTE_ALIGNED(4) juint _ONE_val[] =
 {
     0x00000000UL, 0x3ff00000UL
 };
@@ -411,7 +406,7 @@
 }
 #else
 // The 32 bit code is at most SSE2 compliant
-ALIGNED_(16) juint _static_const_table[] =
+ATTRIBUTE_ALIGNED(16) juint _static_const_table[] =
 {
     0x00000000UL, 0xfff00000UL, 0x00000000UL, 0xfff00000UL, 0xffffffc0UL,
     0x00000000UL, 0xffffffc0UL, 0x00000000UL, 0x0000ffc0UL, 0x00000000UL,
--- a/src/hotspot/cpu/x86/macroAssembler_x86_log.cpp	Tue May 15 10:13:52 2018 -0700
+++ b/src/hotspot/cpu/x86/macroAssembler_x86_log.cpp	Wed May 16 09:45:40 2018 -0700
@@ -28,12 +28,7 @@
 #include "asm/assembler.hpp"
 #include "asm/assembler.inline.hpp"
 #include "macroAssembler_x86.hpp"
-
-#ifdef _MSC_VER
-#define ALIGNED_(x) __declspec(align(x))
-#else
-#define ALIGNED_(x) __attribute__ ((aligned(x)))
-#endif
+#include "utilities/globalDefinitions.hpp"
 
 /******************************************************************************/
 //                     ALGORITHM DESCRIPTION - LOG()
@@ -62,7 +57,7 @@
 
 #ifdef _LP64
 // The 64 bit code is at most SSE2 compliant
-ALIGNED_(16) juint _L_tbl[] =
+ATTRIBUTE_ALIGNED(16) juint _L_tbl[] =
 {
     0xfefa3800UL, 0x3fe62e42UL, 0x93c76730UL, 0x3d2ef357UL, 0xaa241800UL,
     0x3fe5ee82UL, 0x0cda46beUL, 0x3d220238UL, 0x5c364800UL, 0x3fe5af40UL,
@@ -170,12 +165,12 @@
     0x80000000UL
 };
 
-ALIGNED_(16) juint _log2[] =
+ATTRIBUTE_ALIGNED(16) juint _log2[] =
 {
     0xfefa3800UL, 0x3fa62e42UL, 0x93c76730UL, 0x3ceef357UL
 };
 
-ALIGNED_(16) juint _coeff[] =
+ATTRIBUTE_ALIGNED(16) juint _coeff[] =
 {
     0x92492492UL, 0x3fc24924UL, 0x00000000UL, 0xbfd00000UL, 0x3d6fb175UL,
     0xbfc5555eUL, 0x55555555UL, 0x3fd55555UL, 0x9999999aUL, 0x3fc99999UL,
@@ -367,7 +362,7 @@
 }
 #else
 // The 32 bit code is at most SSE2 compliant
-ALIGNED_(16) juint _static_const_table_log[] =
+ATTRIBUTE_ALIGNED(16) juint _static_const_table_log[] =
 {
     0xfefa3800UL, 0x3fe62e42UL, 0x93c76730UL, 0x3d2ef357UL, 0xaa241800UL,
     0x3fe5ee82UL, 0x0cda46beUL, 0x3d220238UL, 0x5c364800UL, 0x3fe5af40UL,
--- a/src/hotspot/cpu/x86/macroAssembler_x86_log10.cpp	Tue May 15 10:13:52 2018 -0700
+++ b/src/hotspot/cpu/x86/macroAssembler_x86_log10.cpp	Wed May 16 09:45:40 2018 -0700
@@ -27,14 +27,9 @@
 #include "precompiled.hpp"
 #include "asm/assembler.hpp"
 #include "asm/assembler.inline.hpp"
+#include "macroAssembler_x86.hpp"
 #include "runtime/stubRoutines.hpp"
-#include "macroAssembler_x86.hpp"
-
-#ifdef _MSC_VER
-#define ALIGNED_(x) __declspec(align(x))
-#else
-#define ALIGNED_(x) __attribute__ ((aligned(x)))
-#endif
+#include "utilities/globalDefinitions.hpp"
 
 /******************************************************************************/
 //                     ALGORITHM DESCRIPTION - LOG10()
@@ -63,17 +58,17 @@
 
 #ifdef _LP64
 // The 64 bit code is at most SSE2 compliant
-ALIGNED_(16) juint _HIGHSIGMASK_log10[] =
+ATTRIBUTE_ALIGNED(16) juint _HIGHSIGMASK_log10[] =
 {
     0xf8000000UL, 0xffffffffUL, 0x00000000UL, 0xffffe000UL
 };
 
-ALIGNED_(16) juint _LOG10_E[] =
+ATTRIBUTE_ALIGNED(16) juint _LOG10_E[] =
 {
     0x00000000UL, 0x3fdbc000UL, 0xbf2e4108UL, 0x3f5a7a6cUL
 };
 
-ALIGNED_(16) juint _L_tbl_log10[] =
+ATTRIBUTE_ALIGNED(16) juint _L_tbl_log10[] =
 {
     0x509f7800UL, 0x3fd34413UL, 0x1f12b358UL, 0x3d1fef31UL, 0x80333400UL,
     0x3fd32418UL, 0xc671d9d0UL, 0xbcf542bfUL, 0x51195000UL, 0x3fd30442UL,
@@ -181,12 +176,12 @@
     0x00000000UL
 };
 
-ALIGNED_(16) juint _log2_log10[] =
+ATTRIBUTE_ALIGNED(16) juint _log2_log10[] =
 {
     0x509f7800UL, 0x3f934413UL, 0x1f12b358UL, 0x3cdfef31UL
 };
 
-ALIGNED_(16) juint _coeff_log10[] =
+ATTRIBUTE_ALIGNED(16) juint _coeff_log10[] =
 {
     0xc1a5f12eUL, 0x40358874UL, 0x64d4ef0dUL, 0xc0089309UL, 0x385593b1UL,
     0xc025c917UL, 0xdc963467UL, 0x3ffc6a02UL, 0x7f9d3aa1UL, 0x4016ab9fUL,
@@ -387,7 +382,7 @@
 }
 #else
 // The 32 bit code is at most SSE2 compliant
-ALIGNED_(16) juint _static_const_table_log10[] =
+ATTRIBUTE_ALIGNED(16) juint _static_const_table_log10[] =
 {
     0x509f7800UL, 0x3fd34413UL, 0x1f12b358UL, 0x3d1fef31UL, 0x80333400UL,
     0x3fd32418UL, 0xc671d9d0UL, 0xbcf542bfUL, 0x51195000UL, 0x3fd30442UL,
--- a/src/hotspot/cpu/x86/macroAssembler_x86_pow.cpp	Tue May 15 10:13:52 2018 -0700
+++ b/src/hotspot/cpu/x86/macroAssembler_x86_pow.cpp	Wed May 16 09:45:40 2018 -0700
@@ -27,14 +27,9 @@
 #include "precompiled.hpp"
 #include "asm/assembler.hpp"
 #include "asm/assembler.inline.hpp"
+#include "macroAssembler_x86.hpp"
 #include "runtime/stubRoutines.hpp"
-#include "macroAssembler_x86.hpp"
-
-#ifdef _MSC_VER
-#define ALIGNED_(x) __declspec(align(x))
-#else
-#define ALIGNED_(x) __attribute__ ((aligned(x)))
-#endif
+#include "utilities/globalDefinitions.hpp"
 
 /******************************************************************************/
 //                     ALGORITHM DESCRIPTION  - POW()
@@ -90,22 +85,22 @@
 
 #ifdef _LP64
 // The 64 bit code is at most SSE2 compliant
-ALIGNED_(16) juint _HIGHSIGMASK[] =
+ATTRIBUTE_ALIGNED(16) juint _HIGHSIGMASK[] =
 {
     0x00000000UL, 0xfffff800UL, 0x00000000UL, 0xfffff800UL
 };
 
-ALIGNED_(16) juint _LOG2_E[] =
+ATTRIBUTE_ALIGNED(16) juint _LOG2_E[] =
 {
     0x00000000UL, 0x3ff72000UL, 0x161bb241UL, 0xbf5dabe1UL
 };
 
-ALIGNED_(16) juint _HIGHMASK_Y[] =
+ATTRIBUTE_ALIGNED(16) juint _HIGHMASK_Y[] =
 {
     0x00000000UL, 0xfffffff8UL, 0x00000000UL, 0xffffffffUL
 };
 
-ALIGNED_(16) juint _T_exp[] =
+ATTRIBUTE_ALIGNED(16) juint _T_exp[] =
 {
     0x00000000UL, 0x3ff00000UL, 0x00000000UL, 0x3b700000UL, 0xfa5abcbfUL,
     0x3ff00b1aUL, 0xa7609f71UL, 0xbc84f6b2UL, 0xa9fb3335UL, 0x3ff0163dUL,
@@ -314,29 +309,29 @@
     0x6b2a23d9UL, 0x3fffe9d9UL, 0x7442fde3UL, 0x3c74a603UL
 };
 
-ALIGNED_(16) juint _e_coeff[] =
+ATTRIBUTE_ALIGNED(16) juint _e_coeff[] =
 {
     0xe78a6731UL, 0x3f55d87fUL, 0xd704a0c0UL, 0x3fac6b08UL, 0x6fba4e77UL,
     0x3f83b2abUL, 0xff82c58fUL, 0x3fcebfbdUL, 0xfefa39efUL, 0x3fe62e42UL,
     0x00000000UL, 0x00000000UL
 };
 
-ALIGNED_(16) juint _coeff_h[] =
+ATTRIBUTE_ALIGNED(16) juint _coeff_h[] =
 {
     0x00000000UL, 0xbfd61a00UL, 0x00000000UL, 0xbf5dabe1UL
 };
 
-ALIGNED_(16) juint _HIGHMASK_LOG_X[] =
+ATTRIBUTE_ALIGNED(16) juint _HIGHMASK_LOG_X[] =
 {
     0xf8000000UL, 0xffffffffUL, 0x00000000UL, 0xfffff800UL
 };
 
-ALIGNED_(8) juint _HALFMASK[] =
+ATTRIBUTE_ALIGNED(8) juint _HALFMASK[] =
 {
     0xf8000000UL, 0xffffffffUL, 0xf8000000UL, 0xffffffffUL
 };
 
-ALIGNED_(16) juint _coeff_pow[] =
+ATTRIBUTE_ALIGNED(16) juint _coeff_pow[] =
 {
     0x6dc96112UL, 0xbf836578UL, 0xee241472UL, 0xbf9b0301UL, 0x9f95985aUL,
     0xbfb528dbUL, 0xb3841d2aUL, 0xbfd619b6UL, 0x518775e3UL, 0x3f9004f2UL,
@@ -345,7 +340,7 @@
     0x486ececbUL, 0x3fc4635eUL, 0x412055ccUL, 0xbdd61bb2UL
 };
 
-ALIGNED_(16) juint _L_tbl_pow[] =
+ATTRIBUTE_ALIGNED(16) juint _L_tbl_pow[] =
 {
     0x00000000UL, 0x3ff00000UL, 0x00000000UL, 0x00000000UL, 0x20000000UL,
     0x3feff00aUL, 0x96621f95UL, 0x3e5b1856UL, 0xe0000000UL, 0x3fefe019UL,
@@ -760,12 +755,12 @@
     0x00000000UL, 0x80000000UL
 };
 
-ALIGNED_(8) juint _log2_pow[] =
+ATTRIBUTE_ALIGNED(8) juint _log2_pow[] =
 {
     0xfefa39efUL, 0x3fe62e42UL, 0xfefa39efUL, 0xbfe62e42UL
 };
 
-ALIGNED_(8) juint _DOUBLE2[] =
+ATTRIBUTE_ALIGNED(8) juint _DOUBLE2[] =
 {
     0x00000000UL, 0x40000000UL
 };
@@ -1862,7 +1857,7 @@
 }
 #else
 // The 32 bit code is at most SSE2 compliant
-ALIGNED_(16) juint _static_const_table_pow[] =
+ATTRIBUTE_ALIGNED(16) juint _static_const_table_pow[] =
 {
     0x00000000UL, 0xbfd61a00UL, 0x00000000UL, 0xbf5dabe1UL, 0xf8000000UL,
     0xffffffffUL, 0x00000000UL, 0xfffff800UL, 0x00000000UL, 0x3ff00000UL,
--- a/src/hotspot/cpu/x86/macroAssembler_x86_sin.cpp	Tue May 15 10:13:52 2018 -0700
+++ b/src/hotspot/cpu/x86/macroAssembler_x86_sin.cpp	Wed May 16 09:45:40 2018 -0700
@@ -27,15 +27,10 @@
 #include "precompiled.hpp"
 #include "asm/assembler.hpp"
 #include "asm/assembler.inline.hpp"
+#include "macroAssembler_x86.hpp"
 #include "runtime/stubRoutines.hpp"
 #include "stubRoutines_x86.hpp"
-#include "macroAssembler_x86.hpp"
-
-#ifdef _MSC_VER
-#define ALIGNED_(x) __declspec(align(x))
-#else
-#define ALIGNED_(x) __attribute__ ((aligned(x)))
-#endif
+#include "utilities/globalDefinitions.hpp"
 
 /******************************************************************************/
 //                     ALGORITHM DESCRIPTION - SIN()
@@ -183,22 +178,22 @@
 
 #ifdef _LP64
 // The 64 bit code is at most SSE2 compliant
-ALIGNED_(16) juint StubRoutines::x86::_ONEHALF[] =
+ATTRIBUTE_ALIGNED(16) juint StubRoutines::x86::_ONEHALF[] =
 {
     0x00000000UL, 0x3fe00000UL, 0x00000000UL, 0x3fe00000UL
 };
 
-ALIGNED_(16) juint StubRoutines::x86::_P_2[] =
+ATTRIBUTE_ALIGNED(16) juint StubRoutines::x86::_P_2[] =
 {
     0x1a600000UL, 0x3d90b461UL, 0x1a600000UL, 0x3d90b461UL
 };
 
-ALIGNED_(16) juint StubRoutines::x86::_SC_4[] =
+ATTRIBUTE_ALIGNED(16) juint StubRoutines::x86::_SC_4[] =
 {
     0xa556c734UL, 0x3ec71de3UL, 0x1a01a01aUL, 0x3efa01a0UL
 };
 
-ALIGNED_(16) juint StubRoutines::x86::_Ctable[] =
+ATTRIBUTE_ALIGNED(16) juint StubRoutines::x86::_Ctable[] =
 {
     0x00000000UL, 0x00000000UL, 0x00000000UL, 0x00000000UL, 0x00000000UL,
     0x00000000UL, 0x00000000UL, 0x3ff00000UL, 0x176d6d31UL, 0xbf73b92eUL,
@@ -305,22 +300,22 @@
     0x00000000UL, 0x3ff00000UL
 };
 
-ALIGNED_(16) juint StubRoutines::x86::_SC_2[] =
+ATTRIBUTE_ALIGNED(16) juint StubRoutines::x86::_SC_2[] =
 {
     0x11111111UL, 0x3f811111UL, 0x55555555UL, 0x3fa55555UL
 };
 
-ALIGNED_(16) juint StubRoutines::x86::_SC_3[] =
+ATTRIBUTE_ALIGNED(16) juint StubRoutines::x86::_SC_3[] =
 {
     0x1a01a01aUL, 0xbf2a01a0UL, 0x16c16c17UL, 0xbf56c16cUL
 };
 
-ALIGNED_(16) juint StubRoutines::x86::_SC_1[] =
+ATTRIBUTE_ALIGNED(16) juint StubRoutines::x86::_SC_1[] =
 {
     0x55555555UL, 0xbfc55555UL, 0x00000000UL, 0xbfe00000UL
 };
 
-ALIGNED_(16) juint StubRoutines::x86::_PI_INV_TABLE[] =
+ATTRIBUTE_ALIGNED(16) juint StubRoutines::x86::_PI_INV_TABLE[] =
 {
     0x00000000UL, 0x00000000UL, 0xa2f9836eUL, 0x4e441529UL, 0xfc2757d1UL,
     0xf534ddc0UL, 0xdb629599UL, 0x3c439041UL, 0xfe5163abUL, 0xdebbc561UL,
@@ -333,52 +328,52 @@
     0xf0cfbc21UL
 };
 
-ALIGNED_(8) juint StubRoutines::x86::_PI_4[] =
+ATTRIBUTE_ALIGNED(8) juint StubRoutines::x86::_PI_4[] =
 {
     0x40000000UL, 0x3fe921fbUL, 0x18469899UL, 0x3e64442dUL
 };
 
-ALIGNED_(8) juint StubRoutines::x86::_PI32INV[] =
+ATTRIBUTE_ALIGNED(8) juint StubRoutines::x86::_PI32INV[] =
 {
     0x6dc9c883UL, 0x40245f30UL
 };
 
-ALIGNED_(8) juint _SHIFTER[] =
+ATTRIBUTE_ALIGNED(8) juint _SHIFTER[] =
 {
     0x00000000UL, 0x43380000UL
 };
 
-ALIGNED_(8) juint StubRoutines::x86::_SIGN_MASK[] =
+ATTRIBUTE_ALIGNED(8) juint StubRoutines::x86::_SIGN_MASK[] =
 {
     0x00000000UL, 0x80000000UL
 };
 
-ALIGNED_(8) juint StubRoutines::x86::_P_3[] =
+ATTRIBUTE_ALIGNED(8) juint StubRoutines::x86::_P_3[] =
 {
     0x2e037073UL, 0x3b63198aUL
 };
 
-ALIGNED_(8) juint _ALL_ONES[] =
+ATTRIBUTE_ALIGNED(8) juint _ALL_ONES[] =
 {
     0xffffffffUL, 0x3fefffffUL
 };
 
-ALIGNED_(8) juint _TWO_POW_55[] =
+ATTRIBUTE_ALIGNED(8) juint _TWO_POW_55[] =
 {
     0x00000000UL, 0x43600000UL
 };
 
-ALIGNED_(8) juint _TWO_POW_M55[] =
+ATTRIBUTE_ALIGNED(8) juint _TWO_POW_M55[] =
 {
     0x00000000UL, 0x3c800000UL
 };
 
-ALIGNED_(8) juint StubRoutines::x86::_P_1[] =
+ATTRIBUTE_ALIGNED(8) juint StubRoutines::x86::_P_1[] =
 {
     0x54400000UL, 0x3fb921fbUL
 };
 
-ALIGNED_(8) juint StubRoutines::x86::_NEG_ZERO[] =
+ATTRIBUTE_ALIGNED(8) juint StubRoutines::x86::_NEG_ZERO[] =
 {
     0x00000000UL, 0x80000000UL
 };
@@ -853,54 +848,54 @@
 }
 #else
 // The 32 bit code is at most SSE2 compliant
-ALIGNED_(8) juint _zero_none[] =
+ATTRIBUTE_ALIGNED(8) juint _zero_none[] =
 {
     0x00000000UL, 0x00000000UL, 0x00000000UL, 0xbff00000UL
 };
 
-ALIGNED_(4) juint __4onpi_d[] =
+ATTRIBUTE_ALIGNED(4) juint __4onpi_d[] =
 {
     0x6dc9c883UL, 0x3ff45f30UL
 };
 
-ALIGNED_(4) juint _TWO_32H[] =
+ATTRIBUTE_ALIGNED(4) juint _TWO_32H[] =
 {
     0x00000000UL, 0x41f80000UL
 };
 
-ALIGNED_(4) juint _pi04_3d[] =
+ATTRIBUTE_ALIGNED(4) juint _pi04_3d[] =
 {
     0x54442d00UL, 0x3fe921fbUL, 0x98cc5180UL, 0x3ce84698UL, 0xcbb5bf6cUL,
     0xb9dfc8f8UL
 };
 
-ALIGNED_(4) juint _pi04_5d[] =
+ATTRIBUTE_ALIGNED(4) juint _pi04_5d[] =
 {
     0x54400000UL, 0x3fe921fbUL, 0x1a600000UL, 0x3dc0b461UL, 0x2e000000UL,
     0x3b93198aUL, 0x25200000UL, 0x396b839aUL, 0x533e63a0UL, 0x37027044UL
 };
 
-ALIGNED_(4) juint _SCALE[] =
+ATTRIBUTE_ALIGNED(4) juint _SCALE[] =
 {
     0x00000000UL, 0x32600000UL
 };
 
-ALIGNED_(4) juint _zeros[] =
+ATTRIBUTE_ALIGNED(4) juint _zeros[] =
 {
     0x00000000UL, 0x00000000UL, 0x00000000UL, 0x80000000UL
 };
 
-ALIGNED_(4) juint _pi04_2d[] =
+ATTRIBUTE_ALIGNED(4) juint _pi04_2d[] =
 {
     0x54400000UL, 0x3fe921fbUL, 0x1a626331UL, 0x3dc0b461UL
 };
 
-ALIGNED_(4) juint _TWO_12H[] =
+ATTRIBUTE_ALIGNED(4) juint _TWO_12H[] =
 {
     0x00000000UL, 0x40b80000UL
 };
 
-ALIGNED_(2) jushort __4onpi_31l[] =
+ATTRIBUTE_ALIGNED(2) jushort __4onpi_31l[] =
 {
     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x836e, 0xa2f9,
     0x40d8, 0x0000, 0x0000, 0x0000, 0x2a50, 0x9c88, 0x40b7, 0x0000, 0x0000, 0x0000,
@@ -1629,29 +1624,29 @@
   ret(0);
 }
 
-ALIGNED_(16) juint StubRoutines::x86::_L_2il0floatpacket_0[] =
+ATTRIBUTE_ALIGNED(16) juint StubRoutines::x86::_L_2il0floatpacket_0[] =
 {
     0xffffffffUL, 0x7fffffffUL, 0x00000000UL, 0x00000000UL
 };
 
-ALIGNED_(16) juint StubRoutines::x86::_Pi4Inv[] =
+ATTRIBUTE_ALIGNED(16) juint StubRoutines::x86::_Pi4Inv[] =
 {
     0x6dc9c883UL, 0x3ff45f30UL
 };
 
-ALIGNED_(16) juint StubRoutines::x86::_Pi4x3[] =
+ATTRIBUTE_ALIGNED(16) juint StubRoutines::x86::_Pi4x3[] =
 {
     0x54443000UL, 0xbfe921fbUL, 0x3b39a000UL, 0x3d373dcbUL, 0xe0e68948UL,
     0xba845c06UL
 };
 
-ALIGNED_(16) juint StubRoutines::x86::_Pi4x4[] =
+ATTRIBUTE_ALIGNED(16) juint StubRoutines::x86::_Pi4x4[] =
 {
     0x54400000UL, 0xbfe921fbUL, 0x1a600000UL, 0xbdc0b461UL, 0x2e000000UL,
     0xbb93198aUL, 0x252049c1UL, 0xb96b839aUL
 };
 
-ALIGNED_(16) jushort _SP[] =
+ATTRIBUTE_ALIGNED(16) jushort _SP[] =
 {
     0xaaab, 0xaaaa, 0xaaaa, 0xaaaa, 0xbffc, 0x0000, 0x8887, 0x8888, 0x8888, 0x8888,
     0x3ff8, 0x0000, 0xc527, 0x0d00, 0x00d0, 0xd00d, 0xbff2, 0x0000, 0x45f6, 0xb616,
@@ -1660,7 +1655,7 @@
     0xbfd6, 0x0000, 0x8610, 0x307f, 0x62a1, 0xc921, 0x3fce, 0x0000
 };
 
-ALIGNED_(16) jushort _CP[] =
+ATTRIBUTE_ALIGNED(16) jushort _CP[] =
 {
     0x0000, 0x0000, 0x0000, 0x8000, 0xbffe, 0x0000, 0xaaa5, 0xaaaa, 0xaaaa, 0xaaaa,
     0x3ffa, 0x0000, 0x9c2f, 0x0b60, 0x60b6, 0xb60b, 0xbff5, 0x0000, 0xf024, 0x0cac,
@@ -1669,7 +1664,7 @@
     0xbfda, 0x0000, 0x3ac6, 0x0ba0, 0x07ce, 0xd585, 0x3fd2, 0x0000
 };
 
-ALIGNED_(16) juint StubRoutines::x86::_ones[] =
+ATTRIBUTE_ALIGNED(16) juint StubRoutines::x86::_ones[] =
 {
     0x00000000UL, 0x3ff00000UL, 0x00000000UL, 0xbff00000UL
 };
@@ -2197,7 +2192,7 @@
   jmp(B1_15);
 }
 
-ALIGNED_(16) juint _static_const_table_sin[] =
+ATTRIBUTE_ALIGNED(16) juint _static_const_table_sin[] =
 {
     0x00000000UL, 0x00000000UL, 0x00000000UL, 0x00000000UL, 0x00000000UL,
     0x00000000UL, 0x00000000UL, 0x3ff00000UL, 0x176d6d31UL, 0xbf73b92eUL,
--- a/src/hotspot/cpu/x86/macroAssembler_x86_tan.cpp	Tue May 15 10:13:52 2018 -0700
+++ b/src/hotspot/cpu/x86/macroAssembler_x86_tan.cpp	Wed May 16 09:45:40 2018 -0700
@@ -27,14 +27,9 @@
 #include "precompiled.hpp"
 #include "asm/assembler.hpp"
 #include "asm/assembler.inline.hpp"
+#include "macroAssembler_x86.hpp"
 #include "runtime/stubRoutines.hpp"
-#include "macroAssembler_x86.hpp"
-
-#ifdef _MSC_VER
-#define ALIGNED_(x) __declspec(align(x))
-#else
-#define ALIGNED_(x) __attribute__ ((aligned(x)))
-#endif
+#include "utilities/globalDefinitions.hpp"
 
 /******************************************************************************/
 //                     ALGORITHM DESCRIPTION - TAN()
@@ -107,42 +102,42 @@
 
 #ifdef _LP64
 // The 64 bit code is at most SSE2 compliant
-ALIGNED_(16) juint _ONEHALF_tan[] =
+ATTRIBUTE_ALIGNED(16) juint _ONEHALF_tan[] =
 {
     0x00000000UL, 0x3fe00000UL, 0x00000000UL, 0x3fe00000UL
 };
 
-ALIGNED_(16) juint _MUL16[] =
+ATTRIBUTE_ALIGNED(16) juint _MUL16[] =
 {
     0x00000000UL, 0x40300000UL, 0x00000000UL, 0x3ff00000UL
 };
 
-ALIGNED_(16) juint _sign_mask_tan[] =
+ATTRIBUTE_ALIGNED(16) juint _sign_mask_tan[] =
 {
     0x00000000UL, 0x80000000UL, 0x00000000UL, 0x80000000UL
 };
 
-ALIGNED_(16) juint _PI32INV_tan[] =
+ATTRIBUTE_ALIGNED(16) juint _PI32INV_tan[] =
 {
     0x6dc9c883UL, 0x3fe45f30UL, 0x6dc9c883UL, 0x40245f30UL
 };
 
-ALIGNED_(16) juint _P_1_tan[] =
+ATTRIBUTE_ALIGNED(16) juint _P_1_tan[] =
 {
     0x54444000UL, 0x3fb921fbUL, 0x54440000UL, 0x3fb921fbUL
 };
 
-ALIGNED_(16) juint _P_2_tan[] =
+ATTRIBUTE_ALIGNED(16) juint _P_2_tan[] =
 {
     0x67674000UL, 0xbd32e7b9UL, 0x4c4c0000UL, 0x3d468c23UL
 };
 
-ALIGNED_(16) juint _P_3_tan[] =
+ATTRIBUTE_ALIGNED(16) juint _P_3_tan[] =
 {
     0x3707344aUL, 0x3aa8a2e0UL, 0x03707345UL, 0x3ae98a2eUL
 };
 
-ALIGNED_(16) juint _Ctable_tan[] =
+ATTRIBUTE_ALIGNED(16) juint _Ctable_tan[] =
 {
     0x00000000UL, 0x00000000UL, 0x00000000UL, 0x00000000UL, 0x882c10faUL,
     0x3f9664f4UL, 0x00000000UL, 0x00000000UL, 0x00000000UL, 0x00000000UL,
@@ -428,37 +423,37 @@
     0x00000000UL, 0x00000000UL, 0x00000000UL
 };
 
-ALIGNED_(16) juint _MASK_35_tan[] =
+ATTRIBUTE_ALIGNED(16) juint _MASK_35_tan[] =
 {
     0xfffc0000UL, 0xffffffffUL, 0x00000000UL, 0x00000000UL
 };
 
-ALIGNED_(16) juint _Q_11_tan[] =
+ATTRIBUTE_ALIGNED(16) juint _Q_11_tan[] =
 {
     0xb8fe4d77UL, 0x3f82609aUL
 };
 
-ALIGNED_(16) juint _Q_9_tan[] =
+ATTRIBUTE_ALIGNED(16) juint _Q_9_tan[] =
 {
     0xbf847a43UL, 0x3f9664a0UL
 };
 
-ALIGNED_(16) juint _Q_7_tan[] =
+ATTRIBUTE_ALIGNED(16) juint _Q_7_tan[] =
 {
     0x52c4c8abUL, 0x3faba1baUL
 };
 
-ALIGNED_(16) juint _Q_5_tan[] =
+ATTRIBUTE_ALIGNED(16) juint _Q_5_tan[] =
 {
     0x11092746UL, 0x3fc11111UL
 };
 
-ALIGNED_(16) juint _Q_3_tan[] =
+ATTRIBUTE_ALIGNED(16) juint _Q_3_tan[] =
 {
     0x55555612UL, 0x3fd55555UL
 };
 
-ALIGNED_(16) juint _PI_INV_TABLE_tan[] =
+ATTRIBUTE_ALIGNED(16) juint _PI_INV_TABLE_tan[] =
 {
     0x00000000UL, 0x00000000UL, 0xa2f9836eUL, 0x4e441529UL, 0xfc2757d1UL,
     0xf534ddc0UL, 0xdb629599UL, 0x3c439041UL, 0xfe5163abUL, 0xdebbc561UL,
@@ -471,32 +466,32 @@
     0xf0cfbc21UL
 };
 
-ALIGNED_(8) juint _PI_4_tan[] =
+ATTRIBUTE_ALIGNED(8) juint _PI_4_tan[] =
 {
     0x00000000UL, 0x3fe921fbUL, 0x4611a626UL, 0x3e85110bUL
 };
 
-ALIGNED_(8) juint _QQ_2_tan[] =
+ATTRIBUTE_ALIGNED(8) juint _QQ_2_tan[] =
 {
     0x676733afUL, 0x3d32e7b9UL
 };
 
-ALIGNED_(8) juint _ONE_tan[] =
+ATTRIBUTE_ALIGNED(8) juint _ONE_tan[] =
 {
     0x00000000UL, 0x3ff00000UL
 };
 
-ALIGNED_(8) juint _TWO_POW_55_tan[] =
+ATTRIBUTE_ALIGNED(8) juint _TWO_POW_55_tan[] =
 {
     0x00000000UL, 0x43600000UL
 };
 
-ALIGNED_(4) juint _TWO_POW_M55_tan[] =
+ATTRIBUTE_ALIGNED(4) juint _TWO_POW_M55_tan[] =
 {
     0x00000000UL, 0x3c800000UL
 };
 
-ALIGNED_(4) juint _NEG_ZERO_tan[] =
+ATTRIBUTE_ALIGNED(4) juint _NEG_ZERO_tan[] =
 {
     0x00000000UL, 0x80000000UL
 };
@@ -1064,21 +1059,21 @@
 }
 #else
 // The 32 bit code is at most SSE2 compliant
-ALIGNED_(16) jushort _TP[] =
+ATTRIBUTE_ALIGNED(16) jushort _TP[] =
 {
     0x4cd6, 0xaf6c, 0xc710, 0xc662, 0xbffd, 0x0000, 0x4b06, 0xb0ac, 0xd3b2, 0xcc2c,
     0x3ff9, 0x0000, 0x00e3, 0xc850, 0xaa28, 0x9533, 0xbff3, 0x0000, 0x2ff0, 0x466d,
     0x1a3b, 0xb266, 0x3fe5, 0x0000
 };
 
-ALIGNED_(16) jushort _TQ[] =
+ATTRIBUTE_ALIGNED(16) jushort _TQ[] =
 {
     0x399c, 0x8391, 0x154c, 0x94ca, 0xbfff, 0x0000, 0xb6a3, 0xc36a, 0x44e2, 0x8a2c,
     0x3ffe, 0x0000, 0xb70f, 0xd068, 0xa6ce, 0xe9dd, 0xbff9, 0x0000, 0x820f, 0x51ce,
     0x7d76, 0x9bff, 0x3ff3, 0x0000
 };
 
-ALIGNED_(16) jushort _GP[] =
+ATTRIBUTE_ALIGNED(16) jushort _GP[] =
 {
     0xaaab, 0xaaaa, 0xaaaa, 0xaaaa, 0xbffd, 0x0000, 0xb62f, 0x0b60, 0x60b6, 0xb60b,
     0xbff9, 0x0000, 0xdfa7, 0x08aa, 0x55e0, 0x8ab3, 0xbff6, 0x0000, 0x85a0, 0xa819,
@@ -1670,7 +1665,7 @@
   jmp(B1_15);
 }
 
-ALIGNED_(16) juint _static_const_table_tan[] =
+ATTRIBUTE_ALIGNED(16) juint _static_const_table_tan[] =
 {
     0x00000000UL, 0x00000000UL, 0x00000000UL, 0x00000000UL, 0x882c10faUL,
     0x3f9664f4UL, 0x00000000UL, 0x00000000UL, 0x00000000UL, 0x00000000UL,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/cpu/x86/rdtsc_x86.cpp	Wed May 16 09:45:40 2018 -0700
@@ -0,0 +1,210 @@
+/*
+ * Copyright (c) 2013, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "rdtsc_x86.hpp"
+#include "runtime/thread.inline.hpp"
+#include "vm_version_ext_x86.hpp"
+
+// The following header contains the implementations of rdtsc()
+#include OS_CPU_HEADER_INLINE(os)
+
+static jlong _epoch = 0;
+static bool rdtsc_elapsed_counter_enabled = false;
+static jlong tsc_frequency = 0;
+
+static jlong set_epoch() {
+  assert(0 == _epoch, "invariant");
+  _epoch = os::rdtsc();
+  return _epoch;
+}
+
+// Base loop to estimate ticks frequency for tsc counter from user mode.
+// Volatiles and sleep() are used to prevent compiler from applying optimizations.
+static void do_time_measurements(volatile jlong& time_base,
+                                 volatile jlong& time_fast,
+                                 volatile jlong& time_base_elapsed,
+                                 volatile jlong& time_fast_elapsed) {
+  static const unsigned int FT_SLEEP_MILLISECS = 1;
+  const unsigned int loopcount = 3;
+
+  volatile jlong start = 0;
+  volatile jlong fstart = 0;
+  volatile jlong end = 0;
+  volatile jlong fend = 0;
+
+  // Figure out the difference between rdtsc and os provided timer.
+  // base algorithm adopted from JRockit.
+  for (unsigned int times = 0; times < loopcount; times++) {
+    start = os::elapsed_counter();
+    OrderAccess::fence();
+    fstart = os::rdtsc();
+
+    // use sleep to prevent compiler from optimizing
+    os::sleep(Thread::current(), FT_SLEEP_MILLISECS, true);
+
+    end = os::elapsed_counter();
+    OrderAccess::fence();
+    fend = os::rdtsc();
+
+    time_base += end - start;
+    time_fast += fend - fstart;
+
+    // basis for calculating the os tick start
+    // to fast time tick start offset
+    time_base_elapsed += end;
+    time_fast_elapsed += (fend - _epoch);
+  }
+
+  time_base /= loopcount;
+  time_fast /= loopcount;
+  time_base_elapsed /= loopcount;
+  time_fast_elapsed /= loopcount;
+}
+
+static jlong initialize_frequency() {
+  assert(0 == tsc_frequency, "invariant");
+  assert(0 == _epoch, "invariant");
+  const jlong initial_counter = set_epoch();
+  if (initial_counter == 0) {
+    return 0;
+  }
+  // os time frequency
+  static double os_freq = (double)os::elapsed_frequency();
+  assert(os_freq > 0, "os_elapsed frequency corruption!");
+
+  double tsc_freq = .0;
+  double os_to_tsc_conv_factor = 1.0;
+
+  // if platform supports invariant tsc,
+  // apply higher resolution and granularity for conversion calculations
+  if (VM_Version_Ext::supports_tscinv_ext()) {
+    // for invariant tsc platforms, take the maximum qualified cpu frequency
+    tsc_freq = (double)VM_Version_Ext::maximum_qualified_cpu_frequency();
+    os_to_tsc_conv_factor = tsc_freq / os_freq;
+  } else {
+    // use measurements to estimate
+    // a conversion factor and the tsc frequency
+
+    volatile jlong time_base = 0;
+    volatile jlong time_fast = 0;
+    volatile jlong time_base_elapsed = 0;
+    volatile jlong time_fast_elapsed = 0;
+
+    // do measurements to get base data
+    // on os timer and fast ticks tsc time relation.
+    do_time_measurements(time_base, time_fast, time_base_elapsed, time_fast_elapsed);
+
+    // if invalid measurements, cannot proceed
+    if (time_fast == 0 || time_base == 0) {
+      return 0;
+    }
+
+    os_to_tsc_conv_factor = (double)time_fast / (double)time_base;
+    if (os_to_tsc_conv_factor > 1) {
+      // estimate on tsc counter frequency
+      tsc_freq = os_to_tsc_conv_factor * os_freq;
+    }
+  }
+
+  if ((tsc_freq < 0) || (tsc_freq > 0 && tsc_freq <= os_freq) || (os_to_tsc_conv_factor <= 1)) {
+    // safer to run with normal os time
+    tsc_freq = .0;
+  }
+
+  // frequency of the tsc_counter
+  return (jlong)tsc_freq;
+}
+
+static bool initialize_elapsed_counter() {
+  tsc_frequency = initialize_frequency();
+  return tsc_frequency != 0 && _epoch != 0;
+}
+
+static bool ergonomics() {
+  const bool invtsc_support = Rdtsc::is_supported();
+  if (FLAG_IS_DEFAULT(UseFastUnorderedTimeStamps) && invtsc_support) {
+    FLAG_SET_ERGO(bool, UseFastUnorderedTimeStamps, true);
+  }
+
+  bool ft_enabled = UseFastUnorderedTimeStamps && invtsc_support;
+
+  if (!ft_enabled) {
+    if (UseFastUnorderedTimeStamps && VM_Version::supports_tsc()) {
+      warning("\nThe hardware does not support invariant tsc (INVTSC) register and/or cannot guarantee tsc synchronization between sockets at startup.\n"\
+        "Values returned via rdtsc() are not guaranteed to be accurate, esp. when comparing values from cross sockets reads. Enabling UseFastUnorderedTimeStamps on non-invariant tsc hardware should be considered experimental.\n");
+      ft_enabled = true;
+    }
+  }
+
+  if (!ft_enabled) {
+    // Warn if unable to support command-line flag
+    if (UseFastUnorderedTimeStamps && !VM_Version::supports_tsc()) {
+      warning("Ignoring UseFastUnorderedTimeStamps, hardware does not support normal tsc");
+    }
+  }
+
+  return ft_enabled;
+}
+
+bool Rdtsc::is_supported() {
+  return VM_Version_Ext::supports_tscinv_ext();
+}
+
+bool Rdtsc::is_elapsed_counter_enabled() {
+  return rdtsc_elapsed_counter_enabled;
+}
+
+jlong Rdtsc::frequency() {
+  return tsc_frequency;
+}
+
+jlong Rdtsc::elapsed_counter() {
+  return os::rdtsc() - _epoch;
+}
+
+jlong Rdtsc::epoch() {
+  return _epoch;
+}
+
+jlong Rdtsc::raw() {
+  return os::rdtsc();
+}
+
+bool Rdtsc::initialize() {
+  static bool initialized = false;
+  if (!initialized) {
+    assert(!rdtsc_elapsed_counter_enabled, "invariant");
+    VM_Version_Ext::initialize();
+    assert(0 == tsc_frequency, "invariant");
+    assert(0 == _epoch, "invariant");
+    bool result = initialize_elapsed_counter(); // init hw
+    if (result) {
+      result = ergonomics(); // check logical state
+    }
+    rdtsc_elapsed_counter_enabled = result;
+    initialized = true;
+  }
+  return rdtsc_elapsed_counter_enabled;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/cpu/x86/rdtsc_x86.hpp	Wed May 16 09:45:40 2018 -0700
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2012, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef CPU_X86_VM_RDTSC_X86_HPP
+#define CPU_X86_VM_RDTSC_X86_HPP
+
+#include "memory/allocation.hpp"
+#include "utilities/macros.hpp"
+
+// Interface to the x86 rdtsc() time counter, if available.
+// Not guaranteed to be synchronized across hardware threads and
+// therefore software threads, and can be updated asynchronously
+// by software. elapsed_counter() can jump backwards
+// as well as jump forward when threads query different cores/sockets.
+// Very much not recommended for general use.
+// INVTSC is a minimal requirement for auto-enablement.
+
+class Rdtsc : AllStatic {
+ public:
+  static jlong elapsed_counter(); // provides quick time stamps
+  static jlong frequency();       // tsc register
+  static bool  is_supported();    // InvariantTSC
+  static jlong raw();             // direct rdtsc() access
+  static bool  is_elapsed_counter_enabled(); // turn off with -XX:-UseFastUnorderedTimeStamps
+  static jlong epoch();
+  static bool  initialize();
+};
+
+#endif // CPU_X86_VM_RDTSC_X86_HPP
--- a/src/hotspot/cpu/x86/stubRoutines_x86.cpp	Tue May 15 10:13:52 2018 -0700
+++ b/src/hotspot/cpu/x86/stubRoutines_x86.cpp	Wed May 16 09:45:40 2018 -0700
@@ -27,14 +27,9 @@
 #include "runtime/frame.inline.hpp"
 #include "runtime/stubRoutines.hpp"
 #include "runtime/thread.inline.hpp"
+#include "utilities/globalDefinitions.hpp"
 #include "crc32c.h"
 
-#ifdef _MSC_VER
-#define ALIGNED_(x) __declspec(align(x))
-#else
-#define ALIGNED_(x) __attribute__ ((aligned(x)))
-#endif
-
 // Implementation of the platform-specific part of StubRoutines - for
 // a description of how to extend it, see the stubRoutines.hpp file.
 
@@ -275,7 +270,7 @@
   }
 }
 
-ALIGNED_(64) juint StubRoutines::x86::_k256[] =
+ATTRIBUTE_ALIGNED(64) juint StubRoutines::x86::_k256[] =
 {
     0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL,
     0x3956c25bUL, 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL,
@@ -298,10 +293,10 @@
 #ifdef _LP64
 // used in MacroAssembler::sha256_AVX2
 // dynamically built from _k256
-ALIGNED_(64) juint StubRoutines::x86::_k256_W[2*sizeof(StubRoutines::x86::_k256)];
+ATTRIBUTE_ALIGNED(64) juint StubRoutines::x86::_k256_W[2*sizeof(StubRoutines::x86::_k256)];
 
 // used in MacroAssembler::sha512_AVX2
-ALIGNED_(64) julong StubRoutines::x86::_k512_W[] =
+ATTRIBUTE_ALIGNED(64) julong StubRoutines::x86::_k512_W[] =
 {
     0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL,
     0xb5c0fbcfec4d3b2fULL, 0xe9b5dba58189dbbcULL,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/cpu/x86/vm_version_ext_x86.cpp	Wed May 16 09:45:40 2018 -0700
@@ -0,0 +1,967 @@
+/*
+ * Copyright (c) 2013, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "jvm.h"
+#include "utilities/macros.hpp"
+#include "asm/macroAssembler.hpp"
+#include "asm/macroAssembler.inline.hpp"
+#include "memory/allocation.inline.hpp"
+#include "memory/resourceArea.hpp"
+#include "runtime/java.hpp"
+#include "runtime/stubCodeGenerator.hpp"
+#include "vm_version_ext_x86.hpp"
+
+typedef enum {
+   CPU_FAMILY_8086_8088  = 0,
+   CPU_FAMILY_INTEL_286  = 2,
+   CPU_FAMILY_INTEL_386  = 3,
+   CPU_FAMILY_INTEL_486  = 4,
+   CPU_FAMILY_PENTIUM    = 5,
+   CPU_FAMILY_PENTIUMPRO = 6,    // Same family several models
+   CPU_FAMILY_PENTIUM_4  = 0xF
+} FamilyFlag;
+
+ typedef enum {
+    RDTSCP_FLAG  = 0x08000000, // bit 27
+    INTEL64_FLAG = 0x20000000  // bit 29
+  } _featureExtendedEdxFlag;
+
+#define CPUID_STANDARD_FN   0x0
+#define CPUID_STANDARD_FN_1 0x1
+#define CPUID_STANDARD_FN_4 0x4
+#define CPUID_STANDARD_FN_B 0xb
+
+#define CPUID_EXTENDED_FN   0x80000000
+#define CPUID_EXTENDED_FN_1 0x80000001
+#define CPUID_EXTENDED_FN_2 0x80000002
+#define CPUID_EXTENDED_FN_3 0x80000003
+#define CPUID_EXTENDED_FN_4 0x80000004
+#define CPUID_EXTENDED_FN_7 0x80000007
+#define CPUID_EXTENDED_FN_8 0x80000008
+
+typedef enum {
+   FPU_FLAG     = 0x00000001,
+   VME_FLAG     = 0x00000002,
+   DE_FLAG      = 0x00000004,
+   PSE_FLAG     = 0x00000008,
+   TSC_FLAG     = 0x00000010,
+   MSR_FLAG     = 0x00000020,
+   PAE_FLAG     = 0x00000040,
+   MCE_FLAG     = 0x00000080,
+   CX8_FLAG     = 0x00000100,
+   APIC_FLAG    = 0x00000200,
+   SEP_FLAG     = 0x00000800,
+   MTRR_FLAG    = 0x00001000,
+   PGE_FLAG     = 0x00002000,
+   MCA_FLAG     = 0x00004000,
+   CMOV_FLAG    = 0x00008000,
+   PAT_FLAG     = 0x00010000,
+   PSE36_FLAG   = 0x00020000,
+   PSNUM_FLAG   = 0x00040000,
+   CLFLUSH_FLAG = 0x00080000,
+   DTS_FLAG     = 0x00200000,
+   ACPI_FLAG    = 0x00400000,
+   MMX_FLAG     = 0x00800000,
+   FXSR_FLAG    = 0x01000000,
+   SSE_FLAG     = 0x02000000,
+   SSE2_FLAG    = 0x04000000,
+   SS_FLAG      = 0x08000000,
+   HTT_FLAG     = 0x10000000,
+   TM_FLAG      = 0x20000000
+} FeatureEdxFlag;
+
+static BufferBlob* cpuid_brand_string_stub_blob;
+static const int   cpuid_brand_string_stub_size = 550;
+
+extern "C" {
+  typedef void (*getCPUIDBrandString_stub_t)(void*);
+}
+
+static getCPUIDBrandString_stub_t getCPUIDBrandString_stub = NULL;
+
+class VM_Version_Ext_StubGenerator: public StubCodeGenerator {
+ public:
+
+  VM_Version_Ext_StubGenerator(CodeBuffer *c) : StubCodeGenerator(c) {}
+
+  address generate_getCPUIDBrandString(void) {
+    // Flags to test CPU type.
+    const uint32_t HS_EFL_AC           = 0x40000;
+    const uint32_t HS_EFL_ID           = 0x200000;
+    // Values for when we don't have a CPUID instruction.
+    const int      CPU_FAMILY_SHIFT = 8;
+    const uint32_t CPU_FAMILY_386   = (3 << CPU_FAMILY_SHIFT);
+    const uint32_t CPU_FAMILY_486   = (4 << CPU_FAMILY_SHIFT);
+
+    Label detect_486, cpu486, detect_586, done, ext_cpuid;
+
+    StubCodeMark mark(this, "VM_Version_Ext", "getCPUIDNameInfo_stub");
+#   define __ _masm->
+
+    address start = __ pc();
+
+    //
+    // void getCPUIDBrandString(VM_Version::CpuidInfo* cpuid_info);
+    //
+    // LP64: rcx and rdx are first and second argument registers on windows
+
+    __ push(rbp);
+#ifdef _LP64
+    __ mov(rbp, c_rarg0); // cpuid_info address
+#else
+    __ movptr(rbp, Address(rsp, 8)); // cpuid_info address
+#endif
+    __ push(rbx);
+    __ push(rsi);
+    __ pushf();          // preserve rbx, and flags
+    __ pop(rax);
+    __ push(rax);
+    __ mov(rcx, rax);
+    //
+    // if we are unable to change the AC flag, we have a 386
+    //
+    __ xorl(rax, HS_EFL_AC);
+    __ push(rax);
+    __ popf();
+    __ pushf();
+    __ pop(rax);
+    __ cmpptr(rax, rcx);
+    __ jccb(Assembler::notEqual, detect_486);
+
+    __ movl(rax, CPU_FAMILY_386);
+    __ jmp(done);
+
+    //
+    // If we are unable to change the ID flag, we have a 486 which does
+    // not support the "cpuid" instruction.
+    //
+    __ bind(detect_486);
+    __ mov(rax, rcx);
+    __ xorl(rax, HS_EFL_ID);
+    __ push(rax);
+    __ popf();
+    __ pushf();
+    __ pop(rax);
+    __ cmpptr(rcx, rax);
+    __ jccb(Assembler::notEqual, detect_586);
+
+    __ bind(cpu486);
+    __ movl(rax, CPU_FAMILY_486);
+    __ jmp(done);
+
+    //
+    // At this point, we have a chip which supports the "cpuid" instruction
+    //
+    __ bind(detect_586);
+    __ xorl(rax, rax);
+    __ cpuid();
+    __ orl(rax, rax);
+    __ jcc(Assembler::equal, cpu486);   // if cpuid doesn't support an input
+                                        // value of at least 1, we give up and
+                                        // assume a 486
+
+    //
+    // Extended cpuid(0x80000000) for processor brand string detection
+    //
+    __ bind(ext_cpuid);
+    __ movl(rax, CPUID_EXTENDED_FN);
+    __ cpuid();
+    __ cmpl(rax, CPUID_EXTENDED_FN_4);
+    __ jcc(Assembler::below, done);
+
+    //
+    // Extended cpuid(0x80000002)  // first 16 bytes in brand string
+    //
+    __ movl(rax, CPUID_EXTENDED_FN_2);
+    __ cpuid();
+    __ lea(rsi, Address(rbp, in_bytes(VM_Version_Ext::proc_name_0_offset())));
+    __ movl(Address(rsi, 0), rax);
+    __ lea(rsi, Address(rbp, in_bytes(VM_Version_Ext::proc_name_1_offset())));
+    __ movl(Address(rsi, 0), rbx);
+    __ lea(rsi, Address(rbp, in_bytes(VM_Version_Ext::proc_name_2_offset())));
+    __ movl(Address(rsi, 0), rcx);
+    __ lea(rsi, Address(rbp, in_bytes(VM_Version_Ext::proc_name_3_offset())));
+    __ movl(Address(rsi,0), rdx);
+
+    //
+    // Extended cpuid(0x80000003) // next 16 bytes in brand string
+    //
+    __ movl(rax, CPUID_EXTENDED_FN_3);
+    __ cpuid();
+    __ lea(rsi, Address(rbp, in_bytes(VM_Version_Ext::proc_name_4_offset())));
+    __ movl(Address(rsi, 0), rax);
+    __ lea(rsi, Address(rbp, in_bytes(VM_Version_Ext::proc_name_5_offset())));
+    __ movl(Address(rsi, 0), rbx);
+    __ lea(rsi, Address(rbp, in_bytes(VM_Version_Ext::proc_name_6_offset())));
+    __ movl(Address(rsi, 0), rcx);
+    __ lea(rsi, Address(rbp, in_bytes(VM_Version_Ext::proc_name_7_offset())));
+    __ movl(Address(rsi,0), rdx);
+
+    //
+    // Extended cpuid(0x80000004) // last 16 bytes in brand string
+    //
+    __ movl(rax, CPUID_EXTENDED_FN_4);
+    __ cpuid();
+    __ lea(rsi, Address(rbp, in_bytes(VM_Version_Ext::proc_name_8_offset())));
+    __ movl(Address(rsi, 0), rax);
+    __ lea(rsi, Address(rbp, in_bytes(VM_Version_Ext::proc_name_9_offset())));
+    __ movl(Address(rsi, 0), rbx);
+    __ lea(rsi, Address(rbp, in_bytes(VM_Version_Ext::proc_name_10_offset())));
+    __ movl(Address(rsi, 0), rcx);
+    __ lea(rsi, Address(rbp, in_bytes(VM_Version_Ext::proc_name_11_offset())));
+    __ movl(Address(rsi,0), rdx);
+
+    //
+    // return
+    //
+    __ bind(done);
+    __ popf();
+    __ pop(rsi);
+    __ pop(rbx);
+    __ pop(rbp);
+    __ ret(0);
+
+#   undef __
+
+    return start;
+  };
+};
+
+
+// VM_Version_Ext statics
+const size_t VM_Version_Ext::VENDOR_LENGTH = 13;
+const size_t VM_Version_Ext::CPU_EBS_MAX_LENGTH = (3 * 4 * 4 + 1);
+const size_t VM_Version_Ext::CPU_TYPE_DESC_BUF_SIZE = 256;
+const size_t VM_Version_Ext::CPU_DETAILED_DESC_BUF_SIZE = 4096;
+char* VM_Version_Ext::_cpu_brand_string = NULL;
+jlong VM_Version_Ext::_max_qualified_cpu_frequency = 0;
+
+int VM_Version_Ext::_no_of_threads = 0;
+int VM_Version_Ext::_no_of_cores = 0;
+int VM_Version_Ext::_no_of_packages = 0;
+
+void VM_Version_Ext::initialize(void) {
+  ResourceMark rm;
+
+  cpuid_brand_string_stub_blob = BufferBlob::create("getCPUIDBrandString_stub", cpuid_brand_string_stub_size);
+  if (cpuid_brand_string_stub_blob == NULL) {
+    vm_exit_during_initialization("Unable to allocate getCPUIDBrandString_stub");
+  }
+  CodeBuffer c(cpuid_brand_string_stub_blob);
+  VM_Version_Ext_StubGenerator g(&c);
+  getCPUIDBrandString_stub = CAST_TO_FN_PTR(getCPUIDBrandString_stub_t,
+                                   g.generate_getCPUIDBrandString());
+}
+
+const char* VM_Version_Ext::cpu_model_description(void) {
+  uint32_t cpu_family = extended_cpu_family();
+  uint32_t cpu_model = extended_cpu_model();
+  const char* model = NULL;
+
+  if (cpu_family == CPU_FAMILY_PENTIUMPRO) {
+    for (uint32_t i = 0; i <= cpu_model; i++) {
+      model = _model_id_pentium_pro[i];
+      if (model == NULL) {
+        break;
+      }
+    }
+  }
+  return model;
+}
+
+const char* VM_Version_Ext::cpu_brand_string(void) {
+  if (_cpu_brand_string == NULL) {
+    _cpu_brand_string = NEW_C_HEAP_ARRAY_RETURN_NULL(char, CPU_EBS_MAX_LENGTH, mtInternal);
+    if (NULL == _cpu_brand_string) {
+      return NULL;
+    }
+    int ret_val = cpu_extended_brand_string(_cpu_brand_string, CPU_EBS_MAX_LENGTH);
+    if (ret_val != OS_OK) {
+      FREE_C_HEAP_ARRAY(char, _cpu_brand_string);
+      _cpu_brand_string = NULL;
+    }
+  }
+  return _cpu_brand_string;
+}
+
+const char* VM_Version_Ext::cpu_brand(void) {
+  const char*  brand  = NULL;
+
+  if ((_cpuid_info.std_cpuid1_ebx.value & 0xFF) > 0) {
+    int brand_num = _cpuid_info.std_cpuid1_ebx.value & 0xFF;
+    brand = _brand_id[0];
+    for (int i = 0; brand != NULL && i <= brand_num; i += 1) {
+      brand = _brand_id[i];
+    }
+  }
+  return brand;
+}
+
+bool VM_Version_Ext::cpu_is_em64t(void) {
+  return ((_cpuid_info.ext_cpuid1_edx.value & INTEL64_FLAG) == INTEL64_FLAG);
+}
+
+bool VM_Version_Ext::is_netburst(void) {
+  return (is_intel() && (extended_cpu_family() == CPU_FAMILY_PENTIUM_4));
+}
+
+bool VM_Version_Ext::supports_tscinv_ext(void) {
+  if (!supports_tscinv_bit()) {
+    return false;
+  }
+
+  if (is_intel()) {
+    return true;
+  }
+
+  if (is_amd()) {
+    return !is_amd_Barcelona();
+  }
+
+  return false;
+}
+
+void VM_Version_Ext::resolve_cpu_information_details(void) {
+
+  // in future we want to base this information on proper cpu
+  // and cache topology enumeration such as:
+  // Intel 64 Architecture Processor Topology Enumeration
+  // which supports system cpu and cache topology enumeration
+  // either using 2xAPICIDs or initial APICIDs
+
+  // currently only rough cpu information estimates
+  // which will not necessarily reflect the exact configuration of the system
+
+  // this is the number of logical hardware threads
+  // visible to the operating system
+  _no_of_threads = os::processor_count();
+
+  // find out number of threads per cpu package
+  int threads_per_package = threads_per_core() * cores_per_cpu();
+
+  // use amount of threads visible to the process in order to guess number of sockets
+  _no_of_packages = _no_of_threads / threads_per_package;
+
+  // process might only see a subset of the total number of threads
+  // from a single processor package. Virtualization/resource management for example.
+  // If so then just write a hard 1 as num of pkgs.
+  if (0 == _no_of_packages) {
+    _no_of_packages = 1;
+  }
+
+  // estimate the number of cores
+  _no_of_cores = cores_per_cpu() * _no_of_packages;
+}
+
+int VM_Version_Ext::number_of_threads(void) {
+  if (_no_of_threads == 0) {
+   resolve_cpu_information_details();
+  }
+  return _no_of_threads;
+}
+
+int VM_Version_Ext::number_of_cores(void) {
+  if (_no_of_cores == 0) {
+    resolve_cpu_information_details();
+  }
+  return _no_of_cores;
+}
+
+int VM_Version_Ext::number_of_sockets(void) {
+  if (_no_of_packages == 0) {
+    resolve_cpu_information_details();
+  }
+  return _no_of_packages;
+}
+
+const char* VM_Version_Ext::cpu_family_description(void) {
+  int cpu_family_id = extended_cpu_family();
+  if (is_amd()) {
+    return _family_id_amd[cpu_family_id];
+  }
+  if (is_intel()) {
+    if (cpu_family_id == CPU_FAMILY_PENTIUMPRO) {
+      return cpu_model_description();
+    }
+    return _family_id_intel[cpu_family_id];
+  }
+  return "Unknown x86";
+}
+
+int VM_Version_Ext::cpu_type_description(char* const buf, size_t buf_len) {
+  assert(buf != NULL, "buffer is NULL!");
+  assert(buf_len >= CPU_TYPE_DESC_BUF_SIZE, "buffer len should at least be == CPU_TYPE_DESC_BUF_SIZE!");
+
+  const char* cpu_type = NULL;
+  const char* x64 = NULL;
+
+  if (is_intel()) {
+    cpu_type = "Intel";
+    x64 = cpu_is_em64t() ? " Intel64" : "";
+  } else if (is_amd()) {
+    cpu_type = "AMD";
+    x64 = cpu_is_em64t() ? " AMD64" : "";
+  } else {
+    cpu_type = "Unknown x86";
+    x64 = cpu_is_em64t() ? " x86_64" : "";
+  }
+
+  jio_snprintf(buf, buf_len, "%s %s%s SSE SSE2%s%s%s%s%s%s%s%s",
+    cpu_type,
+    cpu_family_description(),
+    supports_ht() ? " (HT)" : "",
+    supports_sse3() ? " SSE3" : "",
+    supports_ssse3() ? " SSSE3" : "",
+    supports_sse4_1() ? " SSE4.1" : "",
+    supports_sse4_2() ? " SSE4.2" : "",
+    supports_sse4a() ? " SSE4A" : "",
+    is_netburst() ? " Netburst" : "",
+    is_intel_family_core() ? " Core" : "",
+    x64);
+
+  return OS_OK;
+}
+
+int VM_Version_Ext::cpu_extended_brand_string(char* const buf, size_t buf_len) {
+  assert(buf != NULL, "buffer is NULL!");
+  assert(buf_len >= CPU_EBS_MAX_LENGTH, "buffer len should at least be == CPU_EBS_MAX_LENGTH!");
+  assert(getCPUIDBrandString_stub != NULL, "not initialized");
+
+  // invoke newly generated asm code to fetch CPU Brand String
+  getCPUIDBrandString_stub(&_cpuid_info);
+
+  // fetch results into buffer
+  *((uint32_t*) &buf[0])  = _cpuid_info.proc_name_0;
+  *((uint32_t*) &buf[4])  = _cpuid_info.proc_name_1;
+  *((uint32_t*) &buf[8])  = _cpuid_info.proc_name_2;
+  *((uint32_t*) &buf[12]) = _cpuid_info.proc_name_3;
+  *((uint32_t*) &buf[16]) = _cpuid_info.proc_name_4;
+  *((uint32_t*) &buf[20]) = _cpuid_info.proc_name_5;
+  *((uint32_t*) &buf[24]) = _cpuid_info.proc_name_6;
+  *((uint32_t*) &buf[28]) = _cpuid_info.proc_name_7;
+  *((uint32_t*) &buf[32]) = _cpuid_info.proc_name_8;
+  *((uint32_t*) &buf[36]) = _cpuid_info.proc_name_9;
+  *((uint32_t*) &buf[40]) = _cpuid_info.proc_name_10;
+  *((uint32_t*) &buf[44]) = _cpuid_info.proc_name_11;
+
+  return OS_OK;
+}
+
+size_t VM_Version_Ext::cpu_write_support_string(char* const buf, size_t buf_len) {
+  assert(buf != NULL, "buffer is NULL!");
+  assert(buf_len > 0, "buffer len not enough!");
+
+  unsigned int flag = 0;
+  unsigned int fi = 0;
+  size_t       written = 0;
+  const char*  prefix = "";
+
+#define WRITE_TO_BUF(string)                                                          \
+  {                                                                                   \
+    int res = jio_snprintf(&buf[written], buf_len - written, "%s%s", prefix, string); \
+    if (res < 0 || (size_t) res >= buf_len - 1) {                                     \
+      buf[buf_len-1] = '\0';                                                          \
+      return buf_len - 1;                                                             \
+    }                                                                                 \
+    written += res;                                                                   \
+    if (prefix[0] == '\0') {                                                          \
+      prefix = ", ";                                                                  \
+    }                                                                                 \
+  }
+
+  for (flag = 1, fi = 0; flag <= 0x20000000 ; flag <<= 1, fi++) {
+    if (flag == HTT_FLAG && (((_cpuid_info.std_cpuid1_ebx.value >> 16) & 0xff) <= 1)) {
+      continue; /* no hyperthreading */
+    } else if (flag == SEP_FLAG && (cpu_family() == CPU_FAMILY_PENTIUMPRO && ((_cpuid_info.std_cpuid1_eax.value & 0xff) < 0x33))) {
+      continue; /* no fast system call */
+    }
+    if ((_cpuid_info.std_cpuid1_edx.value & flag) && strlen(_feature_edx_id[fi]) > 0) {
+      WRITE_TO_BUF(_feature_edx_id[fi]);
+    }
+  }
+
+  for (flag = 1, fi = 0; flag <= 0x20000000; flag <<= 1, fi++) {
+    if ((_cpuid_info.std_cpuid1_ecx.value & flag) && strlen(_feature_ecx_id[fi]) > 0) {
+      WRITE_TO_BUF(_feature_ecx_id[fi]);
+    }
+  }
+
+  for (flag = 1, fi = 0; flag <= 0x20000000 ; flag <<= 1, fi++) {
+    if ((_cpuid_info.ext_cpuid1_ecx.value & flag) && strlen(_feature_extended_ecx_id[fi]) > 0) {
+      WRITE_TO_BUF(_feature_extended_ecx_id[fi]);
+    }
+  }
+
+  for (flag = 1, fi = 0; flag <= 0x20000000; flag <<= 1, fi++) {
+    if ((_cpuid_info.ext_cpuid1_edx.value & flag) && strlen(_feature_extended_edx_id[fi]) > 0) {
+      WRITE_TO_BUF(_feature_extended_edx_id[fi]);
+    }
+  }
+
+  if (supports_tscinv_bit()) {
+      WRITE_TO_BUF("Invariant TSC");
+  }
+
+  return written;
+}
+
+/**
+ * Write a detailed description of the cpu to a given buffer, including
+ * feature set.
+ */
+int VM_Version_Ext::cpu_detailed_description(char* const buf, size_t buf_len) {
+  assert(buf != NULL, "buffer is NULL!");
+  assert(buf_len >= CPU_DETAILED_DESC_BUF_SIZE, "buffer len should at least be == CPU_DETAILED_DESC_BUF_SIZE!");
+
+  static const char* unknown = "<unknown>";
+  char               vendor_id[VENDOR_LENGTH];
+  const char*        family = NULL;
+  const char*        model = NULL;
+  const char*        brand = NULL;
+  int                outputLen = 0;
+
+  family = cpu_family_description();
+  if (family == NULL) {
+    family = unknown;
+  }
+
+  model = cpu_model_description();
+  if (model == NULL) {
+    model = unknown;
+  }
+
+  brand = cpu_brand_string();
+
+  if (brand == NULL) {
+    brand = cpu_brand();
+    if (brand == NULL) {
+      brand = unknown;
+    }
+  }
+
+  *((uint32_t*) &vendor_id[0]) = _cpuid_info.std_vendor_name_0;
+  *((uint32_t*) &vendor_id[4]) = _cpuid_info.std_vendor_name_2;
+  *((uint32_t*) &vendor_id[8]) = _cpuid_info.std_vendor_name_1;
+  vendor_id[VENDOR_LENGTH-1] = '\0';
+
+  outputLen = jio_snprintf(buf, buf_len, "Brand: %s, Vendor: %s\n"
+    "Family: %s (0x%x), Model: %s (0x%x), Stepping: 0x%x\n"
+    "Ext. family: 0x%x, Ext. model: 0x%x, Type: 0x%x, Signature: 0x%8.8x\n"
+    "Features: ebx: 0x%8.8x, ecx: 0x%8.8x, edx: 0x%8.8x\n"
+    "Ext. features: eax: 0x%8.8x, ebx: 0x%8.8x, ecx: 0x%8.8x, edx: 0x%8.8x\n"
+    "Supports: ",
+    brand,
+    vendor_id,
+    family,
+    extended_cpu_family(),
+    model,
+    extended_cpu_model(),
+    cpu_stepping(),
+    _cpuid_info.std_cpuid1_eax.bits.ext_family,
+    _cpuid_info.std_cpuid1_eax.bits.ext_model,
+    _cpuid_info.std_cpuid1_eax.bits.proc_type,
+    _cpuid_info.std_cpuid1_eax.value,
+    _cpuid_info.std_cpuid1_ebx.value,
+    _cpuid_info.std_cpuid1_ecx.value,
+    _cpuid_info.std_cpuid1_edx.value,
+    _cpuid_info.ext_cpuid1_eax,
+    _cpuid_info.ext_cpuid1_ebx,
+    _cpuid_info.ext_cpuid1_ecx,
+    _cpuid_info.ext_cpuid1_edx);
+
+  if (outputLen < 0 || (size_t) outputLen >= buf_len - 1) {
+    buf[buf_len-1] = '\0';
+    return OS_ERR;
+  }
+
+  cpu_write_support_string(&buf[outputLen], buf_len - outputLen);
+
+  return OS_OK;
+}
+
+const char* VM_Version_Ext::cpu_name(void) {
+  char cpu_type_desc[CPU_TYPE_DESC_BUF_SIZE];
+  size_t cpu_desc_len = sizeof(cpu_type_desc);
+
+  cpu_type_description(cpu_type_desc, cpu_desc_len);
+  char* tmp = NEW_C_HEAP_ARRAY_RETURN_NULL(char, cpu_desc_len, mtTracing);
+  if (NULL == tmp) {
+    return NULL;
+  }
+  strncpy(tmp, cpu_type_desc, cpu_desc_len);
+  return tmp;
+}
+
+const char* VM_Version_Ext::cpu_description(void) {
+  char cpu_detailed_desc_buffer[CPU_DETAILED_DESC_BUF_SIZE];
+  size_t cpu_detailed_desc_len = sizeof(cpu_detailed_desc_buffer);
+
+  cpu_detailed_description(cpu_detailed_desc_buffer, cpu_detailed_desc_len);
+
+  char* tmp = NEW_C_HEAP_ARRAY_RETURN_NULL(char, cpu_detailed_desc_len, mtTracing);
+
+  if (NULL == tmp) {
+    return NULL;
+  }
+
+  strncpy(tmp, cpu_detailed_desc_buffer, cpu_detailed_desc_len);
+  return tmp;
+}
+
+/**
+ *  See Intel Application note 485 (chapter 10) for details
+ *  on frequency extraction from cpu brand string.
+ *  http://www.intel.com/content/dam/www/public/us/en/documents/application-notes/processor-identification-cpuid-instruction-note.pdf
+ *
+ */
+jlong VM_Version_Ext::max_qualified_cpu_freq_from_brand_string(void) {
+  // get brand string
+  const char* const brand_string = cpu_brand_string();
+  if (brand_string == NULL) {
+    return 0;
+  }
+
+  const u8 MEGA = 1000000;
+  u8 multiplier = 0;
+  jlong frequency = 0;
+
+  // the frequency information in the cpu brand string
+  // is given in either of two formats "x.xxyHz" or "xxxxyHz",
+  // where y=M,G,T and x is digits
+  const char* Hz_location = strchr(brand_string, 'H');
+
+  if (Hz_location != NULL) {
+    if (*(Hz_location + 1) == 'z') {
+      // switch on y in "yHz"
+      switch(*(Hz_location - 1)) {
+        case 'M' :
+          // Set multiplier to frequency is in Hz
+          multiplier = MEGA;
+          break;
+        case 'G' :
+          multiplier = MEGA * 1000;
+          break;
+        case 'T' :
+          multiplier = MEGA * 1000 * 1000;
+          break;
+      }
+    }
+  }
+
+  if (multiplier > 0) {
+    // compute frequency (in Hz) from brand string
+    if (*(Hz_location - 4) == '.') { // if format is "x.xx"
+      frequency =  (jlong)(*(Hz_location - 5) - '0') * (multiplier);
+      frequency += (jlong)(*(Hz_location - 3) - '0') * (multiplier / 10);
+      frequency += (jlong)(*(Hz_location - 2) - '0') * (multiplier / 100);
+    } else { // format is "xxxx"
+      frequency =  (jlong)(*(Hz_location - 5) - '0') * 1000;
+      frequency += (jlong)(*(Hz_location - 4) - '0') * 100;
+      frequency += (jlong)(*(Hz_location - 3) - '0') * 10;
+      frequency += (jlong)(*(Hz_location - 2) - '0');
+      frequency *= multiplier;
+    }
+  }
+  return frequency;
+}
+
+
+jlong VM_Version_Ext::maximum_qualified_cpu_frequency(void) {
+  if (_max_qualified_cpu_frequency == 0) {
+    _max_qualified_cpu_frequency = max_qualified_cpu_freq_from_brand_string();
+  }
+  return _max_qualified_cpu_frequency;
+}
+
+const char* const VM_Version_Ext::_family_id_intel[] = {
+  "8086/8088",
+  "",
+  "286",
+  "386",
+  "486",
+  "Pentium",
+  "Pentium Pro",   //or Pentium-M/Woodcrest depeding on model
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "Pentium 4"
+};
+
+const char* const VM_Version_Ext::_family_id_amd[] = {
+  "",
+  "",
+  "",
+  "",
+  "5x86",
+  "K5/K6",
+  "Athlon/AthlonXP",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "Opteron/Athlon64",
+  "Opteron QC/Phenom"  // Barcelona et.al.
+};
+// Partially from Intel 64 and IA-32 Architecture Software Developer's Manual,
+// September 2013, Vol 3C Table 35-1
+const char* const VM_Version_Ext::_model_id_pentium_pro[] = {
+  "",
+  "Pentium Pro",
+  "",
+  "Pentium II model 3",
+  "",
+  "Pentium II model 5/Xeon/Celeron",
+  "Celeron",
+  "Pentium III/Pentium III Xeon",
+  "Pentium III/Pentium III Xeon",
+  "Pentium M model 9",    // Yonah
+  "Pentium III, model A",
+  "Pentium III, model B",
+  "",
+  "Pentium M model D",    // Dothan
+  "",
+  "Core 2",               // 0xf Woodcrest/Conroe/Merom/Kentsfield/Clovertown
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "Celeron",              // 0x16 Celeron 65nm
+  "Core 2",               // 0x17 Penryn / Harpertown
+  "",
+  "",
+  "Core i7",              // 0x1A CPU_MODEL_NEHALEM_EP
+  "Atom",                 // 0x1B Z5xx series Silverthorn
+  "",
+  "Core 2",               // 0x1D Dunnington (6-core)
+  "Nehalem",              // 0x1E CPU_MODEL_NEHALEM
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "Westmere",             // 0x25 CPU_MODEL_WESTMERE
+  "",
+  "",
+  "",                     // 0x28
+  "",
+  "Sandy Bridge",         // 0x2a "2nd Generation Intel Core i7, i5, i3"
+  "",
+  "Westmere-EP",          // 0x2c CPU_MODEL_WESTMERE_EP
+  "Sandy Bridge-EP",      // 0x2d CPU_MODEL_SANDYBRIDGE_EP
+  "Nehalem-EX",           // 0x2e CPU_MODEL_NEHALEM_EX
+  "Westmere-EX",          // 0x2f CPU_MODEL_WESTMERE_EX
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "Ivy Bridge",           // 0x3a
+  "",
+  "Haswell",              // 0x3c "4th Generation Intel Core Processor"
+  "",                     // 0x3d "Next Generation Intel Core Processor"
+  "Ivy Bridge-EP",        // 0x3e "Next Generation Intel Xeon Processor E7 Family"
+  "",                     // 0x3f "Future Generation Intel Xeon Processor"
+  "",
+  "",
+  "",
+  "",
+  "",
+  "Haswell",              // 0x45 "4th Generation Intel Core Processor"
+  "Haswell",              // 0x46 "4th Generation Intel Core Processor"
+  NULL
+};
+
+/* Brand ID is for back compability
+ * Newer CPUs uses the extended brand string */
+const char* const VM_Version_Ext::_brand_id[] = {
+  "",
+  "Celeron processor",
+  "Pentium III processor",
+  "Intel Pentium III Xeon processor",
+  "",
+  "",
+  "",
+  "",
+  "Intel Pentium 4 processor",
+  NULL
+};
+
+
+const char* const VM_Version_Ext::_feature_edx_id[] = {
+  "On-Chip FPU",
+  "Virtual Mode Extensions",
+  "Debugging Extensions",
+  "Page Size Extensions",
+  "Time Stamp Counter",
+  "Model Specific Registers",
+  "Physical Address Extension",
+  "Machine Check Exceptions",
+  "CMPXCHG8B Instruction",
+  "On-Chip APIC",
+  "",
+  "Fast System Call",
+  "Memory Type Range Registers",
+  "Page Global Enable",
+  "Machine Check Architecture",
+  "Conditional Mov Instruction",
+  "Page Attribute Table",
+  "36-bit Page Size Extension",
+  "Processor Serial Number",
+  "CLFLUSH Instruction",
+  "",
+  "Debug Trace Store feature",
+  "ACPI registers in MSR space",
+  "Intel Architecture MMX Technology",
+  "Fast Float Point Save and Restore",
+  "Streaming SIMD extensions",
+  "Streaming SIMD extensions 2",
+  "Self-Snoop",
+  "Hyper Threading",
+  "Thermal Monitor",
+  "",
+  "Pending Break Enable"
+};
+
+const char* const VM_Version_Ext::_feature_extended_edx_id[] = {
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "SYSCALL/SYSRET",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "Execute Disable Bit",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "RDTSCP",
+  "",
+  "Intel 64 Architecture",
+  "",
+  ""
+};
+
+const char* const VM_Version_Ext::_feature_ecx_id[] = {
+  "Streaming SIMD Extensions 3",
+  "PCLMULQDQ",
+  "64-bit DS Area",
+  "MONITOR/MWAIT instructions",
+  "CPL Qualified Debug Store",
+  "Virtual Machine Extensions",
+  "Safer Mode Extensions",
+  "Enhanced Intel SpeedStep technology",
+  "Thermal Monitor 2",
+  "Supplemental Streaming SIMD Extensions 3",
+  "L1 Context ID",
+  "",
+  "Fused Multiply-Add",
+  "CMPXCHG16B",
+  "xTPR Update Control",
+  "Perfmon and Debug Capability",
+  "",
+  "Process-context identifiers",
+  "Direct Cache Access",
+  "Streaming SIMD extensions 4.1",
+  "Streaming SIMD extensions 4.2",
+  "x2APIC",
+  "MOVBE",
+  "Popcount instruction",
+  "TSC-Deadline",
+  "AESNI",
+  "XSAVE",
+  "OSXSAVE",
+  "AVX",
+  "F16C",
+  "RDRAND",
+  ""
+};
+
+const char* const VM_Version_Ext::_feature_extended_ecx_id[] = {
+  "LAHF/SAHF instruction support",
+  "Core multi-processor leagacy mode",
+  "",
+  "",
+  "",
+  "Advanced Bit Manipulations: LZCNT",
+  "SSE4A: MOVNTSS, MOVNTSD, EXTRQ, INSERTQ",
+  "Misaligned SSE mode",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  "",
+  ""
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/cpu/x86/vm_version_ext_x86.hpp	Wed May 16 09:45:40 2018 -0700
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2013, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef CPU_X86_VM_VM_VERSION_EXT_X86_HPP
+#define CPU_X86_VM_VM_VERSION_EXT_X86_HPP
+
+#include "utilities/macros.hpp"
+#include "vm_version_x86.hpp"
+
+class VM_Version_Ext : public VM_Version {
+ private:
+  static const size_t      VENDOR_LENGTH;
+  static const size_t      CPU_EBS_MAX_LENGTH;
+  static const size_t      CPU_TYPE_DESC_BUF_SIZE;
+  static const size_t      CPU_DETAILED_DESC_BUF_SIZE;
+
+  static const char* const _family_id_intel[];
+  static const char* const _family_id_amd[];
+  static const char* const _brand_id[];
+  static const char* const _model_id_pentium_pro[];
+
+  static const char* const _feature_edx_id[];
+  static const char* const _feature_extended_edx_id[];
+  static const char* const _feature_ecx_id[];
+  static const char* const _feature_extended_ecx_id[];
+
+  static int               _no_of_threads;
+  static int               _no_of_cores;
+  static int               _no_of_packages;
+  static char*             _cpu_brand_string;
+  static jlong             _max_qualified_cpu_frequency;
+
+  static const char* cpu_family_description(void);
+  static const char* cpu_model_description(void);
+  static const char* cpu_brand(void);
+  static const char* cpu_brand_string(void);
+
+  static int cpu_type_description(char* const buf, size_t buf_len);
+  static int cpu_detailed_description(char* const buf, size_t buf_len);
+  static int cpu_extended_brand_string(char* const buf, size_t buf_len);
+
+  static bool cpu_is_em64t(void);
+  static bool is_netburst(void);
+
+  static size_t cpu_write_support_string(char* const buf, size_t buf_len);
+  static void resolve_cpu_information_details(void);
+  static jlong max_qualified_cpu_freq_from_brand_string(void);
+
+ public:
+  // Offsets for cpuid asm stub brand string
+  static ByteSize proc_name_0_offset() { return byte_offset_of(CpuidInfo, proc_name_0); }
+  static ByteSize proc_name_1_offset() { return byte_offset_of(CpuidInfo, proc_name_1); }
+  static ByteSize proc_name_2_offset() { return byte_offset_of(CpuidInfo, proc_name_2); }
+  static ByteSize proc_name_3_offset() { return byte_offset_of(CpuidInfo, proc_name_3); }
+  static ByteSize proc_name_4_offset() { return byte_offset_of(CpuidInfo, proc_name_4); }
+  static ByteSize proc_name_5_offset() { return byte_offset_of(CpuidInfo, proc_name_5); }
+  static ByteSize proc_name_6_offset() { return byte_offset_of(CpuidInfo, proc_name_6); }
+  static ByteSize proc_name_7_offset() { return byte_offset_of(CpuidInfo, proc_name_7); }
+  static ByteSize proc_name_8_offset() { return byte_offset_of(CpuidInfo, proc_name_8); }
+  static ByteSize proc_name_9_offset() { return byte_offset_of(CpuidInfo, proc_name_9); }
+  static ByteSize proc_name_10_offset() { return byte_offset_of(CpuidInfo, proc_name_10); }
+  static ByteSize proc_name_11_offset() { return byte_offset_of(CpuidInfo, proc_name_11); }
+
+  static int number_of_threads(void);
+  static int number_of_cores(void);
+  static int number_of_sockets(void);
+
+  static jlong maximum_qualified_cpu_frequency(void);
+
+  static bool supports_tscinv_ext(void);
+
+  static const char* cpu_name(void);
+  static const char* cpu_description(void);
+
+  static void initialize();
+};
+
+#endif // CPU_X86_VM_VM_VERSION_EXT_X86_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/os/bsd/os_perf_bsd.cpp	Wed May 16 09:45:40 2018 -0700
@@ -0,0 +1,405 @@
+/*
+ * Copyright (c) 2012, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+#include "precompiled.hpp"
+#include "memory/allocation.inline.hpp"
+#include "memory/resourceArea.hpp"
+#include "runtime/os.hpp"
+#include "runtime/os_perf.hpp"
+#include "vm_version_ext_x86.hpp"
+
+#ifdef __APPLE__
+  #import <libproc.h>
+  #include <sys/time.h>
+  #include <sys/sysctl.h>
+  #include <mach/mach.h>
+  #include <mach/task_info.h>
+#endif
+
+static const double NANOS_PER_SEC = 1000000000.0;
+
+class CPUPerformanceInterface::CPUPerformance : public CHeapObj<mtInternal> {
+   friend class CPUPerformanceInterface;
+ private:
+  long _total_cpu_nanos;
+  long _total_csr_nanos;
+  long _jvm_user_nanos;
+  long _jvm_system_nanos;
+  long _jvm_context_switches;
+  long _used_ticks;
+  long _total_ticks;
+  int  _active_processor_count;
+
+  bool now_in_nanos(long* resultp) {
+    timeval current_time;
+    if (gettimeofday(&current_time, NULL) != 0) {
+      // Error getting current time
+      return false;
+    }
+    *resultp = current_time.tv_sec * NANOS_PER_SEC + 1000L * current_time.tv_usec;
+    return true;
+  }
+
+  double normalize(double value) {
+    return MIN2<double>(MAX2<double>(value, 0.0), 1.0);
+  }
+  int cpu_load(int which_logical_cpu, double* cpu_load);
+  int context_switch_rate(double* rate);
+  int cpu_load_total_process(double* cpu_load);
+  int cpu_loads_process(double* pjvmUserLoad, double* pjvmKernelLoad, double* psystemTotalLoad);
+
+  CPUPerformance(const CPUPerformance& rhs); // no impl
+  CPUPerformance& operator=(const CPUPerformance& rhs); // no impl
+ public:
+  CPUPerformance();
+  bool initialize();
+  ~CPUPerformance();
+};
+
+CPUPerformanceInterface::CPUPerformance::CPUPerformance() {
+  _total_cpu_nanos= 0;
+  _total_csr_nanos= 0;
+  _jvm_context_switches = 0;
+  _jvm_user_nanos = 0;
+  _jvm_system_nanos = 0;
+  _used_ticks = 0;
+  _total_ticks = 0;
+  _active_processor_count = 0;
+}
+
+bool CPUPerformanceInterface::CPUPerformance::initialize() {
+  return true;
+}
+
+CPUPerformanceInterface::CPUPerformance::~CPUPerformance() {
+}
+
+int CPUPerformanceInterface::CPUPerformance::cpu_load(int which_logical_cpu, double* cpu_load) {
+  return FUNCTIONALITY_NOT_IMPLEMENTED;
+}
+
+int CPUPerformanceInterface::CPUPerformance::cpu_load_total_process(double* cpu_load) {
+#ifdef __APPLE__
+  host_name_port_t host = mach_host_self();
+  host_flavor_t flavor = HOST_CPU_LOAD_INFO;
+  mach_msg_type_number_t host_info_count = HOST_CPU_LOAD_INFO_COUNT;
+  host_cpu_load_info_data_t cpu_load_info;
+
+  kern_return_t kr = host_statistics(host, flavor, (host_info_t)&cpu_load_info, &host_info_count);
+  if (kr != KERN_SUCCESS) {
+    return OS_ERR;
+  }
+
+  long used_ticks  = cpu_load_info.cpu_ticks[CPU_STATE_USER] + cpu_load_info.cpu_ticks[CPU_STATE_NICE] + cpu_load_info.cpu_ticks[CPU_STATE_SYSTEM];
+  long total_ticks = used_ticks + cpu_load_info.cpu_ticks[CPU_STATE_IDLE];
+
+  if (_used_ticks == 0 || _total_ticks == 0) {
+    // First call, just set the values
+    _used_ticks  = used_ticks;
+    _total_ticks = total_ticks;
+    return OS_ERR;
+  }
+
+  long used_delta  = used_ticks - _used_ticks;
+  long total_delta = total_ticks - _total_ticks;
+
+  _used_ticks  = used_ticks;
+  _total_ticks = total_ticks;
+
+  if (total_delta == 0) {
+    // Avoid division by zero
+    return OS_ERR;
+  }
+
+  *cpu_load = (double)used_delta / total_delta;
+
+  return OS_OK;
+#else
+  return FUNCTIONALITY_NOT_IMPLEMENTED;
+#endif
+}
+
+int CPUPerformanceInterface::CPUPerformance::cpu_loads_process(double* pjvmUserLoad, double* pjvmKernelLoad, double* psystemTotalLoad) {
+#ifdef __APPLE__
+  int result = cpu_load_total_process(psystemTotalLoad);
+  mach_port_t task = mach_task_self();
+  mach_msg_type_number_t task_info_count = TASK_INFO_MAX;
+  task_info_data_t task_info_data;
+  kern_return_t kr = task_info(task, TASK_ABSOLUTETIME_INFO, (task_info_t)task_info_data, &task_info_count);
+  if (kr != KERN_SUCCESS) {
+    return OS_ERR;
+  }
+  task_absolutetime_info_t absolutetime_info = (task_absolutetime_info_t)task_info_data;
+
+  int active_processor_count = os::active_processor_count();
+  long jvm_user_nanos = absolutetime_info->total_user;
+  long jvm_system_nanos = absolutetime_info->total_system;
+
+  long total_cpu_nanos;
+  if(!now_in_nanos(&total_cpu_nanos)) {
+    return OS_ERR;
+  }
+
+  if (_total_cpu_nanos == 0 || active_processor_count != _active_processor_count) {
+    // First call or change in active processor count
+    result = OS_ERR;
+  }
+
+  long delta_nanos = active_processor_count * (total_cpu_nanos - _total_cpu_nanos);
+  if (delta_nanos == 0) {
+    // Avoid division by zero
+    return OS_ERR;
+  }
+
+  *pjvmUserLoad = normalize((double)(jvm_user_nanos - _jvm_user_nanos)/delta_nanos);
+  *pjvmKernelLoad = normalize((double)(jvm_system_nanos - _jvm_system_nanos)/delta_nanos);
+
+  _active_processor_count = active_processor_count;
+  _total_cpu_nanos = total_cpu_nanos;
+  _jvm_user_nanos = jvm_user_nanos;
+  _jvm_system_nanos = jvm_system_nanos;
+
+  return result;
+#else
+  return FUNCTIONALITY_NOT_IMPLEMENTED;
+#endif
+}
+
+int CPUPerformanceInterface::CPUPerformance::context_switch_rate(double* rate) {
+#ifdef __APPLE__
+  mach_port_t task = mach_task_self();
+  mach_msg_type_number_t task_info_count = TASK_INFO_MAX;
+  task_info_data_t task_info_data;
+  kern_return_t kr = task_info(task, TASK_EVENTS_INFO, (task_info_t)task_info_data, &task_info_count);
+  if (kr != KERN_SUCCESS) {
+    return OS_ERR;
+  }
+
+  int result = OS_OK;
+  if (_total_csr_nanos == 0 || _jvm_context_switches == 0) {
+    // First call just set initial values.
+    result = OS_ERR;
+  }
+
+  long jvm_context_switches = ((task_events_info_t)task_info_data)->csw;
+
+  long total_csr_nanos;
+  if(!now_in_nanos(&total_csr_nanos)) {
+    return OS_ERR;
+  }
+  double delta_in_sec = (double)(total_csr_nanos - _total_csr_nanos) / NANOS_PER_SEC;
+  if (delta_in_sec == 0.0) {
+    // Avoid division by zero
+    return OS_ERR;
+  }
+
+  *rate = (jvm_context_switches - _jvm_context_switches) / delta_in_sec;
+
+  _jvm_context_switches = jvm_context_switches;
+  _total_csr_nanos = total_csr_nanos;
+
+  return result;
+#else
+  return FUNCTIONALITY_NOT_IMPLEMENTED;
+#endif
+}
+
+CPUPerformanceInterface::CPUPerformanceInterface() {
+  _impl = NULL;
+}
+
+bool CPUPerformanceInterface::initialize() {
+  _impl = new CPUPerformanceInterface::CPUPerformance();
+  return _impl != NULL && _impl->initialize();
+}
+
+CPUPerformanceInterface::~CPUPerformanceInterface() {
+  if (_impl != NULL) {
+    delete _impl;
+  }
+}
+
+int CPUPerformanceInterface::cpu_load(int which_logical_cpu, double* cpu_load) const {
+  return _impl->cpu_load(which_logical_cpu, cpu_load);
+}
+
+int CPUPerformanceInterface::cpu_load_total_process(double* cpu_load) const {
+  return _impl->cpu_load_total_process(cpu_load);
+}
+
+int CPUPerformanceInterface::cpu_loads_process(double* pjvmUserLoad, double* pjvmKernelLoad, double* psystemTotalLoad) const {
+  return _impl->cpu_loads_process(pjvmUserLoad, pjvmKernelLoad, psystemTotalLoad);
+}
+
+int CPUPerformanceInterface::context_switch_rate(double* rate) const {
+  return _impl->context_switch_rate(rate);
+}
+
+class SystemProcessInterface::SystemProcesses : public CHeapObj<mtInternal> {
+  friend class SystemProcessInterface;
+ private:
+  SystemProcesses();
+  bool initialize();
+  SystemProcesses(const SystemProcesses& rhs); // no impl
+  SystemProcesses& operator=(const SystemProcesses& rhs); // no impl
+  ~SystemProcesses();
+
+  //information about system processes
+  int system_processes(SystemProcess** system_processes, int* no_of_sys_processes) const;
+};
+
+SystemProcessInterface::SystemProcesses::SystemProcesses() {
+}
+
+bool SystemProcessInterface::SystemProcesses::initialize() {
+  return true;
+}
+
+SystemProcessInterface::SystemProcesses::~SystemProcesses() {
+}
+int SystemProcessInterface::SystemProcesses::system_processes(SystemProcess** system_processes, int* no_of_sys_processes) const {
+  assert(system_processes != NULL, "system_processes pointer is NULL!");
+  assert(no_of_sys_processes != NULL, "system_processes counter pointer is NULL!");
+#ifdef __APPLE__
+  pid_t* pids = NULL;
+  int pid_count = 0;
+  ResourceMark rm;
+
+  int try_count = 0;
+  while (pids == NULL) {
+    // Find out buffer size
+    size_t pids_bytes = proc_listpids(PROC_ALL_PIDS, 0, NULL, 0);
+    if (pids_bytes <= 0) {
+      return OS_ERR;
+    }
+    pid_count = pids_bytes / sizeof(pid_t);
+    pids = NEW_RESOURCE_ARRAY(pid_t, pid_count);
+    memset(pids, 0, pids_bytes);
+
+    pids_bytes = proc_listpids(PROC_ALL_PIDS, 0, pids, pids_bytes);
+    if (pids_bytes <= 0) {
+       // couldn't fit buffer, retry.
+      FREE_RESOURCE_ARRAY(pid_t, pids, pid_count);
+      pids = NULL;
+      try_count++;
+      if (try_count > 3) {
+      return OS_ERR;
+      }
+    } else {
+      pid_count = pids_bytes / sizeof(pid_t);
+    }
+  }
+
+  int process_count = 0;
+  SystemProcess* next = NULL;
+  for (int i = 0; i < pid_count; i++) {
+    pid_t pid = pids[i];
+    if (pid != 0) {
+      char buffer[PROC_PIDPATHINFO_MAXSIZE];
+      memset(buffer, 0 , sizeof(buffer));
+      if (proc_pidpath(pid, buffer, sizeof(buffer)) != -1) {
+        int length = strlen(buffer);
+        if (length > 0) {
+          SystemProcess* current = new SystemProcess();
+          char * path = NEW_C_HEAP_ARRAY(char, length + 1, mtInternal);
+          strcpy(path, buffer);
+          current->set_path(path);
+          current->set_pid((int)pid);
+          current->set_next(next);
+          next = current;
+          process_count++;
+        }
+      }
+    }
+  }
+
+  *no_of_sys_processes = process_count;
+  *system_processes = next;
+
+  return OS_OK;
+#endif
+  return FUNCTIONALITY_NOT_IMPLEMENTED;
+}
+
+int SystemProcessInterface::system_processes(SystemProcess** system_procs, int* no_of_sys_processes) const {
+  return _impl->system_processes(system_procs, no_of_sys_processes);
+}
+
+SystemProcessInterface::SystemProcessInterface() {
+  _impl = NULL;
+}
+
+bool SystemProcessInterface::initialize() {
+  _impl = new SystemProcessInterface::SystemProcesses();
+  return _impl != NULL && _impl->initialize();
+}
+
+SystemProcessInterface::~SystemProcessInterface() {
+  if (_impl != NULL) {
+    delete _impl;
+ }
+}
+
+CPUInformationInterface::CPUInformationInterface() {
+  _cpu_info = NULL;
+}
+
+bool CPUInformationInterface::initialize() {
+  _cpu_info = new CPUInformation();
+
+  if (NULL == _cpu_info) {
+    return false;
+  }
+  _cpu_info->set_number_of_hardware_threads(VM_Version_Ext::number_of_threads());
+  _cpu_info->set_number_of_cores(VM_Version_Ext::number_of_cores());
+  _cpu_info->set_number_of_sockets(VM_Version_Ext::number_of_sockets());
+  _cpu_info->set_cpu_name(VM_Version_Ext::cpu_name());
+  _cpu_info->set_cpu_description(VM_Version_Ext::cpu_description());
+
+  return true;
+}
+
+CPUInformationInterface::~CPUInformationInterface() {
+  if (_cpu_info != NULL) {
+    if (_cpu_info->cpu_name() != NULL) {
+      const char* cpu_name = _cpu_info->cpu_name();
+      FREE_C_HEAP_ARRAY(char, cpu_name);
+      _cpu_info->set_cpu_name(NULL);
+    }
+    if (_cpu_info->cpu_description() != NULL) {
+      const char* cpu_desc = _cpu_info->cpu_description();
+      FREE_C_HEAP_ARRAY(char, cpu_desc);
+      _cpu_info->set_cpu_description(NULL);
+    }
+    delete _cpu_info;
+  }
+}
+
+int CPUInformationInterface::cpu_information(CPUInformation& cpu_info) {
+  if (NULL == _cpu_info) {
+    return OS_ERR;
+  }
+
+  cpu_info = *_cpu_info; // shallow copy assignment
+  return OS_OK;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/os/linux/os_perf_linux.cpp	Wed May 16 09:45:40 2018 -0700
@@ -0,0 +1,1060 @@
+/*
+ * Copyright (c) 2012, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "jvm.h"
+#include "memory/allocation.inline.hpp"
+#include "os_linux.inline.hpp"
+#include "runtime/os.hpp"
+#include "runtime/os_perf.hpp"
+
+#ifdef X86
+#include "vm_version_ext_x86.hpp"
+#endif
+#ifdef ARM
+#include "vm_version_ext_arm.hpp"
+#endif
+#ifndef ARM
+#ifdef AARCH64
+#include "vm_version_ext_aarch64.hpp"
+#endif
+#endif
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <sys/resource.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <stdlib.h>
+#include <dlfcn.h>
+#include <pthread.h>
+#include <limits.h>
+
+/**
+   /proc/[number]/stat
+              Status information about the process.  This is used by ps(1).  It is defined in /usr/src/linux/fs/proc/array.c.
+
+              The fields, in order, with their proper scanf(3) format specifiers, are:
+
+              1. pid %d The process id.
+
+              2. comm %s
+                     The filename of the executable, in parentheses.  This is visible whether or not the executable is swapped out.
+
+              3. state %c
+                     One  character  from  the  string "RSDZTW" where R is running, S is sleeping in an interruptible wait, D is waiting in uninterruptible disk
+                     sleep, Z is zombie, T is traced or stopped (on a signal), and W is paging.
+
+              4. ppid %d
+                     The PID of the parent.
+
+              5. pgrp %d
+                     The process group ID of the process.
+
+              6. session %d
+                     The session ID of the process.
+
+              7. tty_nr %d
+                     The tty the process uses.
+
+              8. tpgid %d
+                     The process group ID of the process which currently owns the tty that the process is connected to.
+
+              9. flags %lu
+                     The flags of the process.  The math bit is decimal 4, and the traced bit is decimal 10.
+
+              10. minflt %lu
+                     The number of minor faults the process has made which have not required loading a memory page from disk.
+
+              11. cminflt %lu
+                     The number of minor faults that the process's waited-for children have made.
+
+              12. majflt %lu
+                     The number of major faults the process has made which have required loading a memory page from disk.
+
+              13. cmajflt %lu
+                     The number of major faults that the process's waited-for children have made.
+
+              14. utime %lu
+                     The number of jiffies that this process has been scheduled in user mode.
+
+              15. stime %lu
+                     The number of jiffies that this process has been scheduled in kernel mode.
+
+              16. cutime %ld
+                     The number of jiffies that this process's waited-for children have been scheduled in user mode. (See also times(2).)
+
+              17. cstime %ld
+                     The number of jiffies that this process' waited-for children have been scheduled in kernel mode.
+
+              18. priority %ld
+                     The standard nice value, plus fifteen.  The value is never negative in the kernel.
+
+              19. nice %ld
+                     The nice value ranges from 19 (nicest) to -19 (not nice to others).
+
+              20. 0 %ld  This value is hard coded to 0 as a placeholder for a removed field.
+
+              21. itrealvalue %ld
+                     The time in jiffies before the next SIGALRM is sent to the process due to an interval timer.
+
+              22. starttime %lu
+                     The time in jiffies the process started after system boot.
+
+              23. vsize %lu
+                     Virtual memory size in bytes.
+
+              24. rss %ld
+                     Resident Set Size: number of pages the process has in real memory, minus 3 for administrative purposes. This is just the pages which  count
+                     towards text, data, or stack space.  This does not include pages which have not been demand-loaded in, or which are swapped out.
+
+              25. rlim %lu
+                     Current limit in bytes on the rss of the process (usually 4294967295 on i386).
+
+              26. startcode %lu
+                     The address above which program text can run.
+
+              27. endcode %lu
+                     The address below which program text can run.
+
+              28. startstack %lu
+                     The address of the start of the stack.
+
+              29. kstkesp %lu
+                     The current value of esp (stack pointer), as found in the kernel stack page for the process.
+
+              30. kstkeip %lu
+                     The current EIP (instruction pointer).
+
+              31. signal %lu
+                     The bitmap of pending signals (usually 0).
+
+              32. blocked %lu
+                     The bitmap of blocked signals (usually 0, 2 for shells).
+
+              33. sigignore %lu
+                     The bitmap of ignored signals.
+
+              34. sigcatch %lu
+                     The bitmap of catched signals.
+
+              35. wchan %lu
+                     This  is the "channel" in which the process is waiting.  It is the address of a system call, and can be looked up in a namelist if you need
+                     a textual name.  (If you have an up-to-date /etc/psdatabase, then try ps -l to see the WCHAN field in action.)
+
+              36. nswap %lu
+                     Number of pages swapped - not maintained.
+
+              37. cnswap %lu
+                     Cumulative nswap for child processes.
+
+              38. exit_signal %d
+                     Signal to be sent to parent when we die.
+
+              39. processor %d
+                     CPU number last executed on.
+
+
+
+ ///// SSCANF FORMAT STRING. Copy and use.
+
+field:        1  2  3  4  5  6  7  8  9   10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38 39
+format:       %d %s %c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu %ld %ld %ld %ld %ld %ld %lu %lu %ld %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %d %d
+
+
+*/
+
+/**
+ * For platforms that have them, when declaring
+ * a printf-style function,
+ *   formatSpec is the parameter number (starting at 1)
+ *       that is the format argument ("%d pid %s")
+ *   params is the parameter number where the actual args to
+ *       the format starts. If the args are in a va_list, this
+ *       should be 0.
+ */
+#ifndef PRINTF_ARGS
+#  define PRINTF_ARGS(formatSpec,  params) ATTRIBUTE_PRINTF(formatSpec, params)
+#endif
+
+#ifndef SCANF_ARGS
+#  define SCANF_ARGS(formatSpec,   params) ATTRIBUTE_SCANF(formatSpec, params)
+#endif
+
+#ifndef _PRINTFMT_
+#  define _PRINTFMT_
+#endif
+
+#ifndef _SCANFMT_
+#  define _SCANFMT_
+#endif
+
+
+struct CPUPerfTicks {
+  uint64_t  used;
+  uint64_t  usedKernel;
+  uint64_t  total;
+};
+
+typedef enum {
+  CPU_LOAD_VM_ONLY,
+  CPU_LOAD_GLOBAL,
+} CpuLoadTarget;
+
+enum {
+  UNDETECTED,
+  UNDETECTABLE,
+  LINUX26_NPTL,
+  BAREMETAL
+};
+
+struct CPUPerfCounters {
+  int   nProcs;
+  CPUPerfTicks jvmTicks;
+  CPUPerfTicks* cpus;
+};
+
+static double get_cpu_load(int which_logical_cpu, CPUPerfCounters* counters, double* pkernelLoad, CpuLoadTarget target);
+
+/** reads /proc/<pid>/stat data, with some checks and some skips.
+ *  Ensure that 'fmt' does _NOT_ contain the first two "%d %s"
+ */
+static int SCANF_ARGS(2, 0) vread_statdata(const char* procfile, _SCANFMT_ const char* fmt, va_list args) {
+  FILE*f;
+  int n;
+  char buf[2048];
+
+  if ((f = fopen(procfile, "r")) == NULL) {
+    return -1;
+  }
+
+  if ((n = fread(buf, 1, sizeof(buf), f)) != -1) {
+    char *tmp;
+
+    buf[n-1] = '\0';
+    /** skip through pid and exec name. */
+    if ((tmp = strrchr(buf, ')')) != NULL) {
+      // skip the ')' and the following space
+      // but check that buffer is long enough
+      tmp += 2;
+      if (tmp < buf + n) {
+        n = vsscanf(tmp, fmt, args);
+      }
+    }
+  }
+
+  fclose(f);
+
+  return n;
+}
+
+static int SCANF_ARGS(2, 3) read_statdata(const char* procfile, _SCANFMT_ const char* fmt, ...) {
+  int   n;
+  va_list args;
+
+  va_start(args, fmt);
+  n = vread_statdata(procfile, fmt, args);
+  va_end(args);
+  return n;
+}
+
+static FILE* open_statfile(void) {
+  FILE *f;
+
+  if ((f = fopen("/proc/stat", "r")) == NULL) {
+    static int haveWarned = 0;
+    if (!haveWarned) {
+      haveWarned = 1;
+    }
+  }
+  return f;
+}
+
+static void
+next_line(FILE *f) {
+  int c;
+  do {
+    c = fgetc(f);
+  } while (c != '\n' && c != EOF);
+}
+
+/**
+ * Return the total number of ticks since the system was booted.
+ * If the usedTicks parameter is not NULL, it will be filled with
+ * the number of ticks spent on actual processes (user, system or
+ * nice processes) since system boot. Note that this is the total number
+ * of "executed" ticks on _all_ CPU:s, that is on a n-way system it is
+ * n times the number of ticks that has passed in clock time.
+ *
+ * Returns a negative value if the reading of the ticks failed.
+ */
+static OSReturn get_total_ticks(int which_logical_cpu, CPUPerfTicks* pticks) {
+  FILE*         fh;
+  uint64_t      userTicks, niceTicks, systemTicks, idleTicks;
+  uint64_t      iowTicks = 0, irqTicks = 0, sirqTicks= 0;
+  int           logical_cpu = -1;
+  const int     expected_assign_count = (-1 == which_logical_cpu) ? 4 : 5;
+  int           n;
+
+  if ((fh = open_statfile()) == NULL) {
+    return OS_ERR;
+  }
+  if (-1 == which_logical_cpu) {
+    n = fscanf(fh, "cpu " UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT " "
+            UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT,
+            &userTicks, &niceTicks, &systemTicks, &idleTicks,
+            &iowTicks, &irqTicks, &sirqTicks);
+  } else {
+    // Move to next line
+    next_line(fh);
+
+    // find the line for requested cpu faster to just iterate linefeeds?
+    for (int i = 0; i < which_logical_cpu; i++) {
+      next_line(fh);
+    }
+
+    n = fscanf(fh, "cpu%u " UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT " "
+               UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT,
+               &logical_cpu, &userTicks, &niceTicks,
+               &systemTicks, &idleTicks, &iowTicks, &irqTicks, &sirqTicks);
+  }
+
+  fclose(fh);
+  if (n < expected_assign_count || logical_cpu != which_logical_cpu) {
+#ifdef DEBUG_LINUX_PROC_STAT
+    vm_fprintf(stderr, "[stat] read failed");
+#endif
+    return OS_ERR;
+  }
+
+#ifdef DEBUG_LINUX_PROC_STAT
+  vm_fprintf(stderr, "[stat] read "
+          UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT " "
+          UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT " \n",
+          userTicks, niceTicks, systemTicks, idleTicks,
+          iowTicks, irqTicks, sirqTicks);
+#endif
+
+  pticks->used       = userTicks + niceTicks;
+  pticks->usedKernel = systemTicks + irqTicks + sirqTicks;
+  pticks->total      = userTicks + niceTicks + systemTicks + idleTicks +
+                       iowTicks + irqTicks + sirqTicks;
+
+  return OS_OK;
+}
+
+
+static int get_systemtype(void) {
+  static int procEntriesType = UNDETECTED;
+  DIR *taskDir;
+
+  if (procEntriesType != UNDETECTED) {
+    return procEntriesType;
+  }
+
+  // Check whether we have a task subdirectory
+  if ((taskDir = opendir("/proc/self/task")) == NULL) {
+    procEntriesType = UNDETECTABLE;
+  } else {
+    // The task subdirectory exists; we're on a Linux >= 2.6 system
+    closedir(taskDir);
+    procEntriesType = LINUX26_NPTL;
+  }
+
+  return procEntriesType;
+}
+
+/** read user and system ticks from a named procfile, assumed to be in 'stat' format then. */
+static int read_ticks(const char* procfile, uint64_t* userTicks, uint64_t* systemTicks) {
+  return read_statdata(procfile, "%*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u " UINT64_FORMAT " " UINT64_FORMAT,
+    userTicks, systemTicks);
+}
+
+/**
+ * Return the number of ticks spent in any of the processes belonging
+ * to the JVM on any CPU.
+ */
+static OSReturn get_jvm_ticks(CPUPerfTicks* pticks) {
+  uint64_t userTicks;
+  uint64_t systemTicks;
+
+  if (get_systemtype() != LINUX26_NPTL) {
+    return OS_ERR;
+  }
+
+  if (read_ticks("/proc/self/stat", &userTicks, &systemTicks) != 2) {
+    return OS_ERR;
+  }
+
+  // get the total
+  if (get_total_ticks(-1, pticks) != OS_OK) {
+    return OS_ERR;
+  }
+
+  pticks->used       = userTicks;
+  pticks->usedKernel = systemTicks;
+
+  return OS_OK;
+}
+
+/**
+ * Return the load of the CPU as a double. 1.0 means the CPU process uses all
+ * available time for user or system processes, 0.0 means the CPU uses all time
+ * being idle.
+ *
+ * Returns a negative value if there is a problem in determining the CPU load.
+ */
+static double get_cpu_load(int which_logical_cpu, CPUPerfCounters* counters, double* pkernelLoad, CpuLoadTarget target) {
+  uint64_t udiff, kdiff, tdiff;
+  CPUPerfTicks* pticks;
+  CPUPerfTicks  tmp;
+  double user_load;
+
+  *pkernelLoad = 0.0;
+
+  if (target == CPU_LOAD_VM_ONLY) {
+    pticks = &counters->jvmTicks;
+  } else if (-1 == which_logical_cpu) {
+    pticks = &counters->cpus[counters->nProcs];
+  } else {
+    pticks = &counters->cpus[which_logical_cpu];
+  }
+
+  tmp = *pticks;
+
+  if (target == CPU_LOAD_VM_ONLY) {
+    if (get_jvm_ticks(pticks) != OS_OK) {
+      return -1.0;
+    }
+  } else if (get_total_ticks(which_logical_cpu, pticks) != OS_OK) {
+    return -1.0;
+  }
+
+  // seems like we sometimes end up with less kernel ticks when
+  // reading /proc/self/stat a second time, timing issue between cpus?
+  if (pticks->usedKernel < tmp.usedKernel) {
+    kdiff = 0;
+  } else {
+    kdiff = pticks->usedKernel - tmp.usedKernel;
+  }
+  tdiff = pticks->total - tmp.total;
+  udiff = pticks->used - tmp.used;
+
+  if (tdiff == 0) {
+    return 0.0;
+  } else if (tdiff < (udiff + kdiff)) {
+    tdiff = udiff + kdiff;
+  }
+  *pkernelLoad = (kdiff / (double)tdiff);
+  // BUG9044876, normalize return values to sane values
+  *pkernelLoad = MAX2<double>(*pkernelLoad, 0.0);
+  *pkernelLoad = MIN2<double>(*pkernelLoad, 1.0);
+
+  user_load = (udiff / (double)tdiff);
+  user_load = MAX2<double>(user_load, 0.0);
+  user_load = MIN2<double>(user_load, 1.0);
+
+  return user_load;
+}
+
+static int SCANF_ARGS(1, 2) parse_stat(_SCANFMT_ const char* fmt, ...) {
+  FILE *f;
+  va_list args;
+
+  va_start(args, fmt);
+
+  if ((f = open_statfile()) == NULL) {
+    va_end(args);
+    return OS_ERR;
+  }
+  for (;;) {
+    char line[80];
+    if (fgets(line, sizeof(line), f) != NULL) {
+      if (vsscanf(line, fmt, args) == 1) {
+        fclose(f);
+        va_end(args);
+        return OS_OK;
+      }
+    } else {
+        fclose(f);
+        va_end(args);
+        return OS_ERR;
+    }
+  }
+}
+
+static int get_noof_context_switches(uint64_t* switches) {
+  return parse_stat("ctxt " UINT64_FORMAT "\n", switches);
+}
+
+/** returns boot time in _seconds_ since epoch */
+static int get_boot_time(uint64_t* time) {
+  return parse_stat("btime " UINT64_FORMAT "\n", time);
+}
+
+static int perf_context_switch_rate(double* rate) {
+  static pthread_mutex_t contextSwitchLock = PTHREAD_MUTEX_INITIALIZER;
+  static uint64_t      lastTime;
+  static uint64_t      lastSwitches;
+  static double        lastRate;
+
+  uint64_t lt = 0;
+  int res = 0;
+
+  if (lastTime == 0) {
+    uint64_t tmp;
+    if (get_boot_time(&tmp) < 0) {
+      return OS_ERR;
+    }
+    lt = tmp * 1000;
+  }
+
+  res = OS_OK;
+
+  pthread_mutex_lock(&contextSwitchLock);
+  {
+
+    uint64_t sw;
+    s8 t, d;
+
+    if (lastTime == 0) {
+      lastTime = lt;
+    }
+
+    t = os::javaTimeMillis();
+    d = t - lastTime;
+
+    if (d == 0) {
+      *rate = lastRate;
+    } else if (!get_noof_context_switches(&sw)) {
+      *rate      = ( (double)(sw - lastSwitches) / d ) * 1000;
+      lastRate     = *rate;
+      lastSwitches = sw;
+      lastTime     = t;
+    } else {
+      *rate = 0;
+      res   = OS_ERR;
+    }
+    if (*rate <= 0) {
+      *rate = 0;
+      lastRate = 0;
+    }
+  }
+  pthread_mutex_unlock(&contextSwitchLock);
+
+  return res;
+}
+
+class CPUPerformanceInterface::CPUPerformance : public CHeapObj<mtInternal> {
+  friend class CPUPerformanceInterface;
+ private:
+  CPUPerfCounters _counters;
+
+  int cpu_load(int which_logical_cpu, double* cpu_load);
+  int context_switch_rate(double* rate);
+  int cpu_load_total_process(double* cpu_load);
+  int cpu_loads_process(double* pjvmUserLoad, double* pjvmKernelLoad, double* psystemTotalLoad);
+
+ public:
+  CPUPerformance();
+  bool initialize();
+  ~CPUPerformance();
+};
+
+CPUPerformanceInterface::CPUPerformance::CPUPerformance() {
+  _counters.nProcs = os::active_processor_count();
+  _counters.cpus = NULL;
+}
+
+bool CPUPerformanceInterface::CPUPerformance::initialize() {
+  size_t tick_array_size = (_counters.nProcs +1) * sizeof(CPUPerfTicks);
+  _counters.cpus = (CPUPerfTicks*)NEW_C_HEAP_ARRAY(char, tick_array_size, mtInternal);
+  if (NULL == _counters.cpus) {
+    return false;
+  }
+  memset(_counters.cpus, 0, tick_array_size);
+
+  // For the CPU load total
+  get_total_ticks(-1, &_counters.cpus[_counters.nProcs]);
+
+  // For each CPU
+  for (int i = 0; i < _counters.nProcs; i++) {
+    get_total_ticks(i, &_counters.cpus[i]);
+  }
+  // For JVM load
+  get_jvm_ticks(&_counters.jvmTicks);
+
+  // initialize context switch system
+  // the double is only for init
+  double init_ctx_switch_rate;
+  perf_context_switch_rate(&init_ctx_switch_rate);
+
+  return true;
+}
+
+CPUPerformanceInterface::CPUPerformance::~CPUPerformance() {
+  if (_counters.cpus != NULL) {
+    FREE_C_HEAP_ARRAY(char, _counters.cpus);
+  }
+}
+
+int CPUPerformanceInterface::CPUPerformance::cpu_load(int which_logical_cpu, double* cpu_load) {
+  double u, s;
+  u = get_cpu_load(which_logical_cpu, &_counters, &s, CPU_LOAD_GLOBAL);
+  if (u < 0) {
+    *cpu_load = 0.0;
+    return OS_ERR;
+  }
+  // Cap total systemload to 1.0
+  *cpu_load = MIN2<double>((u + s), 1.0);
+  return OS_OK;
+}
+
+int CPUPerformanceInterface::CPUPerformance::cpu_load_total_process(double* cpu_load) {
+  double u, s;
+  u = get_cpu_load(-1, &_counters, &s, CPU_LOAD_VM_ONLY);
+  if (u < 0) {
+    *cpu_load = 0.0;
+    return OS_ERR;
+  }
+  *cpu_load = u + s;
+  return OS_OK;
+}
+
+int CPUPerformanceInterface::CPUPerformance::cpu_loads_process(double* pjvmUserLoad, double* pjvmKernelLoad, double* psystemTotalLoad) {
+  double u, s, t;
+
+  assert(pjvmUserLoad != NULL, "pjvmUserLoad not inited");
+  assert(pjvmKernelLoad != NULL, "pjvmKernelLoad not inited");
+  assert(psystemTotalLoad != NULL, "psystemTotalLoad not inited");
+
+  u = get_cpu_load(-1, &_counters, &s, CPU_LOAD_VM_ONLY);
+  if (u < 0) {
+    *pjvmUserLoad = 0.0;
+    *pjvmKernelLoad = 0.0;
+    *psystemTotalLoad = 0.0;
+    return OS_ERR;
+  }
+
+  cpu_load(-1, &t);
+  // clamp at user+system and 1.0
+  if (u + s > t) {
+    t = MIN2<double>(u + s, 1.0);
+  }
+
+  *pjvmUserLoad = u;
+  *pjvmKernelLoad = s;
+  *psystemTotalLoad = t;
+
+  return OS_OK;
+}
+
+int CPUPerformanceInterface::CPUPerformance::context_switch_rate(double* rate) {
+  return perf_context_switch_rate(rate);
+}
+
+CPUPerformanceInterface::CPUPerformanceInterface() {
+  _impl = NULL;
+}
+
+bool CPUPerformanceInterface::initialize() {
+  _impl = new CPUPerformanceInterface::CPUPerformance();
+  return NULL == _impl ? false : _impl->initialize();
+}
+
+CPUPerformanceInterface::~CPUPerformanceInterface() {
+  if (_impl != NULL) {
+    delete _impl;
+  }
+}
+
+int CPUPerformanceInterface::cpu_load(int which_logical_cpu, double* cpu_load) const {
+  return _impl->cpu_load(which_logical_cpu, cpu_load);
+}
+
+int CPUPerformanceInterface::cpu_load_total_process(double* cpu_load) const {
+  return _impl->cpu_load_total_process(cpu_load);
+}
+
+int CPUPerformanceInterface::cpu_loads_process(double* pjvmUserLoad, double* pjvmKernelLoad, double* psystemTotalLoad) const {
+  return _impl->cpu_loads_process(pjvmUserLoad, pjvmKernelLoad, psystemTotalLoad);
+}
+
+int CPUPerformanceInterface::context_switch_rate(double* rate) const {
+  return _impl->context_switch_rate(rate);
+}
+
+class SystemProcessInterface::SystemProcesses : public CHeapObj<mtInternal> {
+  friend class SystemProcessInterface;
+ private:
+  class ProcessIterator : public CHeapObj<mtInternal> {
+    friend class SystemProcessInterface::SystemProcesses;
+   private:
+    DIR*           _dir;
+    struct dirent* _entry;
+    bool           _valid;
+    char           _exeName[PATH_MAX];
+    char           _exePath[PATH_MAX];
+
+    ProcessIterator();
+    ~ProcessIterator();
+    bool initialize();
+
+    bool is_valid() const { return _valid; }
+    bool is_valid_entry(struct dirent* entry) const;
+    bool is_dir(const char* name) const;
+    int  fsize(const char* name, uint64_t& size) const;
+
+    char* allocate_string(const char* str) const;
+    void  get_exe_name();
+    char* get_exe_path();
+    char* get_cmdline();
+
+    int current(SystemProcess* process_info);
+    int next_process();
+  };
+
+  ProcessIterator* _iterator;
+  SystemProcesses();
+  bool initialize();
+  ~SystemProcesses();
+
+  //information about system processes
+  int system_processes(SystemProcess** system_processes, int* no_of_sys_processes) const;
+};
+
+bool SystemProcessInterface::SystemProcesses::ProcessIterator::is_dir(const char* name) const {
+  struct stat mystat;
+  int ret_val = 0;
+
+  ret_val = stat(name, &mystat);
+  if (ret_val < 0) {
+    return false;
+  }
+  ret_val = S_ISDIR(mystat.st_mode);
+  return ret_val > 0;
+}
+
+int SystemProcessInterface::SystemProcesses::ProcessIterator::fsize(const char* name, uint64_t& size) const {
+  assert(name != NULL, "name pointer is NULL!");
+  size = 0;
+  struct stat fbuf;
+
+  if (stat(name, &fbuf) < 0) {
+    return OS_ERR;
+  }
+  size = fbuf.st_size;
+  return OS_OK;
+}
+
+// if it has a numeric name, is a directory and has a 'stat' file in it
+bool SystemProcessInterface::SystemProcesses::ProcessIterator::is_valid_entry(struct dirent* entry) const {
+  char buffer[PATH_MAX];
+  uint64_t size = 0;
+
+  if (atoi(entry->d_name) != 0) {
+    jio_snprintf(buffer, PATH_MAX, "/proc/%s", entry->d_name);
+    buffer[PATH_MAX - 1] = '\0';
+
+    if (is_dir(buffer)) {
+      jio_snprintf(buffer, PATH_MAX, "/proc/%s/stat", entry->d_name);
+      buffer[PATH_MAX - 1] = '\0';
+      if (fsize(buffer, size) != OS_ERR) {
+        return true;
+      }
+    }
+  }
+  return false;
+}
+
+// get exe-name from /proc/<pid>/stat
+void SystemProcessInterface::SystemProcesses::ProcessIterator::get_exe_name() {
+  FILE* fp;
+  char  buffer[PATH_MAX];
+
+  jio_snprintf(buffer, PATH_MAX, "/proc/%s/stat", _entry->d_name);
+  buffer[PATH_MAX - 1] = '\0';
+  if ((fp = fopen(buffer, "r")) != NULL) {
+    if (fgets(buffer, PATH_MAX, fp) != NULL) {
+      char* start, *end;
+      // exe-name is between the first pair of ( and )
+      start = strchr(buffer, '(');
+      if (start != NULL && start[1] != '\0') {
+        start++;
+        end = strrchr(start, ')');
+        if (end != NULL) {
+          size_t len;
+          len = MIN2<size_t>(end - start, sizeof(_exeName) - 1);
+          memcpy(_exeName, start, len);
+          _exeName[len] = '\0';
+        }
+      }
+    }
+    fclose(fp);
+  }
+}
+
+// get command line from /proc/<pid>/cmdline
+char* SystemProcessInterface::SystemProcesses::ProcessIterator::get_cmdline() {
+  FILE* fp;
+  char  buffer[PATH_MAX];
+  char* cmdline = NULL;
+
+  jio_snprintf(buffer, PATH_MAX, "/proc/%s/cmdline", _entry->d_name);
+  buffer[PATH_MAX - 1] = '\0';
+  if ((fp = fopen(buffer, "r")) != NULL) {
+    size_t size = 0;
+    char   dummy;
+
+    // find out how long the file is (stat always returns 0)
+    while (fread(&dummy, 1, 1, fp) == 1) {
+      size++;
+    }
+    if (size > 0) {
+      cmdline = NEW_C_HEAP_ARRAY(char, size + 1, mtInternal);
+      if (cmdline != NULL) {
+        cmdline[0] = '\0';
+        if (fseek(fp, 0, SEEK_SET) == 0) {
+          if (fread(cmdline, 1, size, fp) == size) {
+            // the file has the arguments separated by '\0',
+            // so we translate '\0' to ' '
+            for (size_t i = 0; i < size; i++) {
+              if (cmdline[i] == '\0') {
+                cmdline[i] = ' ';
+              }
+            }
+            cmdline[size] = '\0';
+          }
+        }
+      }
+    }
+    fclose(fp);
+  }
+  return cmdline;
+}
+
+// get full path to exe from /proc/<pid>/exe symlink
+char* SystemProcessInterface::SystemProcesses::ProcessIterator::get_exe_path() {
+  char buffer[PATH_MAX];
+
+  jio_snprintf(buffer, PATH_MAX, "/proc/%s/exe", _entry->d_name);
+  buffer[PATH_MAX - 1] = '\0';
+  return realpath(buffer, _exePath);
+}
+
+char* SystemProcessInterface::SystemProcesses::ProcessIterator::allocate_string(const char* str) const {
+  if (str != NULL) {
+    size_t len = strlen(str);
+    char* tmp = NEW_C_HEAP_ARRAY(char, len+1, mtInternal);
+    strncpy(tmp, str, len);
+    tmp[len] = '\0';
+    return tmp;
+  }
+  return NULL;
+}
+
+int SystemProcessInterface::SystemProcesses::ProcessIterator::current(SystemProcess* process_info) {
+  if (!is_valid()) {
+    return OS_ERR;
+  }
+
+  process_info->set_pid(atoi(_entry->d_name));
+
+  get_exe_name();
+  process_info->set_name(allocate_string(_exeName));
+
+  if (get_exe_path() != NULL) {
+     process_info->set_path(allocate_string(_exePath));
+  }
+
+  char* cmdline = NULL;
+  cmdline = get_cmdline();
+  if (cmdline != NULL) {
+    process_info->set_command_line(allocate_string(cmdline));
+    FREE_C_HEAP_ARRAY(char, cmdline);
+  }
+
+  return OS_OK;
+}
+
+int SystemProcessInterface::SystemProcesses::ProcessIterator::next_process() {
+  struct dirent* entry;
+
+  if (!is_valid()) {
+    return OS_ERR;
+  }
+
+  do {
+      entry = os::readdir(_dir, _entry);
+    if (entry == NULL) {
+      // error
+      _valid = false;
+      return OS_ERR;
+    }
+    if (_entry == NULL) {
+      // reached end
+      _valid = false;
+      return OS_ERR;
+    }
+  } while(!is_valid_entry(_entry));
+
+  _valid = true;
+  return OS_OK;
+}
+
+SystemProcessInterface::SystemProcesses::ProcessIterator::ProcessIterator() {
+  _dir = NULL;
+  _entry = NULL;
+  _valid = false;
+}
+
+bool SystemProcessInterface::SystemProcesses::ProcessIterator::initialize() {
+  _dir = opendir("/proc");
+  _entry = (struct dirent*)NEW_C_HEAP_ARRAY(char, sizeof(struct dirent) + NAME_MAX + 1, mtInternal);
+  if (NULL == _entry) {
+    return false;
+  }
+  _valid = true;
+  next_process();
+
+  return true;
+}
+
+SystemProcessInterface::SystemProcesses::ProcessIterator::~ProcessIterator() {
+  if (_entry != NULL) {
+    FREE_C_HEAP_ARRAY(char, _entry);
+  }
+  if (_dir != NULL) {
+    closedir(_dir);
+  }
+}
+
+SystemProcessInterface::SystemProcesses::SystemProcesses() {
+  _iterator = NULL;
+}
+
+bool SystemProcessInterface::SystemProcesses::initialize() {
+  _iterator = new SystemProcessInterface::SystemProcesses::ProcessIterator();
+  return NULL == _iterator ? false : _iterator->initialize();
+}
+
+SystemProcessInterface::SystemProcesses::~SystemProcesses() {
+  if (_iterator != NULL) {
+    delete _iterator;
+  }
+}
+
+int SystemProcessInterface::SystemProcesses::system_processes(SystemProcess** system_processes, int* no_of_sys_processes) const {
+  assert(system_processes != NULL, "system_processes pointer is NULL!");
+  assert(no_of_sys_processes != NULL, "system_processes counter pointers is NULL!");
+  assert(_iterator != NULL, "iterator is NULL!");
+
+  // initialize pointers
+  *no_of_sys_processes = 0;
+  *system_processes = NULL;
+
+  while (_iterator->is_valid()) {
+    SystemProcess* tmp = new SystemProcess();
+    _iterator->current(tmp);
+
+    //if already existing head
+    if (*system_processes != NULL) {
+      //move "first to second"
+      tmp->set_next(*system_processes);
+    }
+    // new head
+    *system_processes = tmp;
+    // increment
+    (*no_of_sys_processes)++;
+    // step forward
+    _iterator->next_process();
+  }
+  return OS_OK;
+}
+
+int SystemProcessInterface::system_processes(SystemProcess** system_procs, int* no_of_sys_processes) const {
+  return _impl->system_processes(system_procs, no_of_sys_processes);
+}
+
+SystemProcessInterface::SystemProcessInterface() {
+  _impl = NULL;
+}
+
+bool SystemProcessInterface::initialize() {
+  _impl = new SystemProcessInterface::SystemProcesses();
+  return NULL == _impl ? false : _impl->initialize();
+}
+
+SystemProcessInterface::~SystemProcessInterface() {
+  if (_impl != NULL) {
+    delete _impl;
+  }
+}
+
+CPUInformationInterface::CPUInformationInterface() {
+  _cpu_info = NULL;
+}
+
+bool CPUInformationInterface::initialize() {
+  _cpu_info = new CPUInformation();
+  if (NULL == _cpu_info) {
+    return false;
+  }
+  _cpu_info->set_number_of_hardware_threads(VM_Version_Ext::number_of_threads());
+  _cpu_info->set_number_of_cores(VM_Version_Ext::number_of_cores());
+  _cpu_info->set_number_of_sockets(VM_Version_Ext::number_of_sockets());
+  _cpu_info->set_cpu_name(VM_Version_Ext::cpu_name());
+  _cpu_info->set_cpu_description(VM_Version_Ext::cpu_description());
+
+  return true;
+}
+
+CPUInformationInterface::~CPUInformationInterface() {
+  if (_cpu_info != NULL) {
+    if (_cpu_info->cpu_name() != NULL) {
+      const char* cpu_name = _cpu_info->cpu_name();
+      FREE_C_HEAP_ARRAY(char, cpu_name);
+      _cpu_info->set_cpu_name(NULL);
+    }
+    if (_cpu_info->cpu_description() != NULL) {
+       const char* cpu_desc = _cpu_info->cpu_description();
+       FREE_C_HEAP_ARRAY(char, cpu_desc);
+      _cpu_info->set_cpu_description(NULL);
+    }
+    delete _cpu_info;
+  }
+}
+
+int CPUInformationInterface::cpu_information(CPUInformation& cpu_info) {
+  if (_cpu_info == NULL) {
+    return OS_ERR;
+  }
+
+  cpu_info = *_cpu_info; // shallow copy assignment
+  return OS_OK;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/os/solaris/os_perf_solaris.cpp	Wed May 16 09:45:40 2018 -0700
@@ -0,0 +1,756 @@
+/*
+ * Copyright (c) 2012, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "jvm.h"
+#include "memory/allocation.inline.hpp"
+#include "runtime/os.hpp"
+#include "runtime/os_perf.hpp"
+#include "os_solaris.inline.hpp"
+#include "utilities/macros.hpp"
+
+#include CPU_HEADER(vm_version_ext)
+
+#include <sys/types.h>
+#include <procfs.h>
+#include <dirent.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <strings.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <kstat.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/sysinfo.h>
+#include <sys/lwp.h>
+#include <pthread.h>
+#include <time.h>
+#include <utmpx.h>
+#include <dlfcn.h>
+#include <sys/loadavg.h>
+#include <limits.h>
+
+static const double NANOS_PER_SEC = 1000000000.0;
+
+struct CPUPerfTicks {
+  kstat_t* kstat;
+  uint64_t last_idle;
+  uint64_t last_total;
+  double   last_ratio;
+};
+
+struct CPUPerfCounters {
+  int           nProcs;
+  CPUPerfTicks* jvmTicks;
+  kstat_ctl_t*  kstat_ctrl;
+};
+
+static int get_info(const char* path, void* info, size_t s, off_t o) {
+  assert(path != NULL, "path is NULL!");
+  assert(info != NULL, "info is NULL!");
+
+  int fd = -1;
+
+  if ((fd = open(path, O_RDONLY)) < 0) {
+    return OS_ERR;
+  }
+  if (pread(fd, info, s, o) != s) {
+    close(fd);
+    return OS_ERR;
+  }
+  close(fd);
+  return OS_OK;
+}
+
+static int get_psinfo2(void* info, size_t s, off_t o) {
+  return get_info("/proc/self/psinfo", info, s, o);
+}
+
+static int get_psinfo(psinfo_t* info) {
+  return get_psinfo2(info, sizeof(*info), 0);
+}
+
+static int get_psinfo(char* file, psinfo_t* info) {
+  assert(file != NULL, "file is NULL!");
+  assert(info != NULL, "info is NULL!");
+  return get_info(file, info, sizeof(*info), 0);
+}
+
+
+static int get_usage(prusage_t* usage) {
+  assert(usage != NULL, "usage is NULL!");
+  return get_info("/proc/self/usage", usage, sizeof(*usage), 0);
+}
+
+static int read_cpustat(kstat_ctl_t* kstat_ctrl, CPUPerfTicks* load, cpu_stat_t* cpu_stat) {
+  assert(kstat_ctrl != NULL, "kstat_ctrl pointer is NULL!");
+  assert(load != NULL, "load pointer is NULL!");
+  assert(cpu_stat != NULL, "cpu_stat pointer is NULL!");
+
+  if (load->kstat == NULL) {
+    // no handle.
+    return OS_ERR;
+  }
+  if (kstat_read(kstat_ctrl, load->kstat, cpu_stat) == OS_ERR) {
+    // disable handle for this CPU
+     load->kstat = NULL;
+     return OS_ERR;
+  }
+  return OS_OK;
+}
+
+static double get_cpu_load(int which_logical_cpu, CPUPerfCounters* counters) {
+  assert(counters != NULL, "counters pointer is NULL!");
+
+  cpu_stat_t  cpu_stat = {0};
+
+  if (which_logical_cpu >= counters->nProcs) {
+    return .0;
+  }
+
+  CPUPerfTicks load = counters->jvmTicks[which_logical_cpu];
+  if (read_cpustat(counters->kstat_ctrl, &load, &cpu_stat) != OS_OK) {
+    return .0;
+  }
+
+  uint_t* usage = cpu_stat.cpu_sysinfo.cpu;
+  if (usage == NULL) {
+    return .0;
+  }
+
+  uint64_t c_idle  = usage[CPU_IDLE];
+  uint64_t c_total = 0;
+
+  for (int i = 0; i < CPU_STATES; i++) {
+    c_total += usage[i];
+  }
+
+  // Calculate diff against previous snapshot
+  uint64_t d_idle  = c_idle - load.last_idle;
+  uint64_t d_total = c_total - load.last_total;
+
+  /** update if weve moved */
+  if (d_total > 0) {
+    // Save current values for next time around
+    load.last_idle  = c_idle;
+    load.last_total = c_total;
+    load.last_ratio = (double) (d_total - d_idle) / d_total;
+  }
+
+  return load.last_ratio;
+}
+
+static int get_boot_time(uint64_t* time) {
+  assert(time != NULL, "time pointer is NULL!");
+  setutxent();
+  for(;;) {
+    struct utmpx* u;
+    if ((u = getutxent()) == NULL) {
+      break;
+    }
+    if (u->ut_type == BOOT_TIME) {
+      *time = u->ut_xtime;
+      endutxent();
+      return OS_OK;
+    }
+  }
+  endutxent();
+  return OS_ERR;
+}
+
+static int get_noof_context_switches(CPUPerfCounters* counters, uint64_t* switches) {
+  assert(switches != NULL, "switches pointer is NULL!");
+  assert(counters != NULL, "counter pointer is NULL!");
+  *switches = 0;
+  uint64_t s = 0;
+
+  // Collect data from all CPUs
+  for (int i = 0; i < counters->nProcs; i++) {
+    cpu_stat_t cpu_stat = {0};
+    CPUPerfTicks load = counters->jvmTicks[i];
+
+    if (read_cpustat(counters->kstat_ctrl, &load, &cpu_stat) == OS_OK) {
+      s += cpu_stat.cpu_sysinfo.pswitch;
+    } else {
+      //fail fast...
+      return OS_ERR;
+    }
+  }
+  *switches = s;
+  return OS_OK;
+}
+
+static int perf_context_switch_rate(CPUPerfCounters* counters, double* rate) {
+  assert(counters != NULL, "counters is NULL!");
+  assert(rate != NULL, "rate pointer is NULL!");
+  static pthread_mutex_t contextSwitchLock = PTHREAD_MUTEX_INITIALIZER;
+  static uint64_t lastTime = 0;
+  static uint64_t lastSwitches = 0;
+  static double   lastRate = 0.0;
+
+  uint64_t lt = 0;
+  int res = 0;
+
+  if (lastTime == 0) {
+    uint64_t tmp;
+    if (get_boot_time(&tmp) < 0) {
+      return OS_ERR;
+    }
+    lt = tmp * 1000;
+  }
+
+  res = OS_OK;
+
+  pthread_mutex_lock(&contextSwitchLock);
+  {
+
+    uint64_t sw = 0;
+    clock_t t, d;
+
+    if (lastTime == 0) {
+      lastTime = lt;
+    }
+
+    t = clock();
+    d = t - lastTime;
+
+    if (d == 0) {
+      *rate = lastRate;
+    } else if (get_noof_context_switches(counters, &sw)== OS_OK) {
+      *rate      = ((double)(sw - lastSwitches) / d) * 1000;
+      lastRate     = *rate;
+      lastSwitches = sw;
+      lastTime     = t;
+    } else {
+      *rate = 0.0;
+      res   = OS_ERR;
+    }
+    if (*rate < 0.0) {
+      *rate = 0.0;
+      lastRate = 0.0;
+    }
+  }
+  pthread_mutex_unlock(&contextSwitchLock);
+  return res;
+ }
+
+
+
+class CPUPerformanceInterface::CPUPerformance : public CHeapObj<mtInternal> {
+   friend class CPUPerformanceInterface;
+ private:
+  CPUPerfCounters _counters;
+  int cpu_load(int which_logical_cpu, double* cpu_load);
+  int context_switch_rate(double* rate);
+  int cpu_load_total_process(double* cpu_load);
+  int cpu_loads_process(double* pjvmUserLoad, double* pjvmKernelLoad, double* psystemTotalLoad);
+
+  CPUPerformance();
+  ~CPUPerformance();
+  bool initialize();
+};
+
+CPUPerformanceInterface::CPUPerformance::CPUPerformance() {
+  _counters.nProcs = 0;
+  _counters.jvmTicks = NULL;
+  _counters.kstat_ctrl = NULL;
+}
+
+bool CPUPerformanceInterface::CPUPerformance::initialize() {
+  // initialize kstat control structure,
+  _counters.kstat_ctrl = kstat_open();
+  assert(_counters.kstat_ctrl != NULL, "error initializing kstat control structure!");
+
+  if (NULL == _counters.kstat_ctrl) {
+    return false;
+  }
+
+  // Get number of CPU(s)
+  if ((_counters.nProcs = sysconf(_SC_NPROCESSORS_ONLN)) == OS_ERR) {
+    // ignore error?
+    _counters.nProcs = 1;
+  }
+
+  assert(_counters.nProcs > 0, "no CPUs detected in sysconf call!");
+  if (_counters.nProcs == 0) {
+    return false;
+  }
+
+  // Data structure(s) for saving CPU load (one per CPU)
+  size_t tick_array_size = _counters.nProcs * sizeof(CPUPerfTicks);
+  _counters.jvmTicks = (CPUPerfTicks*)NEW_C_HEAP_ARRAY(char, tick_array_size, mtInternal);
+  if (NULL == _counters.jvmTicks) {
+    return false;
+  }
+  memset(_counters.jvmTicks, 0, tick_array_size);
+
+  // Get kstat cpu_stat counters for every CPU
+  // loop over kstat to find our cpu_stat(s)
+  int i = 0;
+  for (kstat_t* kstat = _counters.kstat_ctrl->kc_chain; kstat != NULL; kstat = kstat->ks_next) {
+    if (strncmp(kstat->ks_module, "cpu_stat", 8) == 0) {
+      if (kstat_read(_counters.kstat_ctrl, kstat, NULL) == OS_ERR) {
+        continue;
+      }
+      if (i == _counters.nProcs) {
+        // more cpu_stats than reported CPUs
+        break;
+      }
+      _counters.jvmTicks[i++].kstat = kstat;
+    }
+  }
+  return true;
+}
+
+CPUPerformanceInterface::CPUPerformance::~CPUPerformance() {
+  if (_counters.jvmTicks != NULL) {
+    FREE_C_HEAP_ARRAY(char, _counters.jvmTicks);
+  }
+  if (_counters.kstat_ctrl != NULL) {
+    kstat_close(_counters.kstat_ctrl);
+  }
+}
+
+int CPUPerformanceInterface::CPUPerformance::cpu_load(int which_logical_cpu, double* cpu_load) {
+  assert(cpu_load != NULL, "cpu_load pointer is NULL!");
+  double t = .0;
+  if (-1 == which_logical_cpu) {
+    for (int i = 0; i < _counters.nProcs; i++) {
+      t += get_cpu_load(i, &_counters);
+    }
+    // Cap total systemload to 1.0
+    t = MIN2<double>((t / _counters.nProcs), 1.0);
+  } else {
+    t = MIN2<double>(get_cpu_load(which_logical_cpu, &_counters), 1.0);
+  }
+
+  *cpu_load = t;
+  return OS_OK;
+}
+
+int CPUPerformanceInterface::CPUPerformance::cpu_load_total_process(double* cpu_load) {
+  assert(cpu_load != NULL, "cpu_load pointer is NULL!");
+
+  psinfo_t info;
+
+  // Get the percentage of "recent cpu usage" from all the lwp:s in the JVM:s
+  // process. This is returned as a value between 0.0 and 1.0 multiplied by 0x8000.
+  if (get_psinfo2(&info.pr_pctcpu, sizeof(info.pr_pctcpu), offsetof(psinfo_t, pr_pctcpu)) != 0) {
+    *cpu_load = 0.0;
+    return OS_ERR;
+  }
+  *cpu_load = (double) info.pr_pctcpu / 0x8000;
+  return OS_OK;
+}
+
+int CPUPerformanceInterface::CPUPerformance::cpu_loads_process(double* pjvmUserLoad, double* pjvmKernelLoad, double* psystemTotalLoad) {
+  assert(pjvmUserLoad != NULL, "pjvmUserLoad not inited");
+  assert(pjvmKernelLoad != NULL, "pjvmKernelLoad not inited");
+  assert(psystemTotalLoad != NULL, "psystemTotalLoad not inited");
+
+  static uint64_t lastTime;
+  static uint64_t lastUser, lastKernel;
+  static double lastUserRes, lastKernelRes;
+
+  pstatus_t pss;
+  psinfo_t  info;
+
+  *pjvmKernelLoad = *pjvmUserLoad = *psystemTotalLoad = 0;
+  if (get_info("/proc/self/status", &pss.pr_utime, sizeof(timestruc_t)*2, offsetof(pstatus_t, pr_utime)) != 0) {
+    return OS_ERR;
+  }
+
+  if (get_psinfo(&info) != 0) {
+    return OS_ERR;
+  }
+
+  // get the total time in user, kernel and total time
+  // check ratios for 'lately' and multiply the 'recent load'.
+  uint64_t time   = (info.pr_time.tv_sec * NANOS_PER_SEC) + info.pr_time.tv_nsec;
+  uint64_t user   = (pss.pr_utime.tv_sec * NANOS_PER_SEC) + pss.pr_utime.tv_nsec;
+  uint64_t kernel = (pss.pr_stime.tv_sec * NANOS_PER_SEC) + pss.pr_stime.tv_nsec;
+  uint64_t diff   = time - lastTime;
+  double load     = (double) info.pr_pctcpu / 0x8000;
+
+  if (diff > 0) {
+    lastUserRes = (load * (user - lastUser)) / diff;
+    lastKernelRes = (load * (kernel - lastKernel)) / diff;
+
+    // BUG9182835 - patch for clamping these values to sane ones.
+    lastUserRes   = MIN2<double>(1, lastUserRes);
+    lastUserRes   = MAX2<double>(0, lastUserRes);
+    lastKernelRes = MIN2<double>(1, lastKernelRes);
+    lastKernelRes = MAX2<double>(0, lastKernelRes);
+  }
+
+  double t = .0;
+  cpu_load(-1, &t);
+  // clamp at user+system and 1.0
+  if (lastUserRes + lastKernelRes > t) {
+    t = MIN2<double>(lastUserRes + lastKernelRes, 1.0);
+  }
+
+  *pjvmUserLoad   = lastUserRes;
+  *pjvmKernelLoad = lastKernelRes;
+  *psystemTotalLoad = t;
+
+  lastTime   = time;
+  lastUser   = user;
+  lastKernel = kernel;
+
+  return OS_OK;
+}
+
+int CPUPerformanceInterface::CPUPerformance::context_switch_rate(double* rate) {
+  return perf_context_switch_rate(&_counters, rate);
+}
+
+CPUPerformanceInterface::CPUPerformanceInterface() {
+  _impl = NULL;
+}
+
+bool CPUPerformanceInterface::initialize() {
+  _impl = new CPUPerformanceInterface::CPUPerformance();
+  return _impl != NULL && _impl->initialize();
+}
+
+CPUPerformanceInterface::~CPUPerformanceInterface(void) {
+  if (_impl != NULL) {
+    delete _impl;
+  }
+}
+
+int CPUPerformanceInterface::cpu_load(int which_logical_cpu, double* cpu_load) const {
+  return _impl->cpu_load(which_logical_cpu, cpu_load);
+}
+
+int CPUPerformanceInterface::cpu_load_total_process(double* cpu_load) const {
+  return _impl->cpu_load_total_process(cpu_load);
+}
+
+int CPUPerformanceInterface::cpu_loads_process(double* pjvmUserLoad, double* pjvmKernelLoad, double* psystemTotalLoad) const {
+  return _impl->cpu_loads_process(pjvmUserLoad, pjvmKernelLoad, psystemTotalLoad);
+}
+
+int CPUPerformanceInterface::context_switch_rate(double* rate) const {
+  return _impl->context_switch_rate(rate);
+}
+
+class SystemProcessInterface::SystemProcesses : public CHeapObj<mtInternal> {
+  friend class SystemProcessInterface;
+ private:
+  class ProcessIterator : public CHeapObj<mtInternal> {
+    friend class SystemProcessInterface::SystemProcesses;
+   private:
+    DIR*           _dir;
+    struct dirent* _entry;
+    bool           _valid;
+
+    ProcessIterator();
+    ~ProcessIterator();
+    bool initialize();
+
+    bool is_valid() const { return _valid; }
+    bool is_valid_entry(struct dirent* const entry) const;
+    bool is_dir(const char* const name) const;
+    char* allocate_string(const char* const str) const;
+    int current(SystemProcess* const process_info);
+    int next_process();
+  };
+
+  ProcessIterator* _iterator;
+  SystemProcesses();
+  bool initialize();
+  ~SystemProcesses();
+
+  //information about system processes
+  int system_processes(SystemProcess** system_processes, int* no_of_sys_processes) const;
+};
+
+bool SystemProcessInterface::SystemProcesses::ProcessIterator::is_dir(const char* name) const {
+  struct stat64 mystat;
+  int ret_val = 0;
+
+  ret_val = ::stat64(name, &mystat);
+
+  if (ret_val < 0) {
+    return false;
+  }
+  ret_val = S_ISDIR(mystat.st_mode);
+  return ret_val > 0;
+}
+
+// if it has a numeric name, is a directory and has a 'psinfo' file in it
+bool SystemProcessInterface::SystemProcesses::ProcessIterator::is_valid_entry(struct dirent* entry) const {
+  // ignore the "." and ".." directories
+  if ((strcmp(entry->d_name, ".") == 0) ||
+      (strcmp(entry->d_name, "..") == 0)) {
+    return false;
+  }
+
+  char buffer[PATH_MAX] = {0};
+  uint64_t size = 0;
+  bool result = false;
+  FILE *fp = NULL;
+
+  if (atoi(entry->d_name) != 0) {
+    jio_snprintf(buffer, PATH_MAX, "/proc/%s", entry->d_name);
+
+    if (is_dir(buffer)) {
+      memset(buffer, 0, PATH_MAX);
+      jio_snprintf(buffer, PATH_MAX, "/proc/%s/psinfo", entry->d_name);
+      if ((fp = fopen(buffer, "r")) != NULL) {
+        int nread = 0;
+        psinfo_t psinfo_data;
+        if ((nread = fread(&psinfo_data, 1, sizeof(psinfo_t), fp)) != -1) {
+          // only considering system process owned by root
+          if (psinfo_data.pr_uid == 0) {
+            result = true;
+          }
+        }
+      }
+    }
+  }
+
+  if (fp != NULL) {
+    fclose(fp);
+  }
+
+  return result;
+}
+
+char* SystemProcessInterface::SystemProcesses::ProcessIterator::allocate_string(const char* str) const {
+  if (str != NULL) {
+    size_t len = strlen(str);
+    char* tmp = NEW_C_HEAP_ARRAY(char, len+1, mtInternal);
+    strncpy(tmp, str, len);
+    tmp[len] = '\0';
+    return tmp;
+  }
+  return NULL;
+}
+
+int SystemProcessInterface::SystemProcesses::ProcessIterator::current(SystemProcess* process_info) {
+  if (!is_valid()) {
+    return OS_ERR;
+  }
+
+  char psinfo_path[PATH_MAX] = {0};
+  jio_snprintf(psinfo_path, PATH_MAX, "/proc/%s/psinfo", _entry->d_name);
+
+  FILE *fp = NULL;
+  if ((fp = fopen(psinfo_path, "r")) == NULL) {
+    return OS_ERR;
+  }
+
+  int nread = 0;
+  psinfo_t psinfo_data;
+  if ((nread = fread(&psinfo_data, 1, sizeof(psinfo_t), fp)) == -1) {
+    fclose(fp);
+    return OS_ERR;
+  }
+
+  char *exe_path = NULL;
+  if ((psinfo_data.pr_fname != NULL) &&
+      (psinfo_data.pr_psargs != NULL)) {
+    char *path_substring = strstr(psinfo_data.pr_psargs, psinfo_data.pr_fname);
+    if (path_substring != NULL) {
+      int len = path_substring - psinfo_data.pr_psargs;
+      exe_path = NEW_C_HEAP_ARRAY(char, len+1, mtInternal);
+      if (exe_path != NULL) {
+        jio_snprintf(exe_path, len, "%s", psinfo_data.pr_psargs);
+        exe_path[len] = '\0';
+      }
+    }
+  }
+
+  process_info->set_pid(atoi(_entry->d_name));
+  process_info->set_name(allocate_string(psinfo_data.pr_fname));
+  process_info->set_path(allocate_string(exe_path));
+  process_info->set_command_line(allocate_string(psinfo_data.pr_psargs));
+
+  if (exe_path != NULL) {
+    FREE_C_HEAP_ARRAY(char, exe_path);
+  }
+
+  if (fp != NULL) {
+    fclose(fp);
+  }
+
+  return OS_OK;
+}
+
+int SystemProcessInterface::SystemProcesses::ProcessIterator::next_process() {
+  struct dirent* entry;
+
+  if (!is_valid()) {
+    return OS_ERR;
+  }
+
+  do {
+    if ((entry = os::readdir(_dir, _entry)) == NULL) {
+      // error
+      _valid = false;
+      return OS_ERR;
+    }
+  } while(!is_valid_entry(_entry));
+
+  _valid = true;
+  return OS_OK;
+}
+
+SystemProcessInterface::SystemProcesses::ProcessIterator::ProcessIterator() {
+  _dir = NULL;
+  _entry = NULL;
+  _valid = false;
+}
+
+bool SystemProcessInterface::SystemProcesses::ProcessIterator::initialize() {
+  _dir = opendir("/proc");
+  _entry = (struct dirent*)NEW_C_HEAP_ARRAY(char, sizeof(struct dirent) + _PC_NAME_MAX + 1, mtInternal);
+  if (NULL == _entry) {
+    return false;
+  }
+  _valid = true;
+  next_process();
+
+  return true;
+}
+
+SystemProcessInterface::SystemProcesses::ProcessIterator::~ProcessIterator() {
+  if (_entry != NULL) {
+    FREE_C_HEAP_ARRAY(char, _entry);
+  }
+
+  if (_dir != NULL) {
+    closedir(_dir);
+  }
+}
+
+SystemProcessInterface::SystemProcesses::SystemProcesses() {
+  _iterator = NULL;
+}
+
+bool SystemProcessInterface::SystemProcesses::initialize() {
+  _iterator = new SystemProcessInterface::SystemProcesses::ProcessIterator();
+  return _iterator != NULL && _iterator->initialize();
+}
+
+SystemProcessInterface::SystemProcesses::~SystemProcesses() {
+  if (_iterator != NULL) {
+    delete _iterator;
+  }
+}
+
+int SystemProcessInterface::SystemProcesses::system_processes(SystemProcess** system_processes, int* no_of_sys_processes) const {
+  assert(system_processes != NULL, "system_processes pointer is NULL!");
+  assert(no_of_sys_processes != NULL, "system_processes counter pointer is NULL!");
+  assert(_iterator != NULL, "iterator is NULL!");
+
+  // initialize pointers
+  *no_of_sys_processes = 0;
+  *system_processes = NULL;
+
+  while (_iterator->is_valid()) {
+    SystemProcess* tmp = new SystemProcess();
+    _iterator->current(tmp);
+
+    //if already existing head
+    if (*system_processes != NULL) {
+      //move "first to second"
+      tmp->set_next(*system_processes);
+    }
+    // new head
+    *system_processes = tmp;
+    // increment
+    (*no_of_sys_processes)++;
+    // step forward
+    _iterator->next_process();
+  }
+  return OS_OK;
+}
+
+int SystemProcessInterface::system_processes(SystemProcess** system_procs, int* no_of_sys_processes) const {
+  return _impl->system_processes(system_procs, no_of_sys_processes);
+}
+
+SystemProcessInterface::SystemProcessInterface() {
+  _impl = NULL;
+}
+
+bool SystemProcessInterface::initialize() {
+  _impl = new SystemProcessInterface::SystemProcesses();
+  return _impl != NULL && _impl->initialize();
+
+}
+
+SystemProcessInterface::~SystemProcessInterface() {
+  if (_impl != NULL) {
+    delete _impl;
+  }
+}
+
+CPUInformationInterface::CPUInformationInterface() {
+  _cpu_info = NULL;
+}
+
+bool CPUInformationInterface::initialize() {
+  _cpu_info = new CPUInformation();
+  if (_cpu_info == NULL) {
+    return false;
+  }
+  _cpu_info->set_number_of_hardware_threads(VM_Version_Ext::number_of_threads());
+  _cpu_info->set_number_of_cores(VM_Version_Ext::number_of_cores());
+  _cpu_info->set_number_of_sockets(VM_Version_Ext::number_of_sockets());
+  _cpu_info->set_cpu_name(VM_Version_Ext::cpu_name());
+  _cpu_info->set_cpu_description(VM_Version_Ext::cpu_description());
+  return true;
+}
+
+CPUInformationInterface::~CPUInformationInterface() {
+  if (_cpu_info != NULL) {
+    if (_cpu_info->cpu_name() != NULL) {
+      const char* cpu_name = _cpu_info->cpu_name();
+      FREE_C_HEAP_ARRAY(char, cpu_name);
+      _cpu_info->set_cpu_name(NULL);
+    }
+    if (_cpu_info->cpu_description() != NULL) {
+      const char* cpu_desc = _cpu_info->cpu_description();
+      FREE_C_HEAP_ARRAY(char, cpu_desc);
+      _cpu_info->set_cpu_description(NULL);
+    }
+    delete _cpu_info;
+  }
+}
+
+int CPUInformationInterface::cpu_information(CPUInformation& cpu_info) {
+  if (_cpu_info == NULL) {
+    return OS_ERR;
+  }
+
+  cpu_info = *_cpu_info; // shallow copy assignment
+  return OS_OK;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/os/windows/os_perf_windows.cpp	Wed May 16 09:45:40 2018 -0700
@@ -0,0 +1,1332 @@
+/*
+ * Copyright (c) 2012, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "logging/log.hpp"
+#include "memory/allocation.inline.hpp"
+#include "memory/resourceArea.hpp"
+#include "pdh_interface.hpp"
+#include "runtime/os_perf.hpp"
+#include "runtime/os.hpp"
+#include "vm_version_ext_x86.hpp"
+#include "utilities/macros.hpp"
+#include <math.h>
+#include <psapi.h>
+#include <TlHelp32.h>
+
+/*
+ * Windows provides a vast plethora of performance objects and counters,
+ * consumption of which is assisted using the Performance Data Helper (PDH) interface.
+ * We import a selected few api entry points from PDH, see pdh_interface.hpp.
+ *
+ * The code located in this file is to a large extent an abstraction over much of the
+ * plumbing needed to start consuming an object and/or counter of choice.
+ *
+ */
+
+ /*
+ * How to use:
+ * 1. Create query
+ * 2. Add counters to the query
+ * 3. Collect the performance data using the query
+ * 4. Display the performance data using the counters associated with the query
+ * 5. Destroy query (counter destruction implied)
+ */
+
+/*
+ * Every PDH artifact, like processor, process, thread, memory, and so forth are
+ * identified with an index that is always the same irrespective
+ * of the localized version of the operating system or service pack installed.
+ * INFO: Using PDH APIs Correctly in a Localized Language (Q287159)
+ *   http://support.microsoft.com/default.aspx?scid=kb;EN-US;q287159
+ *
+ * To find the correct index for an object or counter, inspect the registry key / value:
+ * [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009\Counter]
+ *
+ * some common PDH indexes
+ */
+static const DWORD PDH_PROCESSOR_IDX = 238;
+static const DWORD PDH_PROCESSOR_TIME_IDX = 6;
+static const DWORD PDH_PRIV_PROCESSOR_TIME_IDX = 144;
+static const DWORD PDH_PROCESS_IDX = 230;
+static const DWORD PDH_ID_PROCESS_IDX = 784;
+static const DWORD PDH_CONTEXT_SWITCH_RATE_IDX = 146;
+static const DWORD PDH_SYSTEM_IDX = 2;
+
+/* useful pdh fmt's */
+static const char* const OBJECT_COUNTER_FMT = "\\%s\\%s";
+static const size_t OBJECT_COUNTER_FMT_LEN = 2;
+static const char* const OBJECT_WITH_INSTANCES_COUNTER_FMT = "\\%s(%s)\\%s";
+static const size_t OBJECT_WITH_INSTANCES_COUNTER_FMT_LEN = 4;
+static const char* const PROCESS_OBJECT_INSTANCE_COUNTER_FMT = "\\%s(%s#%s)\\%s";
+static const size_t PROCESS_OBJECT_INSTANCE_COUNTER_FMT_LEN = 5;
+
+static const char* process_image_name = NULL; // for example, "java" but could have another image name
+static char* pdh_IDProcess_counter_fmt = NULL;   // "\Process(java#%d)\ID Process" */
+
+// Need to limit how often we update a query to minimize the heisenberg effect.
+// (PDH behaves erratically if the counters are queried too often, especially counters that
+// store and use values from two consecutive updates, like cpu load.)
+static const int min_update_interval_millis = 500;
+
+/*
+* Structs for PDH queries.
+*/
+typedef struct {
+  HQUERY query;
+  s8     lastUpdate; // Last time query was updated (current millis).
+} UpdateQueryS, *UpdateQueryP;
+
+
+typedef struct {
+  UpdateQueryS query;
+  HCOUNTER     counter;
+  bool         initialized;
+} CounterQueryS, *CounterQueryP;
+
+typedef struct {
+  UpdateQueryS query;
+  HCOUNTER*    counters;
+  int          noOfCounters;
+  bool         initialized;
+} MultiCounterQueryS, *MultiCounterQueryP;
+
+typedef struct {
+  MultiCounterQueryP queries;
+  int                size;
+  bool               initialized;
+} MultiCounterQuerySetS, *MultiCounterQuerySetP;
+
+static void pdh_cleanup(HQUERY* const query, HCOUNTER* const counter) {
+  if (counter != NULL && *counter != NULL) {
+    PdhDll::PdhRemoveCounter(*counter);
+    *counter = NULL;
+  }
+  if (query != NULL && *query != NULL) {
+    PdhDll::PdhCloseQuery(*query);
+    *query = NULL;
+  }
+}
+
+static CounterQueryP create_counter_query() {
+  CounterQueryP const query = NEW_C_HEAP_ARRAY(CounterQueryS, 1, mtInternal);
+  memset(query, 0, sizeof(CounterQueryS));
+  return query;
+}
+
+static void destroy_counter_query(CounterQueryP query) {
+  assert(query != NULL, "invariant");
+  pdh_cleanup(&query->query.query, &query->counter);
+  FREE_C_HEAP_ARRAY(CounterQueryS, query);
+}
+
+static MultiCounterQueryP create_multi_counter_query() {
+  MultiCounterQueryP const query = NEW_C_HEAP_ARRAY(MultiCounterQueryS, 1, mtInternal);
+  memset(query, 0, sizeof(MultiCounterQueryS));
+  return query;
+}
+
+static void destroy_counter_query(MultiCounterQueryP counter_query) {
+  if (counter_query != NULL) {
+    for (int i = 0; i < counter_query->noOfCounters; ++i) {
+      pdh_cleanup(NULL, &counter_query->counters[i]);
+    }
+    FREE_C_HEAP_ARRAY(char, counter_query->counters);
+    pdh_cleanup(&counter_query->query.query, NULL);
+    FREE_C_HEAP_ARRAY(MultiCounterQueryS, counter_query);
+  }
+}
+
+static void destroy_counter_query(MultiCounterQuerySetP counter_query_set) {
+  for (int i = 0; i < counter_query_set->size; i++) {
+    for (int j = 0; j < counter_query_set->queries[i].noOfCounters; ++j) {
+      pdh_cleanup(NULL, &counter_query_set->queries[i].counters[j]);
+    }
+    FREE_C_HEAP_ARRAY(char, counter_query_set->queries[i].counters);
+    pdh_cleanup(&counter_query_set->queries[i].query.query, NULL);
+  }
+  FREE_C_HEAP_ARRAY(MultiCounterQueryS, counter_query_set->queries);
+  FREE_C_HEAP_ARRAY(MultiCounterQuerySetS, counter_query_set);
+}
+
+static int open_query(HQUERY* query) {
+  return PdhDll::PdhOpenQuery(NULL, 0, query);
+}
+
+template <typename QueryP>
+static int open_query(QueryP query) {
+  return open_query(&query->query);
+}
+
+static int allocate_counters(MultiCounterQueryP query, size_t nofCounters) {
+  assert(query != NULL, "invariant");
+  assert(!query->initialized, "invariant");
+  assert(0 == query->noOfCounters, "invariant");
+  assert(query->counters == NULL, "invariant");
+  query->counters = (HCOUNTER*)NEW_C_HEAP_ARRAY(char, nofCounters * sizeof(HCOUNTER), mtInternal);
+  if (query->counters == NULL) {
+    return OS_ERR;
+  }
+  memset(query->counters, 0, nofCounters * sizeof(HCOUNTER));
+  query->noOfCounters = (int)nofCounters;
+  return OS_OK;
+}
+
+static int allocate_counters(MultiCounterQuerySetP query_set, size_t nofCounters) {
+  assert(query_set != NULL, "invariant");
+  assert(!query_set->initialized, "invariant");
+  for (int i = 0; i < query_set->size; ++i) {
+    if (allocate_counters(&query_set->queries[i], nofCounters) != OS_OK) {
+      return OS_ERR;
+    }
+  }
+  return OS_OK;
+}
+
+static void deallocate_counters(MultiCounterQueryP query) {
+  if (query->counters != NULL) {
+    FREE_C_HEAP_ARRAY(char, query->counters);
+    query->counters = NULL;
+    query->noOfCounters = 0;
+  }
+}
+
+static OSReturn add_counter(UpdateQueryP query, HCOUNTER* counter, const char* path, bool first_sample_on_init) {
+  assert(query != NULL, "invariant");
+  assert(counter != NULL, "invariant");
+  assert(path != NULL, "invariant");
+  if (query->query == NULL) {
+    if (open_query(query) != ERROR_SUCCESS) {
+      return OS_ERR;
+    }
+  }
+  assert(query->query != NULL, "invariant");
+  PDH_STATUS status = PdhDll::PdhAddCounter(query->query, path, 0, counter);
+  if (PDH_CSTATUS_NO_OBJECT == status || PDH_CSTATUS_NO_COUNTER == status) {
+    return OS_ERR;
+  }
+  /*
+  * According to the MSDN documentation, rate counters must be read twice:
+  *
+  * "Obtaining the value of rate counters such as Page faults/sec requires that
+  *  PdhCollectQueryData be called twice, with a specific time interval between
+  *  the two calls, before calling PdhGetFormattedCounterValue. Call Sleep to
+  *  implement the waiting period between the two calls to PdhCollectQueryData."
+  *
+  *  Take the first sample here already to allow for the next "real" sample
+  *  to succeed.
+  */
+  if (first_sample_on_init) {
+    PdhDll::PdhCollectQueryData(query->query);
+  }
+  return OS_OK;
+}
+
+template <typename QueryP>
+static OSReturn add_counter(QueryP counter_query, HCOUNTER* counter, const char* path, bool first_sample_on_init) {
+  assert(counter_query != NULL, "invariant");
+  assert(counter != NULL, "invariant");
+  assert(path != NULL, "invariant");
+  return add_counter(&counter_query->query, counter, path, first_sample_on_init);
+}
+
+static OSReturn add_counter(CounterQueryP counter_query, const char* path, bool first_sample_on_init) {
+  if (add_counter(counter_query, &counter_query->counter, path, first_sample_on_init) != OS_OK) {
+    // performance counter might be disabled in the registry
+    return OS_ERR;
+  }
+  counter_query->initialized = true;
+  return OS_OK;
+}
+
+static OSReturn add_process_counter(MultiCounterQueryP query, int slot_index, const char* path, bool first_sample_on_init) {
+  assert(query != NULL, "invariant");
+  assert(query != NULL, "invariant");
+  assert(slot_index < query->noOfCounters, "invariant");
+  assert(query->counters[slot_index] == NULL, "invariant");
+  const OSReturn ret = add_counter(query, &query->counters[slot_index], path, first_sample_on_init);
+  if (OS_OK == ret) {
+    if (slot_index + 1 == query->noOfCounters) {
+      query->initialized = true;
+    }
+  }
+  return ret;
+}
+
+static int collect_query_data(UpdateQueryP update_query) {
+  assert(update_query != NULL, "invariant");
+  const s8 now = os::javaTimeMillis();
+  if (now - update_query->lastUpdate > min_update_interval_millis) {
+    if (PdhDll::PdhCollectQueryData(update_query->query) != ERROR_SUCCESS) {
+      return OS_ERR;
+    }
+    update_query->lastUpdate = now;
+  }
+  return OS_OK;
+}
+
+template <typename Query>
+static int collect_query_data(Query* counter_query) {
+  assert(counter_query != NULL, "invariant");
+  return collect_query_data(&counter_query->query);
+}
+
+static int formatted_counter_value(HCOUNTER counter, DWORD format, PDH_FMT_COUNTERVALUE* const value) {
+  assert(value != NULL, "invariant");
+  if (PdhDll::PdhGetFormattedCounterValue(counter, format, NULL, value) != ERROR_SUCCESS) {
+    return OS_ERR;
+  }
+  return OS_OK;
+}
+
+/*
+* Working against the Process object and it's related counters is inherently problematic
+* when using the PDH API:
+*
+* Using PDH, a process is not primarily identified by the process id,
+* but with a sequential number, for example \Process(java#0), \Process(java#1), ...
+* The really bad part is that this list is reset as soon as a process exits:
+* If \Process(java#1) exits, \Process(java#3) now becomes \Process(java#2) etc.
+*
+* The PDH api requires a process identifier to be submitted when registering
+* a query, but as soon as the list resets, the query is invalidated (since the name changed).
+*
+* Solution:
+* The #number identifier for a Process query can only decrease after process creation.
+*
+* We therefore create an array of counter queries for all process object instances
+* up to and including ourselves:
+*
+* Ex. we come in as third process instance (java#2), we then create and register
+* queries for the following Process object instances:
+* java#0, java#1, java#2
+*
+* current_query_index_for_process() keeps track of the current "correct" query
+* (in order to keep this index valid when the list resets from underneath,
+* ensure to call current_query_index_for_process() before every query involving
+* Process object instance data).
+*/
+static int current_query_index_for_process() {
+  assert(process_image_name != NULL, "invariant");
+  assert(pdh_IDProcess_counter_fmt != NULL, "invariant");
+  HQUERY tmpQuery = NULL;
+  if (open_query(&tmpQuery) != ERROR_SUCCESS) {
+    return 0;
+  }
+  char counter[512];
+  HCOUNTER handle_counter = NULL;
+  // iterate over all instance indexes and try to find our own pid
+  for (int index = 0; index < max_intx; index++) {
+    jio_snprintf(counter, sizeof(counter) - 1, pdh_IDProcess_counter_fmt, index);
+    assert(strlen(counter) < sizeof(counter), "invariant");
+    if (PdhDll::PdhAddCounter(tmpQuery, counter, 0, &handle_counter) != ERROR_SUCCESS) {
+      pdh_cleanup(&tmpQuery, &handle_counter);
+      return 0;
+    }
+    const PDH_STATUS res = PdhDll::PdhCollectQueryData(tmpQuery);
+    if (res == PDH_INVALID_HANDLE || res == PDH_NO_DATA) {
+      pdh_cleanup(&tmpQuery, &handle_counter);
+      return 0;
+    } else {
+      PDH_FMT_COUNTERVALUE counter_value;
+      formatted_counter_value(handle_counter, PDH_FMT_LONG, &counter_value);
+      pdh_cleanup(NULL, &handle_counter);
+      if ((LONG)os::current_process_id() == counter_value.longValue) {
+        pdh_cleanup(&tmpQuery, NULL);
+        return index;
+      }
+    }
+  }
+  pdh_cleanup(&tmpQuery, NULL);
+  return 0;
+}
+
+static MultiCounterQuerySetP create_process_counter_query() {
+  MultiCounterQuerySetP const query = NEW_C_HEAP_ARRAY(MultiCounterQuerySetS, 1, mtInternal);
+  memset(query, 0, sizeof(MultiCounterQuerySetS));
+  const int current_process_idx = current_query_index_for_process();
+  query->queries = NEW_C_HEAP_ARRAY(MultiCounterQueryS, current_process_idx + 1, mtInternal);
+  memset(query->queries, 0, sizeof(MultiCounterQueryS) * (current_process_idx + 1));
+  query->size = current_process_idx + 1;
+  return query;
+}
+
+static MultiCounterQueryP current_process_counter_query(MultiCounterQuerySetP process_query_set) {
+  assert(process_query_set != NULL, "invariant");
+  const int current_query_index = current_query_index_for_process();
+  assert(current_query_index < process_query_set->size, "invariant");
+  return &process_query_set->queries[current_query_index];
+}
+
+static void clear_multi_counter(MultiCounterQueryP query) {
+  for (int i = 0; i < query->noOfCounters; ++i) {
+    pdh_cleanup(NULL, &query->counters[i]);
+  }
+  pdh_cleanup(&query->query.query, NULL);
+}
+
+static int collect_process_query_data(MultiCounterQuerySetP counter_query_set) {
+  const int current_process_idx = current_query_index_for_process();
+  while (current_process_idx < counter_query_set->size - 1) {
+    const int new_size = --counter_query_set->size;
+    clear_multi_counter(&counter_query_set->queries[new_size]);
+  }
+  return collect_query_data(&counter_query_set->queries[current_process_idx]);
+}
+
+static int query_process_counter(MultiCounterQuerySetP process_query_set, int slot_index, DWORD format, PDH_FMT_COUNTERVALUE* const value) {
+  MultiCounterQueryP const current_query = current_process_counter_query(process_query_set);
+  assert(current_query != NULL, "invariant");
+  assert(slot_index < current_query->noOfCounters, "invariant");
+  assert(current_query->counters[slot_index] != NULL, "invariant");
+  return formatted_counter_value(current_query->counters[slot_index], format, value);
+}
+
+/*
+ * Construct a fully qualified PDH path
+ *
+ * @param objectName   a PDH Object string representation(required)
+ * @param counterName  a PDH Counter string representation(required)
+ * @param imageName    a process image name string, ex. "java" (opt)
+ * @param instance     an instance string, ex. "0", "1", ... (opt)
+ * @return             the fully qualified PDH path.
+ *
+ * Caller will need a ResourceMark.
+ *
+ * (PdhMakeCounterPath() seems buggy on concatenating instances, hence this function instead)
+ */
+static const char* make_fully_qualified_counter_path(const char* object_name,
+                                                     const char* counter_name,
+                                                     const char* image_name = NULL,
+                                                     const char* instance = NULL) {
+  assert(object_name != NULL, "invariant");
+  assert(counter_name != NULL, "invariant");
+  size_t full_counter_path_len = strlen(object_name) + strlen(counter_name);
+
+  char* full_counter_path;
+  size_t jio_snprintf_result = 0;
+  if (image_name) {
+    /*
+    * For paths using the "Process" Object.
+    *
+    * Examples:
+    * form:   "\object_name(image_name#instance)\counter_name"
+    * actual: "\Process(java#2)\ID Process"
+    */
+    full_counter_path_len += PROCESS_OBJECT_INSTANCE_COUNTER_FMT_LEN;
+    full_counter_path_len += strlen(image_name);
+    /*
+    * image_name must be passed together with an associated
+    * instance "number" ("0", "1", "2", ...).
+    * This is required in order to create valid "Process" Object paths.
+    *
+    * Examples: "\Process(java#0)", \Process(java#1"), ...
+    */
+    assert(instance != NULL, "invariant");
+    full_counter_path_len += strlen(instance);
+    full_counter_path = NEW_RESOURCE_ARRAY_RETURN_NULL(char, full_counter_path_len + 1);
+    if (full_counter_path == NULL) {
+      return NULL;
+    }
+    jio_snprintf_result = jio_snprintf(full_counter_path,
+                                       full_counter_path_len + 1,
+                                       PROCESS_OBJECT_INSTANCE_COUNTER_FMT,
+                                       object_name,
+                                       image_name,
+                                       instance,
+                                       counter_name);
+  } else {
+    if (instance) {
+      /*
+      * For paths where the Object has multiple instances.
+      *
+      * Examples:
+      * form:   "\object_name(instance)\counter_name"
+      * actual: "\Processor(0)\% Privileged Time"
+      */
+      full_counter_path_len += strlen(instance);
+      full_counter_path_len += OBJECT_WITH_INSTANCES_COUNTER_FMT_LEN;
+    } else {
+      /*
+      * For "normal" paths.
+      *
+      * Examples:
+      * form:   "\object_name\counter_name"
+      * actual: "\Memory\Available Mbytes"
+      */
+      full_counter_path_len += OBJECT_COUNTER_FMT_LEN;
+    }
+    full_counter_path = NEW_RESOURCE_ARRAY_RETURN_NULL(char, full_counter_path_len + 1);
+    if (full_counter_path == NULL) {
+      return NULL;
+    }
+    if (instance) {
+      jio_snprintf_result = jio_snprintf(full_counter_path,
+                                         full_counter_path_len + 1,
+                                         OBJECT_WITH_INSTANCES_COUNTER_FMT,
+                                         object_name,
+                                         instance,
+                                         counter_name);
+    } else {
+      jio_snprintf_result = jio_snprintf(full_counter_path,
+                                         full_counter_path_len + 1,
+                                         OBJECT_COUNTER_FMT,
+                                         object_name,
+                                         counter_name);
+    }
+  }
+  assert(full_counter_path_len == jio_snprintf_result, "invariant");
+  return full_counter_path;
+}
+
+static void log_invalid_pdh_index(DWORD index) {
+  log_warning(os)("Unable to resolve PDH index: (%ld)", index);
+  log_warning(os)("Please check the registry if this performance object/counter is disabled");
+}
+
+static bool is_valid_pdh_index(DWORD index) {
+  DWORD dummy = 0;
+  if (PdhDll::PdhLookupPerfNameByIndex(NULL, index, NULL, &dummy) != PDH_MORE_DATA) {
+    log_invalid_pdh_index(index);
+    return false;
+  }
+  return true;
+}
+
+/*
+ * Maps an index to a resource area allocated string for the localized PDH artifact.
+ *
+ * Caller will need a ResourceMark.
+ *
+ * @param index    the counter index as specified in the registry
+ * @param ppBuffer pointer to a char*
+ * @return         OS_OK if successful, OS_ERR on failure.
+ */
+static OSReturn lookup_name_by_index(DWORD index, char** p_string) {
+  assert(p_string != NULL, "invariant");
+  if (!is_valid_pdh_index(index)) {
+    return OS_ERR;
+  }
+  // determine size needed
+  DWORD size = 0;
+  PDH_STATUS status = PdhDll::PdhLookupPerfNameByIndex(NULL, index, NULL, &size);
+  assert(status == PDH_MORE_DATA, "invariant");
+  *p_string = NEW_RESOURCE_ARRAY_RETURN_NULL(char, size);
+  if (*p_string== NULL) {
+    return OS_ERR;
+  }
+  if (PdhDll::PdhLookupPerfNameByIndex(NULL, index, *p_string, &size) != ERROR_SUCCESS) {
+    return OS_ERR;
+  }
+  if (0 == size || *p_string == NULL) {
+    return OS_ERR;
+  }
+  // windows vista does not null-terminate the string (although the docs says it will)
+  (*p_string)[size - 1] = '\0';
+  return OS_OK;
+}
+
+static const char* copy_string_to_c_heap(const char* string) {
+  assert(string != NULL, "invariant");
+  const size_t len = strlen(string);
+  char* const cheap_allocated_string = NEW_C_HEAP_ARRAY(char, len + 1, mtInternal);
+  if (NULL == cheap_allocated_string) {
+    return NULL;
+  }
+  strncpy(cheap_allocated_string, string, len + 1);
+  return cheap_allocated_string;
+}
+
+/*
+* Maps an index to a resource area allocated string for the localized PDH artifact.
+*
+* Caller will need a ResourceMark.
+*
+* @param index    the counter index as specified in the registry
+* @return         localized pdh artifact string if successful, NULL on failure.
+*/
+static const char* pdh_localized_artifact(DWORD pdh_artifact_index) {
+  char* pdh_localized_artifact_string = NULL;
+  // get localized name from pdh artifact index
+  if (lookup_name_by_index(pdh_artifact_index, &pdh_localized_artifact_string) != OS_OK) {
+    return NULL;
+  }
+  return pdh_localized_artifact_string;
+}
+
+/*
+ * Returns the PDH string identifying the current process image name.
+ * Use this prefix when getting counters from the PDH process object
+ * representing your process.
+ * Ex. "Process(java#0)\Virtual Bytes" - where "java" is the PDH process
+ * image description.
+ *
+ * Caller needs ResourceMark.
+ *
+ * @return the process image description. NULL if the call failed.
+*/
+static const char* pdh_process_image_name() {
+  char* module_name = NEW_RESOURCE_ARRAY_RETURN_NULL(char, MAX_PATH);
+  if (NULL == module_name) {
+    return NULL;
+  }
+  // Find our module name and use it to extract the image name used by PDH
+  DWORD getmfn_return = GetModuleFileName(NULL, module_name, MAX_PATH);
+  if (getmfn_return >= MAX_PATH || 0 == getmfn_return) {
+    return NULL;
+  }
+  if (os::get_last_error() == ERROR_INSUFFICIENT_BUFFER) {
+    return NULL;
+  }
+  char* process_image_name = strrchr(module_name, '\\'); //drop path
+  process_image_name++;                                  //skip slash
+  char* dot_pos = strrchr(process_image_name, '.');      //drop .exe
+  dot_pos[0] = '\0';
+  return process_image_name;
+}
+
+static void deallocate_pdh_constants() {
+  if (process_image_name != NULL) {
+    FREE_C_HEAP_ARRAY(char, process_image_name);
+    process_image_name = NULL;
+  }
+  if (pdh_IDProcess_counter_fmt != NULL) {</