diff src/share/vm/runtime/compilationPolicy.hpp @ 1783:d5d065957597

6953144: Tiered compilation Summary: Infrastructure for tiered compilation support (interpreter + c1 + c2) for 32 and 64 bit. Simple tiered policy implementation. Reviewed-by: kvn, never, phh, twisti
author iveresov
date Fri, 03 Sep 2010 17:51:07 -0700
parents c18cbe5936b8
children f95d63e2154a
line wrap: on
line diff
--- a/src/share/vm/runtime/compilationPolicy.hpp	Thu Sep 02 11:40:02 2010 -0700
+++ b/src/share/vm/runtime/compilationPolicy.hpp	Fri Sep 03 17:51:07 2010 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2010, 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
@@ -25,53 +25,91 @@
 // The CompilationPolicy selects which method (if any) should be compiled.
 // It also decides which methods must always be compiled (i.e., are never
 // interpreted).
+class CompileTask;
+class CompileQueue;
 
 class CompilationPolicy : public CHeapObj {
- private:
   static CompilationPolicy* _policy;
   // Accumulated time
   static elapsedTimer       _accumulated_time;
 
   static bool               _in_vm_startup;
-
- public:
-  virtual void method_invocation_event(methodHandle m, TRAPS) = 0;
-  virtual void method_back_branch_event(methodHandle m, int branch_bci, int loop_top_bci, TRAPS) = 0;
-  virtual int compilation_level(methodHandle m, int branch_bci) = 0;
-
-  void reset_counter_for_invocation_event(methodHandle method);
-  void reset_counter_for_back_branch_event(methodHandle method);
-
+public:
   static  void set_in_vm_startup(bool in_vm_startup) { _in_vm_startup = in_vm_startup; }
   static  void completed_vm_startup();
-  static  bool delayCompilationDuringStartup() { return _in_vm_startup; }
+  static  bool delay_compilation_during_startup()    { return _in_vm_startup; }
 
-  static bool mustBeCompiled(methodHandle m);      // m must be compiled before executing it
-  static bool canBeCompiled(methodHandle m);       // m is allowed to be compiled
-
+  // m must be compiled before executing it
+  static bool must_be_compiled(methodHandle m, int comp_level = CompLevel_all);
+  // m is allowed to be compiled
+  static bool can_be_compiled(methodHandle m, int comp_level = CompLevel_all);
+  static bool is_compilation_enabled();
   static void set_policy(CompilationPolicy* policy) { _policy = policy; }
-  static CompilationPolicy* policy() { return _policy; }
+  static CompilationPolicy* policy()                { return _policy; }
 
   // Profiling
   elapsedTimer* accumulated_time() { return &_accumulated_time; }
   void print_time() PRODUCT_RETURN;
+  virtual int compiler_count(CompLevel comp_level) = 0;
+  // main notification entry, return a pointer to an nmethod if the OSR is required,
+  // returns NULL otherwise.
+  virtual nmethod* event(methodHandle method, methodHandle inlinee, int branch_bci, int bci, CompLevel comp_level, TRAPS) = 0;
+  // safepoint() is called at the end of the safepoint
+  virtual void do_safepoint_work() = 0;
+  // reprofile request
+  virtual void reprofile(ScopeDesc* trap_scope, bool is_osr) = 0;
+  // delay_compilation(method) can be called by any component of the runtime to notify the policy
+  // that it's recommended to delay the complation of this method.
+  virtual void delay_compilation(methodOop method) = 0;
+  // disable_compilation() is called whenever the runtime decides to disable compilation of the
+  // specified method.
+  virtual void disable_compilation(methodOop method) = 0;
+  // Select task is called by CompileBroker. The queue is guaranteed to have at least one
+  // element and is locked. The function should select one and return it.
+  virtual CompileTask* select_task(CompileQueue* compile_queue) = 0;
+  // Tell the runtime if we think a given method is adequately profiled.
+  virtual bool is_mature(methodOop method) = 0;
+  // Do policy initialization
+  virtual void initialize() = 0;
 };
 
-class SimpleCompPolicy : public CompilationPolicy {
+// A base class for baseline policies.
+class NonTieredCompPolicy : public CompilationPolicy {
+  int _compiler_count;
+protected:
+  static void trace_frequency_counter_overflow(methodHandle m, int branch_bci, int bci);
+  static void trace_osr_request(methodHandle method, nmethod* osr, int bci);
+  static void trace_osr_completion(nmethod* osr_nm);
+  void reset_counter_for_invocation_event(methodHandle method);
+  void reset_counter_for_back_branch_event(methodHandle method);
+public:
+  NonTieredCompPolicy() : _compiler_count(0) { }
+  virtual int compiler_count(CompLevel comp_level);
+  virtual void do_safepoint_work();
+  virtual void reprofile(ScopeDesc* trap_scope, bool is_osr);
+  virtual void delay_compilation(methodOop method);
+  virtual void disable_compilation(methodOop method);
+  virtual bool is_mature(methodOop method);
+  virtual void initialize();
+  virtual CompileTask* select_task(CompileQueue* compile_queue);
+  virtual nmethod* event(methodHandle method, methodHandle inlinee, int branch_bci, int bci, CompLevel comp_level, TRAPS);
+  virtual void method_invocation_event(methodHandle m, TRAPS) = 0;
+  virtual void method_back_branch_event(methodHandle m, int bci, TRAPS) = 0;
+};
+
+class SimpleCompPolicy : public NonTieredCompPolicy {
  public:
-  void method_invocation_event( methodHandle m, TRAPS);
-  void method_back_branch_event(methodHandle m, int branch_bci, int loop_top_bci, TRAPS);
-  int compilation_level(methodHandle m, int branch_bci);
+  virtual void method_invocation_event(methodHandle m, TRAPS);
+  virtual void method_back_branch_event(methodHandle m, int bci, TRAPS);
 };
 
 // StackWalkCompPolicy - existing C2 policy
 
 #ifdef COMPILER2
-class StackWalkCompPolicy : public CompilationPolicy {
+class StackWalkCompPolicy : public NonTieredCompPolicy {
  public:
-  void method_invocation_event(methodHandle m, TRAPS);
-  void method_back_branch_event(methodHandle m, int branch_bci, int loop_top_bci, TRAPS);
-  int compilation_level(methodHandle m, int branch_bci);
+  virtual void method_invocation_event(methodHandle m, TRAPS);
+  virtual void method_back_branch_event(methodHandle m, int bci, TRAPS);
 
  private:
   RFrame* findTopInlinableFrame(GrowableArray<RFrame*>* stack);