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