Files
UnrealEngineUWP/Engine/Source/Developer/Windows/LiveCoding/Private/External/LC_ClientCommandActions.cpp

241 lines
6.6 KiB
C++
Raw Normal View History

// Copyright 2011-2020 Molecular Matters GmbH, all rights reserved.
// BEGIN EPIC MOD
//#include PCH_INCLUDE
// END EPIC MOD
#include "LC_ClientCommandActions.h"
#include "LC_ClientUserCommandThread.h"
#include "LC_DuplexPipe.h"
#include "LC_SyncPoint.h"
#include "LC_Executable.h"
#include "LC_Event.h"
#include "LC_Process.h"
// BEGIN EPIC MOD
#include "LC_Logging.h"
// END EPIC MOD
bool actions::RegisterProcessFinished::Execute(const CommandType* command, const DuplexPipe* pipe, void* context, const void*, size_t)
{
bool* successfullyRegisteredProcess = static_cast<bool*>(context);
*successfullyRegisteredProcess = command->success;
pipe->SendAck();
// don't continue execution
return false;
}
bool actions::EnableModulesFinished::Execute(const CommandType* command, const DuplexPipe* pipe, void*, const void*, size_t)
{
Event* event = static_cast<Event*>(command->token);
event->Signal();
pipe->SendAck();
return false;
}
bool actions::DisableModulesFinished::Execute(const CommandType* command, const DuplexPipe* pipe, void*, const void*, size_t)
{
Event* event = static_cast<Event*>(command->token);
event->Signal();
pipe->SendAck();
return false;
}
bool actions::EnterSyncPoint::Execute(const CommandType*, const DuplexPipe* pipe, void*, const void*, size_t)
{
syncPoint::Enter();
pipe->SendAck();
return true;
}
bool actions::LeaveSyncPoint::Execute(const CommandType*, const DuplexPipe* pipe, void*, const void*, size_t)
{
syncPoint::Leave();
pipe->SendAck();
return true;
}
bool actions::CallHooks::Execute(const CommandType* command, const DuplexPipe* pipe, void*, const void* payload, size_t)
{
switch (command->type)
{
case hook::Type::PREPATCH:
hook::CallHooksInRange<hook::PrepatchFunction>(command->rangeBegin, command->rangeEnd);
break;
case hook::Type::POSTPATCH:
hook::CallHooksInRange<hook::PostpatchFunction>(command->rangeBegin, command->rangeEnd);
break;
case hook::Type::COMPILE_START:
hook::CallHooksInRange<hook::CompileStartFunction>(command->rangeBegin, command->rangeEnd);
break;
case hook::Type::COMPILE_SUCCESS:
hook::CallHooksInRange<hook::CompileSuccessFunction>(command->rangeBegin, command->rangeEnd);
break;
case hook::Type::COMPILE_ERROR:
hook::CallHooksInRange<hook::CompileErrorFunction>(command->rangeBegin, command->rangeEnd);
break;
case hook::Type::COMPILE_ERROR_MESSAGE:
hook::CallHooksInRange<hook::CompileErrorMessageFunction>(command->rangeBegin, command->rangeEnd, static_cast<const wchar_t*>(payload));
break;
}
pipe->SendAck();
return true;
}
// BEGIN EPIC MOD - Support for UE debug visualizers
FName optimizations and improvements Encoding improvements * New hash table implementation --- Move away from 16-bit hashes since we need more than 64k buckets to hold 2M entries efficiently --- Change to CityHash64, which is faster and stronger --- Remove hardcoded max limit * NAME_INDEX changed from contigouos int to monotonically increasing int --- Opens up for future deduplication schemes that are better than number suffix dedup. --- Saves some memory since we don't need to maintain a contiguous array --- Typed up to cause compile errors when used as integer directly * Avoid touching data repeatedly, normal path only does single hash of data * New constructor that allows supplying string length up front * Avoid dynamic allocations in string conversions >= 128 characters * Avoid extra copying when splitting numbers * More efficient IsPureAnsi check * Only do one global lazy initialization call instead of multiple * Switch to faster RW locks * Switch from single lock to sharded hash map with separate locks * Memory optimizations that reduces per entry overhead: 4 bytes slots, 2 byte headers and don't store null terminator Improved API & documentation * Document that IsValid() rarely makes sense * Hide global state such as GetNames() * Reduce amount of implementation details visible in header * NameTypes.h size down by ~1/3 while adding documentation, stronger type safety and new APIs Future possibilities * Memory savings: Removing public NAME_INDEX and global FName array allows using the 32-bit FNameEntryId for arbitrary deduplication schemes. This can save both actual stored strings memory by deduplication and half the size of FName instances from 8B to 4B in shipping / test configs by removing the number part. * Implementation can be tweaked further, for instance could persist 32-bit slot index hash inside slot to increase encoding performance in development / debug at the cost of memory. Perf & mem results for internal project: * Editor startup wall time: 12% speedup, 22.0s -> 19.5s --- Warm disk and asset registry cache --- Some gains from nametable serialization improvements --- Some of these gains might be from orthogonal asset discovery optimizations * Win64 Test Client memory usage with ~400k names: 30.3Mb -> 22.2Mb #rb steve.robb, pj.kack #jira UE-59973 [CL 5774657 by Johan Torp in Dev-Core branch]
2019-04-08 11:29:35 -04:00
extern uint8** GNameBlocksDebug;
class FChunkedFixedUObjectArray;
extern FChunkedFixedUObjectArray*& GObjectArrayForDebugVisualizers;
namespace UE::Core{ struct FVisualizerDebuggingState; }
extern UE::Core::FVisualizerDebuggingState*& GDebuggingState;
// END EPIC MOD
// BEGIN EPIC MOD - Support for object reinstancing. We need to call a global post-patch handler, rather than just getting individual callbacks for modified modules.
extern void LiveCodingBeginPatch();
// END EPIC MOD
// BEGIN EPIC MOD - Notification that compilation has finished
extern void LiveCodingEndCompile();
// END EPIC MOD
// BEGIN EPIC MOD
extern void LiveCodingPreCompile();
extern void LiveCodingPostCompile(commands::PostCompileResult postCompileResult);
extern void LiveCodingTriggerReload();
// END EPIC MOD
bool actions::LoadPatch::Execute(const CommandType* command, const DuplexPipe* pipe, void*, const void*, size_t)
{
// load library into this process
HMODULE module = ::LoadLibraryW(command->path);
// BEGIN EPIC MOD - Support for UE debug visualizers
if (module != nullptr)
{
typedef void InitNatvisHelpersFunc(uint8** NameTable, FChunkedFixedUObjectArray* ObjectArray, UE::Core::FVisualizerDebuggingState* DebuggingState);
InitNatvisHelpersFunc* InitNatvisHelpers = (InitNatvisHelpersFunc*)(void*)GetProcAddress(module, "InitNatvisHelpers");
if (InitNatvisHelpers != nullptr)
{
(*InitNatvisHelpers)(GNameBlocksDebug, GObjectArrayForDebugVisualizers, GDebuggingState);
}
}
// END EPIC MOD
// BEGIN EPIC MOD - Support for object reinstancing. We need to call a global post-patch handler, rather than just getting individual callbacks for modified modules.
LiveCoding Re-instancing LIMITATIONS: 1) Re-instancing will only update UClass instance data. 2) Adding and removing properties should only be done towards the end of a class or structure and can not be followed by complex data types. 3) Adding and removing properties from a base class should not be done if a derived class contains complex data types. KNOWN ISSUES: 1) Changes to enumerations and structures will not be reflected in existing blueprints. However, adding new nodes to the blueprint will show the updated enumeration or structure. 2) If a class contains an enumeration or structure as a member, the class will not be re-instanced if enumeration or structure is changed. CHANGES: 1) LiveCodingServer 1a) Modified to always execute certain static instances during load. 1b) Modified to exclude the _Statics static structures to avoid patching to old copies. 2) Added support for LiveCoding reinstancing 2a) Refactored deferred registration system for UClass, UEnum, and UScriptStruct to use a common system that works for normal game, hot reload and live coding. 2b) Type specific version check data is possible (i.e. enum doesn't have a size) 2c) Single registration static for UClass 2d) Single registration class for all types that is just a blind forward to API. 2e) Static and dynamic registrations use different API entry points to avoid having overloaded argument lists that just apply to one or the other. 2f) Shims for older API 3) New common "Reload" system to avoid using HotReload code. 3a) Support common delegates regardless of who is reloading/reinstancing. 3b) Re-instancing code moved from HotReload to Kismet2 (where the bulk of the re-instance code already existed). 3c) Modified PyWrapper to use new helper class instead of depending on HotRelaod 3d) Added WITH_RELOAD which is defined if HotReload or LiveCoding is enabled. 3e) Modifed existing code to use new #define and delegates. Robert did the review on the changes covered by Part 2. Remaining changes are all straightforward. #rb robert.manuszewski #jira UE-74493 [CL 15736777 by Tim Smith in ue5-main branch]
2021-03-18 08:13:59 -04:00
LiveCodingBeginPatch();
// END EPIC MOD
pipe->SendAck();
// send back command with module info
pipe->SendCommandAndWaitForAck(commands::LoadPatchInfo { module }, nullptr, 0u);
return true;
}
bool actions::UnloadPatch::Execute(const CommandType* command, const DuplexPipe* pipe, void*, const void*, size_t)
{
// unload library from this process
::FreeLibrary(command->module);
pipe->SendAck();
return true;
}
bool actions::CallEntryPoint::Execute(const CommandType* command, const DuplexPipe* pipe, void*, const void*, size_t)
{
executable::CallDllEntryPoint(command->moduleBase, command->entryPointRva);
pipe->SendAck();
return true;
}
bool actions::LogOutput::Execute(const CommandType*, const DuplexPipe* pipe, void*, const void* payload, size_t)
{
// BEGIN EPIC MOD
Logging::LogNoFormat<Logging::Channel::USER>(static_cast<const wchar_t*>(payload));
// END EPIC MOD
pipe->SendAck();
return true;
}
bool actions::CompilationFinished::Execute(const CommandType*, const DuplexPipe* pipe, void*, const void*, size_t)
{
pipe->SendAck();
// BEGIN EPIC MOD - Notification that compilation has finished
LiveCoding Re-instancing LIMITATIONS: 1) Re-instancing will only update UClass instance data. 2) Adding and removing properties should only be done towards the end of a class or structure and can not be followed by complex data types. 3) Adding and removing properties from a base class should not be done if a derived class contains complex data types. KNOWN ISSUES: 1) Changes to enumerations and structures will not be reflected in existing blueprints. However, adding new nodes to the blueprint will show the updated enumeration or structure. 2) If a class contains an enumeration or structure as a member, the class will not be re-instanced if enumeration or structure is changed. CHANGES: 1) LiveCodingServer 1a) Modified to always execute certain static instances during load. 1b) Modified to exclude the _Statics static structures to avoid patching to old copies. 2) Added support for LiveCoding reinstancing 2a) Refactored deferred registration system for UClass, UEnum, and UScriptStruct to use a common system that works for normal game, hot reload and live coding. 2b) Type specific version check data is possible (i.e. enum doesn't have a size) 2c) Single registration static for UClass 2d) Single registration class for all types that is just a blind forward to API. 2e) Static and dynamic registrations use different API entry points to avoid having overloaded argument lists that just apply to one or the other. 2f) Shims for older API 3) New common "Reload" system to avoid using HotReload code. 3a) Support common delegates regardless of who is reloading/reinstancing. 3b) Re-instancing code moved from HotReload to Kismet2 (where the bulk of the re-instance code already existed). 3c) Modified PyWrapper to use new helper class instead of depending on HotRelaod 3d) Added WITH_RELOAD which is defined if HotReload or LiveCoding is enabled. 3e) Modifed existing code to use new #define and delegates. Robert did the review on the changes covered by Part 2. Remaining changes are all straightforward. #rb robert.manuszewski #jira UE-74493 [CL 15736777 by Tim Smith in ue5-main branch]
2021-03-18 08:13:59 -04:00
LiveCodingEndCompile();
// END EPIC MOD
// don't continue execution
return false;
}
bool actions::HandleExceptionFinished::Execute(const CommandType* command, const DuplexPipe* pipe, void* context, const void*, size_t)
{
ClientUserCommandThread::ExceptionResult* resultContext = static_cast<ClientUserCommandThread::ExceptionResult*>(context);
resultContext->returnAddress = command->returnAddress;
resultContext->framePointer = command->framePointer;
resultContext->stackPointer = command->stackPointer;
resultContext->continueExecution = command->continueExecution;
pipe->SendAck();
// don't continue execution
return false;
}
// BEGIN EPIC MOD
bool actions::PreCompile::Execute(const CommandType*, const DuplexPipe* pipe, void*, const void*, size_t)
{
LiveCodingPreCompile();
pipe->SendAck();
return true;
}
bool actions::PostCompile::Execute(const CommandType* command, const DuplexPipe* pipe, void*, const void*, size_t)
{
LiveCodingPostCompile(command->postCompileResult);
pipe->SendAck();
return true;
}
bool actions::TriggerReload::Execute(const CommandType*, const DuplexPipe* pipe, void*, const void*, size_t)
{
LiveCodingTriggerReload();
syncPoint::Leave();
syncPoint::Enter();
pipe->SendAck();
return true;
}
// END EPIC MOD