f496e538f4
This is the next step towards preventing compiler from directly peeking into runtime and instead interact with runtime through a well defined surface. The goal of the refactoring to locate all places where compiler accesses some runtime information and partion those accesses into two categories: - creating objects in the host runtime (e.g. allocating strings, numbers, etc) during compilation; - accessing properties of the target runtime (e.g. offsets of fields) to embed those into the generated code; This change introduces dart::compiler and dart::compiler::target namespaces. All code in the compiler will gradually be moved into dart::compiler namespace. One of the motivations for this change is to be able to prevent access to globally defined host constants like kWordSize by shadowing them in the dart::compiler namespace. The nested namespace dart::compiler::target hosts all information about target runtime that compiler could access, e.g. compiler::target::kWordSize defines word size of the target which will eventually be made different from the host kWordSize (defined by dart::kWordSize). The API for compiler to runtime interaction is placed into compiler_api.h. Note that we still permit runtime to access compiler internals directly - this is not going to be decoupled as part of this work. Issue https://github.com/dart-lang/sdk/issues/31709 Change-Id: If4396d295879391becfa6c38d4802bbff81f5b20 Reviewed-on: https://dart-review.googlesource.com/c/90242 Commit-Queue: Vyacheslav Egorov <vegorov@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com>
101 lines
2.3 KiB
C++
101 lines
2.3 KiB
C++
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#ifndef RUNTIME_VM_LOG_H_
|
|
#define RUNTIME_VM_LOG_H_
|
|
|
|
#include "vm/allocation.h"
|
|
#include "vm/growable_array.h"
|
|
#include "vm/os.h"
|
|
|
|
namespace dart {
|
|
|
|
class Isolate;
|
|
class LogBlock;
|
|
|
|
#if defined(_MSC_VER)
|
|
#define THR_Print(format, ...) Log::Current()->Print(format, __VA_ARGS__)
|
|
#else
|
|
#define THR_Print(format, ...) Log::Current()->Print(format, ##__VA_ARGS__)
|
|
#endif
|
|
|
|
#define THR_VPrint(format, args) Log::Current()->VPrint(format, args)
|
|
|
|
typedef void (*LogPrinter)(const char* str, ...) PRINTF_ATTRIBUTE(1, 2);
|
|
|
|
class Log {
|
|
public:
|
|
explicit Log(LogPrinter printer = OS::PrintErr);
|
|
~Log();
|
|
|
|
static Log* Current();
|
|
|
|
// Append a formatted string to the log.
|
|
void Print(const char* format, ...) PRINTF_ATTRIBUTE(2, 3);
|
|
|
|
void VPrint(const char* format, va_list args);
|
|
|
|
// Flush and truncate the log. The log is flushed starting at cursor
|
|
// and truncated to cursor afterwards.
|
|
void Flush(const intptr_t cursor = 0);
|
|
|
|
// Clears the log.
|
|
void Clear();
|
|
|
|
// Current cursor.
|
|
intptr_t cursor() const;
|
|
|
|
// A logger that does nothing.
|
|
static Log* NoOpLog();
|
|
|
|
private:
|
|
void TerminateString();
|
|
void EnableManualFlush();
|
|
void DisableManualFlush(const intptr_t cursor);
|
|
|
|
// Returns true when flush is required.
|
|
bool ShouldFlush() const;
|
|
|
|
// Returns false if we should drop log messages related to 'isolate'.
|
|
static bool ShouldLogForIsolate(const Isolate* isolate);
|
|
|
|
static Log noop_log_;
|
|
LogPrinter printer_;
|
|
intptr_t manual_flush_;
|
|
MallocGrowableArray<char> buffer_;
|
|
|
|
friend class LogBlock;
|
|
friend class LogTestHelper;
|
|
DISALLOW_COPY_AND_ASSIGN(Log);
|
|
};
|
|
|
|
// Causes all log messages to be buffered until destructor is called.
|
|
// Can be nested.
|
|
class LogBlock : public StackResource {
|
|
public:
|
|
LogBlock(ThreadState* thread, Log* log)
|
|
: StackResource(thread), log_(log), cursor_(log->cursor()) {
|
|
Initialize();
|
|
}
|
|
|
|
LogBlock()
|
|
: StackResource(ThreadState::Current()),
|
|
log_(Log::Current()),
|
|
cursor_(Log::Current()->cursor()) {
|
|
Initialize();
|
|
}
|
|
|
|
~LogBlock();
|
|
|
|
private:
|
|
void Initialize();
|
|
|
|
Log* const log_;
|
|
const intptr_t cursor_;
|
|
};
|
|
|
|
} // namespace dart
|
|
|
|
#endif // RUNTIME_VM_LOG_H_
|