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 nmethod* 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 AOTCodeReader* aot_code_reader);
387
388 // Register the result of a compilation.
389 void register_method(ciMethod* target,
390 int entry_bci,
391 CodeOffsets* offsets,
392 int orig_pc_offset,
393 CodeBuffer* code_buffer,
394 int frame_words,
395 OopMapSet* oop_map_set,
396 ExceptionHandlerTable* handler_table,
397 ImplicitExceptionTable* inc_table,
398 AbstractCompiler* compiler,
399 bool has_clinit_barriers,
400 bool for_preload,
401 bool has_unsafe_access,
402 bool has_wide_vectors,
403 bool has_monitors,
404 bool has_scoped_access,
405 int immediate_oops_patched,
406 bool install_code,
407 AOTCodeEntry* entry = nullptr);
408
409 // Access to certain well known ciObjects.
410 #define VM_CLASS_FUNC(name, ignore_s) \
411 ciInstanceKlass* name() { \
412 return _##name;\
413 }
414 VM_CLASSES_DO(VM_CLASS_FUNC)
415 #undef VM_CLASS_FUNC
416
417 ciInstance* NullPointerException_instance() {
418 assert(_NullPointerException_instance != nullptr, "initialization problem");
419 return _NullPointerException_instance;
420 }
421 ciInstance* ArithmeticException_instance() {
422 assert(_ArithmeticException_instance != nullptr, "initialization problem");
423 return _ArithmeticException_instance;
424 }
425 ciInstance* ArrayIndexOutOfBoundsException_instance() {
426 assert(_ArrayIndexOutOfBoundsException_instance != nullptr, "initialization problem");
427 return _ArrayIndexOutOfBoundsException_instance;
477
478 // Notice that a method has been inlined in the current compile;
479 // used only for statistics.
480 void notice_inlined_method(ciMethod* method);
481
482 // Total number of bytecodes in inlined methods in this compile
483 int num_inlined_bytecodes() const;
484
485 // Output stream for logging compilation info.
486 CompileLog* log() { return _log; }
487 void set_log(CompileLog* log) { _log = log; }
488
489 void record_failure(const char* reason); // Record failure and report later
490 void report_failure(const char* reason); // Report failure immediately
491 void record_method_not_compilable(const char* reason, bool all_tiers = false);
492 void record_out_of_memory_failure();
493
494 // RedefineClasses support
495 void metadata_do(MetadataClosure* f) { _factory->metadata_do(f); }
496
497 private:
498 AOTCodeEntry* _aot_clinit_barriers_entry;
499
500 public:
501 void set_aot_clinit_barriers_entry(AOTCodeEntry* entry) { _aot_clinit_barriers_entry = entry; }
502 AOTCodeEntry* aot_clinit_barriers_entry() const { return _aot_clinit_barriers_entry; }
503
504 // Replay support
505 private:
506 static int klass_compare(const InstanceKlass* const &ik1, const InstanceKlass* const &ik2) {
507 if (ik1 > ik2) {
508 return 1;
509 } else if (ik1 < ik2) {
510 return -1;
511 } else {
512 return 0;
513 }
514 }
515 bool dyno_loc(const InstanceKlass* ik, const char *&loc) const;
516 void set_dyno_loc(const InstanceKlass* ik);
517 void record_best_dyno_loc(const InstanceKlass* ik);
518 bool print_dyno_loc(outputStream* out, const InstanceKlass* ik) const;
519
520 GrowableArray<const InstanceKlass*>* _dyno_klasses;
521 GrowableArray<const char *>* _dyno_locs;
522
523 #define MAX_DYNO_NAME_LENGTH 1024
528 void dump_replay_data(int compile_id);
529 void dump_inline_data(int compile_id);
530 void dump_replay_data(outputStream* out);
531 void dump_replay_data_unsafe(outputStream* out);
532 void dump_replay_data_helper(outputStream* out);
533 void dump_compile_data(outputStream* out);
534 void dump_replay_data_version(outputStream* out);
535
536 const char *dyno_name(const InstanceKlass* ik) const;
537 const char *replay_name(const InstanceKlass* ik) const;
538 const char *replay_name(ciKlass* i) const;
539
540 void record_lambdaform(Thread* thread, oop obj);
541 void record_member(Thread* thread, oop obj);
542 void record_mh(Thread* thread, oop obj);
543 void record_call_site_obj(Thread* thread, oop obj);
544 void record_call_site_method(Thread* thread, Method* adapter);
545 void process_invokedynamic(const constantPoolHandle &cp, int index, JavaThread* thread);
546 void process_invokehandle(const constantPoolHandle &cp, int index, JavaThread* thread);
547 void find_dynamic_call_sites();
548
549 bool is_precompiled();
550 bool is_fully_initialized(InstanceKlass* ik);
551 InstanceKlass::ClassState compute_init_state_for_precompiled(InstanceKlass* ik);
552 };
553
554 #endif // SHARE_CI_CIENV_HPP
|