Merge JEP-349-branch
authormgronlun
Mon, 30 Sep 2019 14:29:09 +0200
branchJEP-349-branch
changeset 58400 61034c56a41e
parent 58399 db26cf04e6ab (current diff)
parent 58398 ff559f979c4b (diff)
child 58401 1211070f439d
Merge
--- a/src/hotspot/share/runtime/compilationPolicy.cpp	Mon Sep 30 14:27:44 2019 +0200
+++ b/src/hotspot/share/runtime/compilationPolicy.cpp	Mon Sep 30 14:29:09 2019 +0200
@@ -191,7 +191,7 @@
 }
 
 #ifndef PRODUCT
-void NonTieredCompPolicy::trace_osr_completion(nmethod* osr_nm) {
+void SimpleCompPolicy::trace_osr_completion(nmethod* osr_nm) {
   if (TraceOnStackReplacement) {
     if (osr_nm == NULL) tty->print_cr("compilation failed");
     else tty->print_cr("nmethod " INTPTR_FORMAT, p2i(osr_nm));
@@ -199,7 +199,7 @@
 }
 #endif // !PRODUCT
 
-void NonTieredCompPolicy::initialize() {
+void SimpleCompPolicy::initialize() {
   // Setup the compiler thread numbers
   if (CICompilerCountPerCPU) {
     // Example: if CICompilerCountPerCPU is true, then we get
@@ -233,7 +233,7 @@
 // - with COMPILER2 not defined it should return zero for c2 compilation levels.
 // - with COMPILER1 not defined it should return zero for c1 compilation levels.
 // - if neither is defined - always return zero.
-int NonTieredCompPolicy::compiler_count(CompLevel comp_level) {
+int SimpleCompPolicy::compiler_count(CompLevel comp_level) {
   assert(!TieredCompilation, "This policy should not be used with TieredCompilation");
   if (COMPILER2_PRESENT(is_server_compilation_mode_vm() && is_c2_compile(comp_level) ||)
       is_client_compilation_mode_vm() && is_c1_compile(comp_level)) {
@@ -242,7 +242,7 @@
   return 0;
 }
 
-void NonTieredCompPolicy::reset_counter_for_invocation_event(const methodHandle& m) {
+void SimpleCompPolicy::reset_counter_for_invocation_event(const methodHandle& m) {
   // Make sure invocation and backedge counter doesn't overflow again right away
   // as would be the case for native methods.
 
@@ -256,7 +256,7 @@
   assert(!m->was_never_executed(), "don't reset to 0 -- could be mistaken for never-executed");
 }
 
-void NonTieredCompPolicy::reset_counter_for_back_branch_event(const methodHandle& m) {
+void SimpleCompPolicy::reset_counter_for_back_branch_event(const methodHandle& m) {
   // Delay next back-branch event but pump up invocation counter to trigger
   // whole method compilation.
   MethodCounters* mcs = m->method_counters();
@@ -314,13 +314,13 @@
 }
 
 // Called at the end of the safepoint
-void NonTieredCompPolicy::do_safepoint_work() {
+void SimpleCompPolicy::do_safepoint_work() {
   if(UseCounterDecay && CounterDecay::is_decay_needed()) {
     CounterDecay::decay();
   }
 }
 
-void NonTieredCompPolicy::reprofile(ScopeDesc* trap_scope, bool is_osr) {
+void SimpleCompPolicy::reprofile(ScopeDesc* trap_scope, bool is_osr) {
   ScopeDesc* sd = trap_scope;
   MethodCounters* mcs;
   InvocationCounter* c;
@@ -346,7 +346,7 @@
 
 // This method can be called by any component of the runtime to notify the policy
 // that it's recommended to delay the compilation of this method.
-void NonTieredCompPolicy::delay_compilation(Method* method) {
+void SimpleCompPolicy::delay_compilation(Method* method) {
   MethodCounters* mcs = method->method_counters();
   if (mcs != NULL) {
     mcs->invocation_counter()->decay();
@@ -354,7 +354,7 @@
   }
 }
 
-void NonTieredCompPolicy::disable_compilation(Method* method) {
+void SimpleCompPolicy::disable_compilation(Method* method) {
   MethodCounters* mcs = method->method_counters();
   if (mcs != NULL) {
     mcs->invocation_counter()->set_state(InvocationCounter::wait_for_nothing);
@@ -362,11 +362,11 @@
   }
 }
 
-CompileTask* NonTieredCompPolicy::select_task(CompileQueue* compile_queue) {
+CompileTask* SimpleCompPolicy::select_task(CompileQueue* compile_queue) {
   return select_task_helper(compile_queue);
 }
 
-bool NonTieredCompPolicy::is_mature(Method* method) {
+bool SimpleCompPolicy::is_mature(Method* method) {
   MethodData* mdo = method->method_data();
   assert(mdo != NULL, "Should be");
   uint current = mdo->mileage_of(method);
@@ -381,7 +381,7 @@
   return (current >= initial + target);
 }
 
-nmethod* NonTieredCompPolicy::event(const methodHandle& method, const methodHandle& inlinee, int branch_bci,
+nmethod* SimpleCompPolicy::event(const methodHandle& method, const methodHandle& inlinee, int branch_bci,
                                     int bci, CompLevel comp_level, CompiledMethod* nm, JavaThread* thread) {
   assert(comp_level == CompLevel_none, "This should be only called from the interpreter");
   NOT_PRODUCT(trace_frequency_counter_overflow(method, branch_bci, bci));
@@ -440,7 +440,7 @@
 }
 
 #ifndef PRODUCT
-void NonTieredCompPolicy::trace_frequency_counter_overflow(const methodHandle& m, int branch_bci, int bci) {
+void SimpleCompPolicy::trace_frequency_counter_overflow(const methodHandle& m, int branch_bci, int bci) {
   if (TraceInvocationCounterOverflow) {
     MethodCounters* mcs = m->method_counters();
     assert(mcs != NULL, "MethodCounters cannot be NULL for profiling");
@@ -472,7 +472,7 @@
   }
 }
 
-void NonTieredCompPolicy::trace_osr_request(const methodHandle& method, nmethod* osr, int bci) {
+void SimpleCompPolicy::trace_osr_request(const methodHandle& method, nmethod* osr, int bci) {
   if (TraceOnStackReplacement) {
     ResourceMark rm;
     tty->print(osr != NULL ? "Reused OSR entry for " : "Requesting OSR entry for ");
@@ -482,8 +482,6 @@
 }
 #endif // !PRODUCT
 
-// SimpleCompPolicy - compile current method
-
 void SimpleCompPolicy::method_invocation_event(const methodHandle& m, JavaThread* thread) {
   const int comp_level = CompLevel_highest_tier;
   const int hot_count = m->invocation_count();
--- a/src/hotspot/share/runtime/compilationPolicy.hpp	Mon Sep 30 14:27:44 2019 +0200
+++ b/src/hotspot/share/runtime/compilationPolicy.hpp	Mon Sep 30 14:29:09 2019 +0200
@@ -84,17 +84,19 @@
   virtual bool should_not_inline(ciEnv* env, ciMethod* method) { return false; }
 };
 
-// A base class for baseline policies.
-class NonTieredCompPolicy : public CompilationPolicy {
+// A simple compilation policy.
+class SimpleCompPolicy : public CompilationPolicy {
   int _compiler_count;
-protected:
+ private:
   static void trace_frequency_counter_overflow(const methodHandle& m, int branch_bci, int bci);
   static void trace_osr_request(const methodHandle& method, nmethod* osr, int bci);
   static void trace_osr_completion(nmethod* osr_nm);
   void reset_counter_for_invocation_event(const methodHandle& method);
   void reset_counter_for_back_branch_event(const methodHandle& method);
-public:
-  NonTieredCompPolicy() : _compiler_count(0) { }
+  void method_invocation_event(const methodHandle& m, JavaThread* thread);
+  void method_back_branch_event(const methodHandle& m, int bci, JavaThread* thread);
+ public:
+  SimpleCompPolicy() : _compiler_count(0) { }
   virtual CompLevel initial_compile_level() { return CompLevel_highest_tier; }
   virtual int compiler_count(CompLevel comp_level);
   virtual void do_safepoint_work();
@@ -105,14 +107,7 @@
   virtual void initialize();
   virtual CompileTask* select_task(CompileQueue* compile_queue);
   virtual nmethod* event(const methodHandle& method, const methodHandle& inlinee, int branch_bci, int bci, CompLevel comp_level, CompiledMethod* nm, JavaThread* thread);
-  virtual void method_invocation_event(const methodHandle& m, JavaThread* thread) = 0;
-  virtual void method_back_branch_event(const methodHandle& m, int bci, JavaThread* thread) = 0;
 };
 
-class SimpleCompPolicy : public NonTieredCompPolicy {
- public:
-  virtual void method_invocation_event(const methodHandle& m, JavaThread* thread);
-  virtual void method_back_branch_event(const methodHandle& m, int bci, JavaThread* thread);
-};
 
 #endif // SHARE_RUNTIME_COMPILATIONPOLICY_HPP
--- a/src/hotspot/share/runtime/tieredThresholdPolicy.hpp	Mon Sep 30 14:27:44 2019 +0200
+++ b/src/hotspot/share/runtime/tieredThresholdPolicy.hpp	Mon Sep 30 14:29:09 2019 +0200
@@ -215,7 +215,6 @@
 
   bool maybe_switch_to_aot(const methodHandle& mh, CompLevel cur_level, CompLevel next_level, JavaThread* thread);
 
-protected:
   int c1_count() const     { return _c1_count; }
   int c2_count() const     { return _c2_count; }
   void set_c1_count(int x) { _c1_count = x;    }
@@ -224,11 +223,11 @@
   enum EventType { CALL, LOOP, COMPILE, REMOVE_FROM_QUEUE, UPDATE_IN_QUEUE, REPROFILE, MAKE_NOT_ENTRANT };
   void print_event(EventType type, const methodHandle& mh, const methodHandle& imh, int bci, CompLevel level);
   // Print policy-specific information if necessary
-  virtual void print_specific(EventType type, const methodHandle& mh, const methodHandle& imh, int bci, CompLevel level);
+  void print_specific(EventType type, const methodHandle& mh, const methodHandle& imh, int bci, CompLevel level);
   // Check if the method can be compiled, change level if necessary
   void compile(const methodHandle& mh, int bci, CompLevel level, JavaThread* thread);
   // Submit a given method for compilation
-  virtual void submit_compile(const methodHandle& mh, int bci, CompLevel level, JavaThread* thread);
+  void submit_compile(const methodHandle& mh, int bci, CompLevel level, JavaThread* thread);
   // Simple methods are as good being compiled with C1 as C2.
   // This function tells if it's such a function.
   inline static bool is_trivial(Method* method);
@@ -242,10 +241,10 @@
 
   // Get a compilation level for a given method.
   static CompLevel comp_level(Method* method);
-  virtual void method_invocation_event(const methodHandle& method, const methodHandle& inlinee,
-                                       CompLevel level, CompiledMethod* nm, JavaThread* thread);
-  virtual void method_back_branch_event(const methodHandle& method, const methodHandle& inlinee,
-                                        int bci, CompLevel level, CompiledMethod* nm, JavaThread* thread);
+  void method_invocation_event(const methodHandle& method, const methodHandle& inlinee,
+                               CompLevel level, CompiledMethod* nm, JavaThread* thread);
+  void method_back_branch_event(const methodHandle& method, const methodHandle& inlinee,
+                                int bci, CompLevel level, CompiledMethod* nm, JavaThread* thread);
 
   void set_increase_threshold_at_ratio() { _increase_threshold_at_ratio = 100 / (100 - (double)IncreaseFirstTierCompileThresholdAt); }
   void set_start_time(jlong t) { _start_time = t;    }
--- a/src/java.base/linux/classes/sun/nio/fs/LinuxFileSystem.java	Mon Sep 30 14:27:44 2019 +0200
+++ b/src/java.base/linux/classes/sun/nio/fs/LinuxFileSystem.java	Mon Sep 30 14:29:09 2019 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2019, 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
@@ -79,10 +79,26 @@
         ArrayList<UnixMountEntry> entries = new ArrayList<>();
         try {
             long fp = setmntent(Util.toBytes(fstab), Util.toBytes("r"));
+            int maxLineSize = 1024;
+            try {
+                for (;;) {
+                    int lineSize = getlinelen(fp);
+                    if (lineSize == -1)
+                        break;
+                    if (lineSize > maxLineSize)
+                        maxLineSize = lineSize;
+                }
+            } catch (UnixException x) {
+                // nothing we need to do
+            } finally {
+                rewind(fp);
+            }
+
             try {
                 for (;;) {
                     UnixMountEntry entry = new UnixMountEntry();
-                    int res = getmntent(fp, entry);
+                    // count in NUL character at the end
+                    int res = getmntent(fp, entry, maxLineSize + 1);
                     if (res < 0)
                         break;
                     entries.add(entry);
--- a/src/java.base/linux/classes/sun/nio/fs/LinuxNativeDispatcher.java	Mon Sep 30 14:27:44 2019 +0200
+++ b/src/java.base/linux/classes/sun/nio/fs/LinuxNativeDispatcher.java	Mon Sep 30 14:29:09 2019 +0200
@@ -51,7 +51,17 @@
     /**
      * int getmntent(FILE *fp, struct mnttab *mp, int len);
      */
-    static native int getmntent(long fp, UnixMountEntry entry)
+
+    static int getmntent(long fp, UnixMountEntry entry, int buflen) throws UnixException {
+        NativeBuffer buffer = NativeBuffers.getNativeBuffer(buflen);
+        try {
+            return getmntent0(fp, entry, buffer.address(), buflen);
+        } finally {
+            buffer.release();
+        }
+    }
+
+    static native int getmntent0(long fp, UnixMountEntry entry, long buffer, int bufLen)
         throws UnixException;
 
     /**
--- a/src/java.base/linux/native/libnio/fs/LinuxNativeDispatcher.c	Mon Sep 30 14:27:44 2019 +0200
+++ b/src/java.base/linux/native/libnio/fs/LinuxNativeDispatcher.c	Mon Sep 30 14:29:09 2019 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2019, 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
@@ -169,12 +169,11 @@
 }
 
 JNIEXPORT jint JNICALL
-Java_sun_nio_fs_LinuxNativeDispatcher_getmntent(JNIEnv* env, jclass this,
-    jlong value, jobject entry)
+Java_sun_nio_fs_LinuxNativeDispatcher_getmntent0(JNIEnv* env, jclass this,
+    jlong value, jobject entry, jlong buffer, jint bufLen)
 {
     struct mntent ent;
-    char buf[1024];
-    int buflen = sizeof(buf);
+    char * buf = (char*)jlong_to_ptr(buffer);
     struct mntent* m;
     FILE* fp = jlong_to_ptr(value);
     jsize len;
@@ -184,7 +183,7 @@
     char* fstype;
     char* options;
 
-    m = getmntent_r(fp, &ent, (char*)&buf, buflen);
+    m = getmntent_r(fp, &ent, buf, (int)bufLen);
     if (m == NULL)
         return -1;
     name = m->mnt_fsname;
--- a/src/java.base/unix/classes/sun/nio/fs/UnixNativeDispatcher.java	Mon Sep 30 14:27:44 2019 +0200
+++ b/src/java.base/unix/classes/sun/nio/fs/UnixNativeDispatcher.java	Mon Sep 30 14:29:09 2019 +0200
@@ -119,6 +119,16 @@
     static native void fclose(long stream) throws UnixException;
 
     /**
+     * void rewind(FILE* stream);
+     */
+    static native void rewind(long stream) throws UnixException;
+
+    /**
+     * ssize_t getline(char **lineptr, size_t *n, FILE *stream);
+     */
+    static native int getlinelen(long stream) throws UnixException;
+
+    /**
      * link(const char* existing, const char* new)
      */
     static void link(UnixPath existing, UnixPath newfile) throws UnixException {
--- a/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c	Mon Sep 30 14:27:44 2019 +0200
+++ b/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c	Mon Sep 30 14:29:09 2019 +0200
@@ -403,6 +403,51 @@
     }
 }
 
+JNIEXPORT void JNICALL
+Java_sun_nio_fs_UnixNativeDispatcher_rewind(JNIEnv* env, jclass this, jlong stream)
+{
+    FILE* fp = jlong_to_ptr(stream);
+    int saved_errno;
+
+    errno = 0;
+    rewind(fp);
+    saved_errno = errno;
+    if (ferror(fp)) {
+        throwUnixException(env, saved_errno);
+    }
+}
+
+/**
+ * This function returns line length without NUL terminator or -1 on EOF.
+ */
+JNIEXPORT jint JNICALL
+Java_sun_nio_fs_UnixNativeDispatcher_getlinelen(JNIEnv* env, jclass this, jlong stream)
+{
+    FILE* fp = jlong_to_ptr(stream);
+    size_t lineSize = 0;
+    char * lineBuffer = NULL;
+    int saved_errno;
+
+    ssize_t res = getline(&lineBuffer, &lineSize, fp);
+    saved_errno = errno;
+
+    /* Should free lineBuffer no matter result, according to man page */
+    if (lineBuffer != NULL)
+        free(lineBuffer);
+
+    if (feof(fp))
+        return -1;
+
+    /* On successfull return res >= 0, otherwise res is -1 */
+    if (res == -1)
+        throwUnixException(env, saved_errno);
+
+    if (res > INT_MAX)
+        throwUnixException(env, EOVERFLOW);
+
+    return (jint)res;
+}
+
 JNIEXPORT jint JNICALL
 Java_sun_nio_fs_UnixNativeDispatcher_open0(JNIEnv* env, jclass this,
     jlong pathAddress, jint oflags, jint mode)