0N/A/*
1879N/A * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#ifndef SHARE_VM_CODE_DEBUGINFOREC_HPP
1879N/A#define SHARE_VM_CODE_DEBUGINFOREC_HPP
1879N/A
1879N/A#include "ci/ciClassList.hpp"
1879N/A#include "ci/ciInstanceKlass.hpp"
1879N/A#include "ci/ciMethod.hpp"
1879N/A#include "code/debugInfo.hpp"
1879N/A#include "code/location.hpp"
1879N/A#include "code/pcDesc.hpp"
1879N/A#include "compiler/oopMap.hpp"
1879N/A#include "oops/oop.hpp"
1879N/A#include "utilities/growableArray.hpp"
1879N/A
0N/A//** The DebugInformationRecorder collects debugging information
0N/A// for a compiled method.
0N/A// Debugging information is used for:
0N/A// - garbage collecting compiled frames
0N/A// - stack tracing across compiled frames
0N/A// - deoptimizating compiled frames
0N/A//
0N/A// The implementation requires the compiler to use the recorder
0N/A// in the following order:
0N/A// 1) Describe debug information for safepoints at increasing addresses.
0N/A// a) Add safepoint entry (use add_safepoint or add_non_safepoint)
0N/A// b) Describe scopes for that safepoint
0N/A// - create locals if needed (use create_scope_values)
0N/A// - create expressions if needed (use create_scope_values)
0N/A// - create monitor stack if needed (use create_monitor_values)
0N/A// - describe scope (use describe_scope)
0N/A// "repeat last four steps for all scopes"
0N/A// "outer most scope first and inner most scope last"
0N/A// NB: nodes from create_scope_values and create_locations
0N/A// can be reused for simple sharing.
0N/A// - mark the end of the scopes (end_safepoint or end_non_safepoint)
0N/A// 2) Use oop_size, data_size, pcs_size to create the nmethod and
0N/A// finally migrate the debugging information into the nmethod
0N/A// by calling copy_to.
0N/A
0N/Aclass DebugToken; // Opaque datatype for stored:
0N/A // - GrowableArray<ScopeValue*>
0N/A // - GrowableArray<MonitorValue*>
0N/A
0N/A// Alias for InvocationEntryBci.
0N/A// Both constants are used for a pseudo-BCI which refers
0N/A// to the state just _before_ a method is entered.
0N/A// SynchronizationEntryBCI is used where the emphasis
0N/A// is on the implicit monitorenter of a synchronized method.
0N/Aconst int SynchronizationEntryBCI = InvocationEntryBci;
0N/A
0N/Aclass DIR_Chunk; // private class, a nugget of collected information
0N/A
0N/Aclass DebugInformationRecorder: public ResourceObj {
0N/A public:
0N/A // constructor
0N/A DebugInformationRecorder(OopRecorder* oop_recorder);
0N/A
0N/A // adds an oopmap at a specific offset
0N/A void add_oopmap(int pc_offset, OopMap* map);
0N/A
0N/A // adds a jvm mapping at pc-offset, for a safepoint only
0N/A void add_safepoint(int pc_offset, OopMap* map);
0N/A
0N/A // adds a jvm mapping at pc-offset, for a non-safepoint (profile point)
0N/A void add_non_safepoint(int pc_offset);
0N/A
0N/A // Describes debugging information for a scope at the given pc_offset.
0N/A // Calls must be in non-decreasing order of pc_offset.
0N/A // If there are several calls at a single pc_offset,
0N/A // then they occur in the same order as they were performed by the JVM,
0N/A // with the most recent (innermost) call being described last.
0N/A // For a safepoint, the pc_offset must have been mentioned
0N/A // previously by add_safepoint.
0N/A // Otherwise, the pc_offset must have been mentioned previously
0N/A // by add_non_safepoint, and the locals, expressions, and monitors
0N/A // must all be null.
0N/A void describe_scope(int pc_offset,
0N/A ciMethod* method,
0N/A int bci,
900N/A bool reexecute,
1135N/A bool is_method_handle_invoke = false,
1253N/A bool return_oop = false,
0N/A DebugToken* locals = NULL,
0N/A DebugToken* expressions = NULL,
0N/A DebugToken* monitors = NULL);
0N/A
0N/A
0N/A void dump_object_pool(GrowableArray<ScopeValue*>* objects);
0N/A
0N/A // This call must follow every add_safepoint,
0N/A // after any intervening describe_scope calls.
0N/A void end_safepoint(int pc_offset) { end_scopes(pc_offset, true); }
0N/A void end_non_safepoint(int pc_offset) { end_scopes(pc_offset, false); }
0N/A
0N/A // helper fuctions for describe_scope to enable sharing
0N/A DebugToken* create_scope_values(GrowableArray<ScopeValue*>* values);
0N/A DebugToken* create_monitor_values(GrowableArray<MonitorValue*>* monitors);
0N/A
0N/A // returns the size of the generated scopeDescs.
0N/A int data_size();
0N/A int pcs_size();
0N/A int oop_size() { return oop_recorder()->oop_size(); }
0N/A
0N/A // copy the generated debugging information to nmethod
0N/A void copy_to(nmethod* nm);
0N/A
0N/A // verifies the debug information
0N/A void verify(const nmethod* code);
0N/A
0N/A static void print_statistics() PRODUCT_RETURN;
0N/A
0N/A // Method for setting oopmaps to temporarily preserve old handling of oopmaps
0N/A OopMapSet *_oopmaps;
0N/A void set_oopmaps(OopMapSet *oopmaps) { _oopmaps = oopmaps; }
0N/A
0N/A OopRecorder* oop_recorder() { return _oop_recorder; }
0N/A
0N/A int last_pc_offset() { return last_pc()->pc_offset(); }
0N/A
0N/A bool recording_non_safepoints() { return _recording_non_safepoints; }
0N/A
0N/A private:
0N/A friend class ScopeDesc;
0N/A friend class vframeStreamCommon;
0N/A friend class DIR_Chunk;
0N/A
0N/A // True if we are recording non-safepoint scopes.
0N/A // This flag is set if DebugNonSafepoints is true, or if
0N/A // JVMTI post_compiled_method_load events are enabled.
0N/A const bool _recording_non_safepoints;
0N/A
0N/A DebugInfoWriteStream* _stream;
0N/A
0N/A DebugInfoWriteStream* stream() const { return _stream; }
0N/A
0N/A OopRecorder* _oop_recorder;
0N/A
0N/A // Scopes that have been described so far.
0N/A GrowableArray<DIR_Chunk*>* _all_chunks;
0N/A GrowableArray<DIR_Chunk*>* _shared_chunks;
0N/A DIR_Chunk* _next_chunk;
0N/A DIR_Chunk* _next_chunk_limit;
0N/A
0N/A#ifdef ASSERT
0N/A enum { rs_null, rs_safepoint, rs_non_safepoint };
0N/A int _recording_state;
0N/A#endif
0N/A
0N/A PcDesc* _pcs;
0N/A int _pcs_size;
0N/A int _pcs_length;
0N/A // Note: Would use GrowableArray<PcDesc>, but structs are not supported.
0N/A
0N/A // PC of most recent real safepoint before the current one,
0N/A // updated after end_scopes.
0N/A int _prev_safepoint_pc;
0N/A
0N/A PcDesc* last_pc() {
0N/A guarantee(_pcs_length > 0, "a safepoint must be declared already");
0N/A return &_pcs[_pcs_length-1];
0N/A }
0N/A PcDesc* prev_pc() {
0N/A guarantee(_pcs_length > 1, "a safepoint must be declared already");
0N/A return &_pcs[_pcs_length-2];
0N/A }
0N/A void add_new_pc_offset(int pc_offset);
0N/A void end_scopes(int pc_offset, bool is_safepoint);
0N/A
0N/A int serialize_monitor_values(GrowableArray<MonitorValue*>* monitors);
0N/A int serialize_scope_values(GrowableArray<ScopeValue*>* values);
0N/A int find_sharable_decode_offset(int stream_offset);
0N/A
0N/A public:
0N/A enum { serialized_null = 0 };
0N/A};
1879N/A
1879N/A#endif // SHARE_VM_CODE_DEBUGINFOREC_HPP