< prev index next >

src/hotspot/share/ci/ciEnv.hpp

Print this page

  1 /*
  2  * Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #ifndef SHARE_CI_CIENV_HPP
 26 #define SHARE_CI_CIENV_HPP
 27 
 28 #include "ci/ciClassList.hpp"
 29 #include "ci/ciObjectFactory.hpp"
 30 #include "classfile/vmClassMacros.hpp"
 31 #include "code/debugInfoRec.hpp"
 32 #include "code/dependencies.hpp"
 33 #include "code/exceptionHandlerTable.hpp"
 34 #include "compiler/cHeapStringHolder.hpp"
 35 #include "compiler/compiler_globals.hpp"
 36 #include "compiler/compilerThread.hpp"
 37 #include "oops/methodData.hpp"
 38 #include "runtime/javaThread.hpp"
 39 
 40 class CompileTask;
 41 class OopMapSet;


 42 
 43 // ciEnv
 44 //
 45 // This class is the top level broker for requests from the compiler
 46 // to the VM.
 47 class ciEnv : StackObj {
 48   CI_PACKAGE_ACCESS_TO
 49   friend class CompileBroker;
 50   friend class Dependencies;  // for get_object, during logging
 51   friend class RecordLocation;
 52   friend class PrepareExtraDataClosure;
 53 
 54 private:
 55   Arena*           _arena;       // Alias for _ciEnv_arena except in init_shared_objects()
 56   Arena            _ciEnv_arena;
 57   ciObjectFactory* _factory;
 58   OopRecorder*     _oop_recorder;
 59   DebugInformationRecorder* _debug_info;
 60   Dependencies*    _dependencies;
 61   CHeapStringHolder _failure_reason;

274   ciReturnAddress* get_return_address(int bci) {
275     return _factory->get_return_address(bci);
276   }
277 
278   // Get a ciMethodData representing the methodData for a method
279   // with none.
280   ciMethodData* get_empty_methodData() {
281     return _factory->get_empty_methodData();
282   }
283 
284   // General utility : get a buffer of some required length.
285   // Used in symbol creation.
286   char* name_buffer(int req_len);
287 
288   // Is this thread currently in the VM state?
289   static bool is_in_vm();
290 
291   // Helper routine for determining the validity of a compilation with
292   // respect to method dependencies (e.g. concurrent class loading).
293   void validate_compile_task_dependencies(ciMethod* target);






294 public:
295   enum {
296     MethodCompilable,
297     MethodCompilable_not_at_tier,
298     MethodCompilable_never
299   };
300 
301   ciEnv(CompileTask* task);
302   // Used only during initialization of the ci
303   ciEnv(Arena* arena);
304   ~ciEnv();
305 
306   OopRecorder* oop_recorder() { return _oop_recorder; }
307   void set_oop_recorder(OopRecorder* r) { _oop_recorder = r; }
308 
309   DebugInformationRecorder* debug_info() { return _debug_info; }
310   void set_debug_info(DebugInformationRecorder* i) { _debug_info = i; }
311 
312   Dependencies* dependencies() { return _dependencies; }
313   void set_dependencies(Dependencies* d) { _dependencies = d; }

346     return _jvmti_can_access_local_variables || _jvmti_can_pop_frame;
347   }
348   bool  jvmti_can_hotswap_or_post_breakpoint() const { return _jvmti_can_hotswap_or_post_breakpoint; }
349   bool  jvmti_can_post_on_exceptions()         const { return _jvmti_can_post_on_exceptions; }
350   bool  jvmti_can_get_owned_monitor_info()     const { return _jvmti_can_get_owned_monitor_info; }
351   bool  jvmti_can_walk_any_space()             const { return _jvmti_can_walk_any_space; }
352 
353   // Cache DTrace flags
354   void  cache_dtrace_flags();
355   bool  dtrace_method_probes()   const { return _dtrace_method_probes; }
356   bool  dtrace_alloc_probes()    const { return _dtrace_alloc_probes; }
357 
358   // The compiler task which has created this env.
359   // May be useful to find out compile_id, comp_level, etc.
360   CompileTask* task() const { return _task; }
361 
362   // Handy forwards to the task:
363   int comp_level();   // task()->comp_level()
364   int compile_id();  // task()->compile_id()
365 


















366   // Register the result of a compilation.
367   void register_method(ciMethod*                 target,
368                        int                       entry_bci,
369                        CodeOffsets*              offsets,
370                        int                       orig_pc_offset,
371                        CodeBuffer*               code_buffer,
372                        int                       frame_words,
373                        OopMapSet*                oop_map_set,
374                        ExceptionHandlerTable*    handler_table,
375                        ImplicitExceptionTable*   inc_table,
376                        AbstractCompiler*         compiler,


377                        bool                      has_unsafe_access,
378                        bool                      has_wide_vectors,
379                        bool                      has_monitors,
380                        bool                      has_scoped_access,
381                        int                       immediate_oops_patched);


382 
383   // Access to certain well known ciObjects.
384 #define VM_CLASS_FUNC(name, ignore_s) \
385   ciInstanceKlass* name() { \
386     return _##name;\
387   }
388   VM_CLASSES_DO(VM_CLASS_FUNC)
389 #undef VM_CLASS_FUNC
390 
391   ciInstance* NullPointerException_instance() {
392     assert(_NullPointerException_instance != nullptr, "initialization problem");
393     return _NullPointerException_instance;
394   }
395   ciInstance* ArithmeticException_instance() {
396     assert(_ArithmeticException_instance != nullptr, "initialization problem");
397     return _ArithmeticException_instance;
398   }
399   ciInstance* ArrayIndexOutOfBoundsException_instance() {
400     assert(_ArrayIndexOutOfBoundsException_instance != nullptr, "initialization problem");
401     return _ArrayIndexOutOfBoundsException_instance;

451 
452   // Notice that a method has been inlined in the current compile;
453   // used only for statistics.
454   void notice_inlined_method(ciMethod* method);
455 
456   // Total number of bytecodes in inlined methods in this compile
457   int num_inlined_bytecodes() const;
458 
459   // Output stream for logging compilation info.
460   CompileLog* log() { return _log; }
461   void set_log(CompileLog* log) { _log = log; }
462 
463   void record_failure(const char* reason);      // Record failure and report later
464   void report_failure(const char* reason);      // Report failure immediately
465   void record_method_not_compilable(const char* reason, bool all_tiers = false);
466   void record_out_of_memory_failure();
467 
468   // RedefineClasses support
469   void metadata_do(MetadataClosure* f) { _factory->metadata_do(f); }
470 







471   // Replay support
472 private:
473   static int klass_compare(const InstanceKlass* const &ik1, const InstanceKlass* const &ik2) {
474     if (ik1 > ik2) {
475       return 1;
476     } else if (ik1 < ik2) {
477       return -1;
478     } else {
479       return 0;
480     }
481   }
482   bool dyno_loc(const InstanceKlass* ik, const char *&loc) const;
483   void set_dyno_loc(const InstanceKlass* ik);
484   void record_best_dyno_loc(const InstanceKlass* ik);
485   bool print_dyno_loc(outputStream* out, const InstanceKlass* ik) const;
486 
487   GrowableArray<const InstanceKlass*>* _dyno_klasses;
488   GrowableArray<const char *>*         _dyno_locs;
489 
490 #define MAX_DYNO_NAME_LENGTH 1024

495   void dump_replay_data(int compile_id);
496   void dump_inline_data(int compile_id);
497   void dump_replay_data(outputStream* out);
498   void dump_replay_data_unsafe(outputStream* out);
499   void dump_replay_data_helper(outputStream* out);
500   void dump_compile_data(outputStream* out);
501   void dump_replay_data_version(outputStream* out);
502 
503   const char *dyno_name(const InstanceKlass* ik) const;
504   const char *replay_name(const InstanceKlass* ik) const;
505   const char *replay_name(ciKlass* i) const;
506 
507   void record_lambdaform(Thread* thread, oop obj);
508   void record_member(Thread* thread, oop obj);
509   void record_mh(Thread* thread, oop obj);
510   void record_call_site_obj(Thread* thread, oop obj);
511   void record_call_site_method(Thread* thread, Method* adapter);
512   void process_invokedynamic(const constantPoolHandle &cp, int index, JavaThread* thread);
513   void process_invokehandle(const constantPoolHandle &cp, int index, JavaThread* thread);
514   void find_dynamic_call_sites();




515 };
516 
517 #endif // SHARE_CI_CIENV_HPP

  1 /*
  2  * Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #ifndef SHARE_CI_CIENV_HPP
 26 #define SHARE_CI_CIENV_HPP
 27 
 28 #include "ci/ciClassList.hpp"
 29 #include "ci/ciObjectFactory.hpp"
 30 #include "classfile/vmClassMacros.hpp"
 31 #include "code/debugInfoRec.hpp"
 32 #include "code/dependencies.hpp"
 33 #include "code/exceptionHandlerTable.hpp"
 34 #include "compiler/cHeapStringHolder.hpp"
 35 #include "compiler/compiler_globals.hpp"
 36 #include "compiler/compilerThread.hpp"
 37 #include "oops/methodData.hpp"
 38 #include "runtime/javaThread.hpp"
 39 
 40 class CompileTask;
 41 class OopMapSet;
 42 class AOTCodeEntry;
 43 class AOTCodeReader;
 44 
 45 // ciEnv
 46 //
 47 // This class is the top level broker for requests from the compiler
 48 // to the VM.
 49 class ciEnv : StackObj {
 50   CI_PACKAGE_ACCESS_TO
 51   friend class CompileBroker;
 52   friend class Dependencies;  // for get_object, during logging
 53   friend class RecordLocation;
 54   friend class PrepareExtraDataClosure;
 55 
 56 private:
 57   Arena*           _arena;       // Alias for _ciEnv_arena except in init_shared_objects()
 58   Arena            _ciEnv_arena;
 59   ciObjectFactory* _factory;
 60   OopRecorder*     _oop_recorder;
 61   DebugInformationRecorder* _debug_info;
 62   Dependencies*    _dependencies;
 63   CHeapStringHolder _failure_reason;

276   ciReturnAddress* get_return_address(int bci) {
277     return _factory->get_return_address(bci);
278   }
279 
280   // Get a ciMethodData representing the methodData for a method
281   // with none.
282   ciMethodData* get_empty_methodData() {
283     return _factory->get_empty_methodData();
284   }
285 
286   // General utility : get a buffer of some required length.
287   // Used in symbol creation.
288   char* name_buffer(int req_len);
289 
290   // Is this thread currently in the VM state?
291   static bool is_in_vm();
292 
293   // Helper routine for determining the validity of a compilation with
294   // respect to method dependencies (e.g. concurrent class loading).
295   void validate_compile_task_dependencies(ciMethod* target);
296 
297   // Helper rountimes to factor out common code used by routines that register a method
298   // i.e. register_aot_method() and register_method()
299   bool is_compilation_valid(JavaThread* thread, ciMethod* target, bool preload, bool install_code, CodeBuffer* code_buffer, AOTCodeEntry* aot_code_entry);
300   void make_code_usable(JavaThread* thread, ciMethod* target, bool preload, int entry_bci, AOTCodeEntry* aot_code_entry, nmethod* nm);
301 
302 public:
303   enum {
304     MethodCompilable,
305     MethodCompilable_not_at_tier,
306     MethodCompilable_never
307   };
308 
309   ciEnv(CompileTask* task);
310   // Used only during initialization of the ci
311   ciEnv(Arena* arena);
312   ~ciEnv();
313 
314   OopRecorder* oop_recorder() { return _oop_recorder; }
315   void set_oop_recorder(OopRecorder* r) { _oop_recorder = r; }
316 
317   DebugInformationRecorder* debug_info() { return _debug_info; }
318   void set_debug_info(DebugInformationRecorder* i) { _debug_info = i; }
319 
320   Dependencies* dependencies() { return _dependencies; }
321   void set_dependencies(Dependencies* d) { _dependencies = d; }

354     return _jvmti_can_access_local_variables || _jvmti_can_pop_frame;
355   }
356   bool  jvmti_can_hotswap_or_post_breakpoint() const { return _jvmti_can_hotswap_or_post_breakpoint; }
357   bool  jvmti_can_post_on_exceptions()         const { return _jvmti_can_post_on_exceptions; }
358   bool  jvmti_can_get_owned_monitor_info()     const { return _jvmti_can_get_owned_monitor_info; }
359   bool  jvmti_can_walk_any_space()             const { return _jvmti_can_walk_any_space; }
360 
361   // Cache DTrace flags
362   void  cache_dtrace_flags();
363   bool  dtrace_method_probes()   const { return _dtrace_method_probes; }
364   bool  dtrace_alloc_probes()    const { return _dtrace_alloc_probes; }
365 
366   // The compiler task which has created this env.
367   // May be useful to find out compile_id, comp_level, etc.
368   CompileTask* task() const { return _task; }
369 
370   // Handy forwards to the task:
371   int comp_level();   // task()->comp_level()
372   int compile_id();  // task()->compile_id()
373 
374   // Register method loaded from AOT code cache
375   void register_aot_method(JavaThread* thread,
376                            ciMethod* target,
377                            AbstractCompiler* compiler,
378                            nmethod* archived_nm,
379                            address reloc_data,
380                            GrowableArray<Handle>& oop_list,
381                            GrowableArray<Metadata*>& metadata_list,
382                            ImmutableOopMapSet* oopmaps,
383                            address immutable_data,
384                            GrowableArray<Handle>& reloc_imm_oop_list,
385                            GrowableArray<Metadata*>& reloc_imm_metadata_list,
386 #ifndef PRODUCT
387                            AsmRemarks& asm_remarks,
388                            DbgStrings& dbg_strings,
389 #endif /* PRODUCT */
390                            AOTCodeReader* aot_code_reader);
391 
392   // Register the result of a compilation.
393   void register_method(ciMethod*                 target,
394                        int                       entry_bci,
395                        CodeOffsets*              offsets,
396                        int                       orig_pc_offset,
397                        CodeBuffer*               code_buffer,
398                        int                       frame_words,
399                        OopMapSet*                oop_map_set,
400                        ExceptionHandlerTable*    handler_table,
401                        ImplicitExceptionTable*   inc_table,
402                        AbstractCompiler*         compiler,
403                        bool                      has_clinit_barriers,
404                        bool                      for_preload,
405                        bool                      has_unsafe_access,
406                        bool                      has_wide_vectors,
407                        bool                      has_monitors,
408                        bool                      has_scoped_access,
409                        int                       immediate_oops_patched,
410                        bool                      install_code,
411                        AOTCodeEntry*             entry = nullptr);
412 
413   // Access to certain well known ciObjects.
414 #define VM_CLASS_FUNC(name, ignore_s) \
415   ciInstanceKlass* name() { \
416     return _##name;\
417   }
418   VM_CLASSES_DO(VM_CLASS_FUNC)
419 #undef VM_CLASS_FUNC
420 
421   ciInstance* NullPointerException_instance() {
422     assert(_NullPointerException_instance != nullptr, "initialization problem");
423     return _NullPointerException_instance;
424   }
425   ciInstance* ArithmeticException_instance() {
426     assert(_ArithmeticException_instance != nullptr, "initialization problem");
427     return _ArithmeticException_instance;
428   }
429   ciInstance* ArrayIndexOutOfBoundsException_instance() {
430     assert(_ArrayIndexOutOfBoundsException_instance != nullptr, "initialization problem");
431     return _ArrayIndexOutOfBoundsException_instance;

481 
482   // Notice that a method has been inlined in the current compile;
483   // used only for statistics.
484   void notice_inlined_method(ciMethod* method);
485 
486   // Total number of bytecodes in inlined methods in this compile
487   int num_inlined_bytecodes() const;
488 
489   // Output stream for logging compilation info.
490   CompileLog* log() { return _log; }
491   void set_log(CompileLog* log) { _log = log; }
492 
493   void record_failure(const char* reason);      // Record failure and report later
494   void report_failure(const char* reason);      // Report failure immediately
495   void record_method_not_compilable(const char* reason, bool all_tiers = false);
496   void record_out_of_memory_failure();
497 
498   // RedefineClasses support
499   void metadata_do(MetadataClosure* f) { _factory->metadata_do(f); }
500 
501 private:
502   AOTCodeEntry* _aot_clinit_barriers_entry;
503 
504 public:
505   void  set_aot_clinit_barriers_entry(AOTCodeEntry* entry) { _aot_clinit_barriers_entry = entry; }
506   AOTCodeEntry* aot_clinit_barriers_entry()          const { return _aot_clinit_barriers_entry; }
507 
508   // Replay support
509 private:
510   static int klass_compare(const InstanceKlass* const &ik1, const InstanceKlass* const &ik2) {
511     if (ik1 > ik2) {
512       return 1;
513     } else if (ik1 < ik2) {
514       return -1;
515     } else {
516       return 0;
517     }
518   }
519   bool dyno_loc(const InstanceKlass* ik, const char *&loc) const;
520   void set_dyno_loc(const InstanceKlass* ik);
521   void record_best_dyno_loc(const InstanceKlass* ik);
522   bool print_dyno_loc(outputStream* out, const InstanceKlass* ik) const;
523 
524   GrowableArray<const InstanceKlass*>* _dyno_klasses;
525   GrowableArray<const char *>*         _dyno_locs;
526 
527 #define MAX_DYNO_NAME_LENGTH 1024

532   void dump_replay_data(int compile_id);
533   void dump_inline_data(int compile_id);
534   void dump_replay_data(outputStream* out);
535   void dump_replay_data_unsafe(outputStream* out);
536   void dump_replay_data_helper(outputStream* out);
537   void dump_compile_data(outputStream* out);
538   void dump_replay_data_version(outputStream* out);
539 
540   const char *dyno_name(const InstanceKlass* ik) const;
541   const char *replay_name(const InstanceKlass* ik) const;
542   const char *replay_name(ciKlass* i) const;
543 
544   void record_lambdaform(Thread* thread, oop obj);
545   void record_member(Thread* thread, oop obj);
546   void record_mh(Thread* thread, oop obj);
547   void record_call_site_obj(Thread* thread, oop obj);
548   void record_call_site_method(Thread* thread, Method* adapter);
549   void process_invokedynamic(const constantPoolHandle &cp, int index, JavaThread* thread);
550   void process_invokehandle(const constantPoolHandle &cp, int index, JavaThread* thread);
551   void find_dynamic_call_sites();
552 
553   bool is_precompiled();
554   bool is_fully_initialized(InstanceKlass* ik);
555   InstanceKlass::ClassState compute_init_state_for_precompiled(InstanceKlass* ik);
556 };
557 
558 #endif // SHARE_CI_CIENV_HPP
< prev index next >