Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ install_manifest.txt
*.o
Makefile
pal/src/config.h
DbgController.js.h

# Generated by other tools
*.orig
Expand Down
3 changes: 2 additions & 1 deletion bin/ChakraCore/ChakraCoreShared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ void DummyJSRTCall()
JsRuntimeHandle *runtime;
JsRuntimeAttributes attr;
JsCreateRuntime(attr, nullptr, runtime);
JsDiagStartDebugging(runtime, nullptr, nullptr);
}
#endif

Expand All @@ -30,4 +31,4 @@ EXTERN_C BOOL WINAPI DllMain(HINSTANCE hmod, DWORD dwReason, PVOID pvReserved)
return TRUE;
}

static_assert(__LINE__ == 33, "You shouldn't add anything to this file or ChakraCoreDllFunc.cpp. Please consider again!");
static_assert(__LINE__ == 34, "You shouldn't add anything to this file or ChakraCoreDllFunc.cpp. Please consider again!");
4 changes: 2 additions & 2 deletions bin/ch/Debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ static const char controllerScript[] = {
'\0'
};
#else
static const char controllerScript[] = { '\0' };
#include "DbgController.js.h"
#endif

class Debugger
{
public:
Expand Down
63 changes: 63 additions & 0 deletions bin/ch/jstoc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env python
#-------------------------------------------------------------------------------------------------------
# Copyright (C) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
#-------------------------------------------------------------------------------------------------------

from __future__ import with_statement # py 2.5
import sys
import os

def print_usage():
print "jstoc tool"
print "creates a (const char array) from a javascript file."
print ""
print "usage: jstoc.py <js file path> <variable name>"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usage: jstoc.py [](start = 11, length = 15)

Output some more help message about what this script does?

sys.exit(1)

def convert():
if len(sys.argv) < 3:
print_usage()

js_file_name = sys.argv[1]
if os.path.isfile(js_file_name) == False:
print_usage()

h_file_name = js_file_name + '.h'

js_file_time = os.path.getmtime(js_file_name)
h_file_time = 0
if os.path.isfile(h_file_name):
h_file_time = os.path.getmtime(h_file_name)

str_header = "static const char " + sys.argv[2] + "[] = {\n"

# if header file is up to date and no update to jstoc.py since, skip..
if h_file_time < js_file_time or h_file_time < os.path.getmtime(sys.argv[0]):
with open(js_file_name, "rb") as js_file:
last_break = len(str_header) # skip first line
byte = js_file.read(1)
while byte:
str_header += str(ord(byte))
str_header += ","
# beautify a bit. limit column to ~80
column_check = (len(str_header) + 1) - last_break
if column_check > 5 and column_check % 80 < 5:
last_break = len(str_header) + 1
str_header += "\n"
else:
str_header += " "
byte = js_file.read(1)
str_header += "0\n};"

h_file = open(h_file_name, "w")
h_file.write(str_header)
h_file.close()
print "-- " + h_file_name + " is created"
else:
print "-- " + h_file_name + " is up to date. skipping."

if __name__ == '__main__':
sys.exit(convert())
else:
print("try without python")
7 changes: 7 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,13 @@ if [[ ${#_CXX} > 0 ]]; then
CC_PREFIX="-DCMAKE_CXX_COMPILER=$_CXX -DCMAKE_C_COMPILER=$_CC"
fi

# prepare DbgController.js.h
CH_DIR="${CHAKRACORE_DIR}/bin/ch"
"${CH_DIR}/jstoc.py" "${CH_DIR}/DbgController.js" controllerScript
if [[ $? != 0 ]]; then
exit 1
fi

build_directory="$CHAKRACORE_DIR/BuildLinux/${BUILD_TYPE:0}"
if [ ! -d "$build_directory" ]; then
SAFE_RUN `mkdir -p $build_directory`
Expand Down
6 changes: 3 additions & 3 deletions lib/Backend/NativeCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ NativeCodeGenerator::CodeGen(PageAllocator * pageAllocator, CodeGenWorkItem* wor
Func::Codegen(&jitArena, jitWorkItem, scriptContext->GetThreadContext(),
scriptContext, &jitWriteData, epInfo, nullptr, jitWorkItem->GetPolymorphicInlineCacheInfo(), allocators,
#if !FLOATVAR
pNumberAllocator,
pNumberAllocator,
#endif
codeGenProfiler, !foreground);
}
Expand Down Expand Up @@ -1548,7 +1548,7 @@ NativeCodeGenerator::CheckCodeGen(Js::ScriptFunction * function)

if(!nativeCodeGen->Processor()->PrioritizeJob(nativeCodeGen, entryPoint, function))
{
#ifdef ENABLE_SCRIPT_PROFILING
#if defined(ENABLE_SCRIPT_PROFILING) || defined(ENABLE_SCRIPT_DEBUGGING)
#define originalEntryPoint_IS_ProfileDeferredParsingThunk \
(originalEntryPoint == ProfileDeferredParsingThunk)
#else
Expand Down Expand Up @@ -2005,7 +2005,7 @@ NativeCodeGenerator::JobProcessed(JsUtil::Job *const job, const bool succeeded)
Assert(workItem->GetCodeAddress() != NULL);

uint loopNum = loopBodyCodeGen->GetJITData()->loopNumber;
functionBody->SetLoopBodyEntryPoint(loopBodyCodeGen->loopHeader, entryPoint, (Js::JavascriptMethod)workItem->GetCodeAddress(), loopNum);
functionBody->SetLoopBodyEntryPoint(loopBodyCodeGen->loopHeader, entryPoint, (Js::JavascriptMethod)workItem->GetCodeAddress(), loopNum);
entryPoint->SetCodeGenDone();
}
else
Expand Down
2 changes: 1 addition & 1 deletion lib/Common/BackendApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#define ProfileEntryThunk Js::ScriptContext::DebugProfileProbeThunk

#define DefaultDeferredParsingThunk Js::JavascriptFunction::DeferredParsingThunk
#ifdef ENABLE_SCRIPT_PROFILING
#if defined(ENABLE_SCRIPT_PROFILING) || defined(ENABLE_SCRIPT_DEBUGGING)
#define ProfileDeferredParsingThunk Js::ScriptContext::ProfileModeDeferredParsingThunk
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we use ProfileDeferredParsingThunk in debugging.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, the method itself doesn't receive any call but I've fixed it's impl. for xplat instead of adding even more ifdef checks etc.

#endif

Expand Down
7 changes: 4 additions & 3 deletions lib/Common/CommonDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@
#ifdef _WIN32
// dep: TIME_ZONE_INFORMATION, DaylightTimeHelper, Windows.Globalization
#define ENABLE_GLOBALIZATION
// dep: IDebugDocumentContext
#define ENABLE_SCRIPT_DEBUGGING
// dep: IActiveScriptProfilerCallback, IActiveScriptProfilerHeapEnum
#define ENABLE_SCRIPT_PROFILING
#ifndef __clang__
Expand All @@ -125,6 +123,9 @@
#define ENABLE_CUSTOM_ENTROPY
#endif

// dep: IDebugDocumentContext
#define ENABLE_SCRIPT_DEBUGGING

// GC features

// Concurrent and Partial GC are disabled on non-Windows builds
Expand Down Expand Up @@ -351,7 +352,7 @@
#if ENABLE_TTD
#define TTDAssert(C, M) { if(!(C)) TTDAbort_fatal_error(M); }
#else
#define TTDAssert(C, M)
#define TTDAssert(C, M)
#endif

#if ENABLE_TTD
Expand Down
11 changes: 11 additions & 0 deletions lib/Common/CommonPal.h
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,16 @@ void TryFinally(const TryFunc& tryFunc, const FinallyFunc& finallyFunc)
finallyFunc(hasException);
}

#ifdef DISABLE_SEH
#define __TRY_FINALLY_BEGIN TryFinally([&]()
#define __FINALLY , [&](bool /* hasException */)
#define __TRY_FINALLY_END );
#else
#define __TRY_FINALLY_BEGIN __try
#define __FINALLY __finally
#define __TRY_FINALLY_END
#endif

namespace PlatformAgnostic
{
__forceinline unsigned char _BitTestAndSet(LONG *_BitBase, int _BitPos)
Expand Down Expand Up @@ -690,3 +700,4 @@ namespace PlatformAgnostic
#include "PlatformAgnostic/SystemInfo.h"
#include "PlatformAgnostic/Thread.h"
#include "PlatformAgnostic/AssemblyCommon.h"
#include "PlatformAgnostic/Debugger.h"
5 changes: 4 additions & 1 deletion lib/Common/Memory/amd64/XDataAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ bool XDataAllocator::Initialize(void* segmentStart, void* segmentEnd)

XDataAllocator::~XDataAllocator()
{
current = nullptr;
ClearFreeList();
}

Expand All @@ -42,7 +43,8 @@ void XDataAllocator::Delete()
HeapDelete(this);
}

bool XDataAllocator::Alloc(ULONG_PTR functionStart, DWORD functionSize, ushort pdataCount, ushort xdataSize, SecondaryAllocation* allocation)
bool XDataAllocator::Alloc(ULONG_PTR functionStart, DWORD functionSize,
ushort pdataCount, ushort xdataSize, SecondaryAllocation* allocation)
{
XDataAllocation* xdata = static_cast<XDataAllocation*>(allocation);
Assert(start != nullptr);
Expand Down Expand Up @@ -107,6 +109,7 @@ void XDataAllocator::ClearFreeList()
{
entry = next;
next = entry->next;
entry->address = nullptr;
HeapDelete(entry);
}
this->freeList = NULL;
Expand Down
135 changes: 135 additions & 0 deletions lib/Common/PlatformAgnostic/Debugger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------

#ifndef RUNTIME_PLATFORM_AGNOSTIC_DEBUGGER
#define RUNTIME_PLATFORM_AGNOSTIC_DEBUGGER

#ifndef _WIN32

#define ACTIVPROF_E_PROFILER_PRESENT 0x0200
#define ACTIVPROF_E_PROFILER_ABSENT 0x0201
#define ACTIVPROF_E_UNABLE_TO_APPLY_ACTION 0x0202
#define PROFILER_TOKEN uint

typedef enum {
PROFILER_SCRIPT_TYPE_USER,
PROFILER_SCRIPT_TYPE_DYNAMIC,
PROFILER_SCRIPT_TYPE_NATIVE,
PROFILER_SCRIPT_TYPE_DOM
} PROFILER_SCRIPT_TYPE;

typedef enum {
PROFILER_EVENT_MASK_TRACE_SCRIPT_FUNCTION_CALL = 0x00000001,
PROFILER_EVENT_MASK_TRACE_NATIVE_FUNCTION_CALL = 0x00000002,
PROFILER_EVENT_MASK_TRACE_DOM_FUNCTION_CALL = 0x00000004,
PROFILER_EVENT_MASK_TRACE_ALL =
PROFILER_EVENT_MASK_TRACE_SCRIPT_FUNCTION_CALL |
PROFILER_EVENT_MASK_TRACE_NATIVE_FUNCTION_CALL,
PROFILER_EVENT_MASK_TRACE_ALL_WITH_DOM = PROFILER_EVENT_MASK_TRACE_ALL |
PROFILER_EVENT_MASK_TRACE_DOM_FUNCTION_CALL
} PROFILER_EVENT_MASK;

interface IEnumDebugCodeContexts : IUnknown
{
// HRESULT Next( ..

// HRESULT Skip( ..

// HRESULT Reset();

// HRESULT Clone( ..
};

interface IDebugDocumentInfo : IUnknown
{
HRESULT GetName(char* dn, BSTR *name);

HRESULT GetDocumentClassId(CLSID *dclsid);
};

interface IDebugDocument : IDebugDocumentInfo
{
};

interface IDebugDocumentContext : IUnknown
{
HRESULT GetDocument(IDebugDocument **doc);

HRESULT EnumCodeContexts(IEnumDebugCodeContexts **dctx);
};

class IActiveScriptProfilerCallback
{
public:
HRESULT Initialize(DWORD ctx)
{
return S_OK;
}

HRESULT Shutdown(HRESULT _)
{
return S_OK;
}

HRESULT Release()
{
return S_OK;
}

HRESULT QueryInterface(IActiveScriptProfilerCallback **_)
{
return S_OK;
}

HRESULT ScriptCompiled(PROFILER_TOKEN scriptId, PROFILER_SCRIPT_TYPE type, IUnknown *ctx)
{
return S_OK;
}

HRESULT FunctionCompiled(PROFILER_TOKEN functionId, PROFILER_TOKEN scriptId,
const WCHAR* pwszFunctionName, const WCHAR* pwszFunctionNameHint, IUnknown *ctx)
{
return S_OK;
}

HRESULT OnFunctionEnter(PROFILER_TOKEN scriptId, PROFILER_TOKEN functionId)
{
return S_OK;
}

HRESULT OnFunctionExit(PROFILER_TOKEN scriptId, PROFILER_TOKEN functionId)
{
return S_OK;
}

// IActiveScriptProfilerCallback2
HRESULT OnFunctionEnterByName(const WCHAR *functionName, PROFILER_SCRIPT_TYPE _)
{
return S_OK;
}

HRESULT OnFunctionExitByName(const WCHAR *functionName, PROFILER_SCRIPT_TYPE _)
{
return S_OK;
}

// IActiveScriptProfilerCallback3
HRESULT AddRef()
{
return S_OK;
}

HRESULT SetWebWorkerId(PROFILER_TOKEN _)
{
return S_OK;
}
};

#define IActiveScriptProfilerCallback2 IActiveScriptProfilerCallback
#define IActiveScriptProfilerCallback3 IActiveScriptProfilerCallback

#endif // !_WIN32

#endif // RUNTIME_PLATFORM_AGNOSTIC_DEBUGGER
4 changes: 2 additions & 2 deletions lib/Jsrt/Jsrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3454,9 +3454,9 @@ CHAKRA_API JsTTDStart()

Js::ScriptContext* scriptContext = currentContext->GetScriptContext();
TTDAssert(scriptContext->IsTTDRecordOrReplayModeEnabled(), "Need to create in TTD Record Mode.");

#if ENABLE_NATIVE_CODEGEN
TTDAssert(JITManager::GetJITManager() == nullptr || !JITManager::GetJITManager()->IsOOPJITEnabled(), "TTD cannot run with OOP JIT yet!!!");

#endif
return GlobalAPIWrapper_NoRecord([&]() -> JsErrorCode
{
if(scriptContext->IsTTDRecordModeEnabled())
Expand Down
4 changes: 2 additions & 2 deletions lib/Runtime/Base/CrossSite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,14 @@ namespace Js

bool CrossSite::IsThunk(JavascriptMethod thunk)
{
#ifdef ENABLE_SCRIPT_PROFILING
#if defined(ENABLE_SCRIPT_PROFILING) || defined(ENABLE_SCRIPT_DEBUGGING)
return (thunk == CrossSite::ProfileThunk || thunk == CrossSite::DefaultThunk);
#else
return (thunk == CrossSite::DefaultThunk);
#endif
}

#ifdef ENABLE_SCRIPT_PROFILING
#if defined(ENABLE_SCRIPT_PROFILING) || defined(ENABLE_SCRIPT_DEBUGGING)
Var CrossSite::ProfileThunk(RecyclableObject* callable, CallInfo callInfo, ...)
{
JavascriptFunction* function = JavascriptFunction::FromVar(callable);
Expand Down
Loading