Skip to content

Commit

Permalink
Remove ExtendedWeakReference (#543)
Browse files Browse the repository at this point in the history
  • Loading branch information
josesimoes authored Dec 13, 2017
1 parent 880f335 commit 19edf5e
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 78 deletions.
32 changes: 16 additions & 16 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,22 +187,22 @@
secure: WOqlCsnwTzfDPJFoNV/h8mEESIpG/9uFn1u6oE8hGZtXwIQQlsY+NyyLt9Y5xoFn

matrix:
# - BOARD_NAME: 'ST_STM32F4_DISCOVERY'
# BUILD_OPTIONS: '-DTARGET_SERIES=STM32F4xx -DUSE_FPU=TRUE -DNF_FEATURE_DEBUGGER=TRUE -DSWO_OUTPUT=ON -DNF_FEATURE_RTC=ON -DAPI_Windows.Devices.Gpio=ON'
# - BOARD_NAME: 'ST_STM32F429I_DISCOVERY'
# BUILD_OPTIONS: '-DTARGET_SERIES=STM32F4xx -DUSE_FPU=TRUE -DNF_FEATURE_DEBUGGER=TRUE -DSWO_OUTPUT=ON -DNF_FEATURE_RTC=ON -DAPI_Windows.Devices.Gpio=ON'
# - BOARD_NAME: 'ST_NUCLEO64_F091RC'
# BUILD_OPTIONS: '-DTARGET_SERIES=STM32F0xx -DUSE_FPU=TRUE -DNF_FEATURE_DEBUGGER=TRUE -DSWO_OUTPUT=OFF -DNF_FEATURE_RTC=ON -DAPI_Windows.Devices.Gpio=OFF'
# - BOARD_NAME: 'ST_NUCLEO144_F746ZG'
# BUILD_OPTIONS: '-DTARGET_SERIES=STM32F7xx -DUSE_FPU=TRUE -DNF_FEATURE_DEBUGGER=TRUE -DSWO_OUTPUT=ON -DNF_FEATURE_RTC=ON -DAPI_Windows.Devices.Gpio=ON'
# - BOARD_NAME: 'MBN_QUAIL'
# BUILD_OPTIONS: '-DTARGET_SERIES=STM32F4xx -DUSE_FPU=TRUE -DNF_FEATURE_DEBUGGER=TRUE -DSWO_OUTPUT=OFF -DNF_FEATURE_RTC=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON'
# NEEDS_DFU: 'True'
# - BOARD_NAME: 'ST_STM32F769I_DISCOVERY'
# BUILD_OPTIONS: '-DTARGET_SERIES=STM32F7xx -DUSE_FPU=TRUE -DNF_FEATURE_DEBUGGER=TRUE -DSWO_OUTPUT=ON -DNF_FEATURE_RTC=ON -DAPI_Windows.Devices.Gpio=ON'
# - BOARD_NAME: 'NETDUINO3_WIFI'
# BUILD_OPTIONS: '-DTARGET_SERIES=STM32F4xx -DUSE_FPU=TRUE -DNF_FEATURE_DEBUGGER=TRUE -DSWO_OUTPUT=OFF -DNF_FEATURE_RTC=ON -DAPI_Windows.Devices.Gpio=ON'
# NEEDS_DFU: 'True'
- BOARD_NAME: 'ST_STM32F4_DISCOVERY'
BUILD_OPTIONS: '-DTARGET_SERIES=STM32F4xx -DUSE_FPU=TRUE -DNF_FEATURE_DEBUGGER=TRUE -DSWO_OUTPUT=ON -DNF_FEATURE_RTC=ON -DAPI_Windows.Devices.Gpio=ON'
- BOARD_NAME: 'ST_STM32F429I_DISCOVERY'
BUILD_OPTIONS: '-DTARGET_SERIES=STM32F4xx -DUSE_FPU=TRUE -DNF_FEATURE_DEBUGGER=TRUE -DSWO_OUTPUT=ON -DNF_FEATURE_RTC=ON -DAPI_Windows.Devices.Gpio=ON'
- BOARD_NAME: 'ST_NUCLEO64_F091RC'
BUILD_OPTIONS: '-DTARGET_SERIES=STM32F0xx -DUSE_FPU=TRUE -DNF_FEATURE_DEBUGGER=TRUE -DSWO_OUTPUT=OFF -DNF_FEATURE_RTC=ON -DAPI_Windows.Devices.Gpio=OFF'
- BOARD_NAME: 'ST_NUCLEO144_F746ZG'
BUILD_OPTIONS: '-DTARGET_SERIES=STM32F7xx -DUSE_FPU=TRUE -DNF_FEATURE_DEBUGGER=TRUE -DSWO_OUTPUT=ON -DNF_FEATURE_RTC=ON -DAPI_Windows.Devices.Gpio=ON'
- BOARD_NAME: 'MBN_QUAIL'
BUILD_OPTIONS: '-DTARGET_SERIES=STM32F4xx -DUSE_FPU=TRUE -DNF_FEATURE_DEBUGGER=TRUE -DSWO_OUTPUT=OFF -DNF_FEATURE_RTC=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON'
NEEDS_DFU: 'True'
- BOARD_NAME: 'ST_STM32F769I_DISCOVERY'
BUILD_OPTIONS: '-DTARGET_SERIES=STM32F7xx -DUSE_FPU=TRUE -DNF_FEATURE_DEBUGGER=TRUE -DSWO_OUTPUT=ON -DNF_FEATURE_RTC=ON -DAPI_Windows.Devices.Gpio=ON'
- BOARD_NAME: 'NETDUINO3_WIFI'
BUILD_OPTIONS: '-DTARGET_SERIES=STM32F4xx -DUSE_FPU=TRUE -DNF_FEATURE_DEBUGGER=TRUE -DSWO_OUTPUT=OFF -DNF_FEATURE_RTC=ON -DAPI_Windows.Devices.Gpio=ON'
NEEDS_DFU: 'True'
- BOARD_NAME: 'NANOCLR_WINDOWS'

matrix:
Expand Down
5 changes: 0 additions & 5 deletions src/CLR/Core/Execution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1942,11 +1942,6 @@ HRESULT CLR_RT_ExecutionEngine::NewObject( CLR_RT_HeapBlock& reference, const CL

NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_WeakReference::CreateInstance( weakref ));

if(inst.m_data == g_CLR_RT_WellKnownTypes.m_ExtendedWeakReference.m_data)
{
weakref->m_identity.m_flags |= CLR_RT_HeapBlock_WeakReference::WR_ExtendedType;
}

reference.SetObjectReference( weakref );
}
break;
Expand Down
11 changes: 0 additions & 11 deletions src/CLR/Core/GarbageCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,17 +469,6 @@ void CLR_RT_GarbageCollector::MarkWeak()

if(weak->IsAlive())
{
//
// Only extended weak references are kept alive, memory permitting.
//
if(weak->m_identity.m_flags & CLR_RT_HeapBlock_WeakReference::WR_ExtendedType)
{
if(weak->m_targetSerialized && weak->m_targetSerialized->IsAlive() == false)
{
weak->m_targetSerialized->MarkAlive();
}
}

if(weak->m_targetDirect)
{
if(weak->m_targetDirect->IsAlive())
Expand Down
35 changes: 2 additions & 33 deletions src/CLR/Core/HeapPersistence/Heap_Persistence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ bool CLR_RT_Persistence_Manager::ObjectHeader::Initialize( CLR_RT_HeapBlock_Weak

m_identity = wr->m_identity;
m_identity.m_crc = m_identity.ComputeCRC( array->GetFirstElement(), m_identity.m_length );
m_identity.m_flags &= CLR_RT_HeapBlock_WeakReference::WR_MaskForStorage;

memcpy( &m_object, array, sizeof(m_object) );
m_object.SetFlags( CLR_RT_HeapBlock::HB_Pinned | CLR_RT_HeapBlock::HB_Alive );
Expand Down Expand Up @@ -1303,22 +1302,10 @@ HRESULT CLR_RT_HeapBlock_WeakReference::SetTarget( CLR_RT_HeapBlock& targetRefer

m_targetDirect = target;

//
// Check if this is an Extended Weak Reference before calling SerializationEnabled().
// Checking a flag is faster than calling a function that is unlikely to be inlined
// (from a separate static library)
//
// As WR_ExtendedType can only be set in the constructor of the ExtendedWeakReference class,
// this flag cannot be unset after an EWR is persisted to flash.
// Thus, the EWR invalidation code only needs to be called when WR_ExtendedType is set,
// allowing it to be inside the following 'if' block, and minimizing the number of 'if' conditions
// to check for the non EWR case.
//
// This is particularly important to nanoCore and System.Threading.Dispatcher, which uses a
// WeakReference to cache the last used Dispatcher and improve event throughput.
//
if((m_identity.m_flags & CLR_RT_HeapBlock_WeakReference::WR_ExtendedType) != 0 &&
CLR_RT_BinaryFormatter::SerializationEnabled())
if(CLR_RT_BinaryFormatter::SerializationEnabled())
{
if(target)
{
Expand Down Expand Up @@ -1431,25 +1418,7 @@ void CLR_RT_HeapBlock_WeakReference::InsertInPriorityOrder()
NATIVE_PROFILE_CLR_HEAP_PERSISTENCE();
this->Unlink(); // Remove from the list before looking for a spot, to avoid comparing against ourselves.

if(m_identity.m_flags & CLR_RT_HeapBlock_WeakReference::WR_ExtendedType)
{
CLR_INT32 pri = m_identity.m_priority;
CLR_RT_HeapBlock_WeakReference* ptr = (CLR_RT_HeapBlock_WeakReference*)g_CLR_RT_ExecutionEngine.m_weakReferences.FirstNode();
while(true)
{
CLR_RT_HeapBlock_WeakReference* ptrNext = (CLR_RT_HeapBlock_WeakReference*)ptr->Next(); if(!ptrNext) break;

if(ptr->m_identity.m_priority <= pri) break;

ptr = ptrNext;
}

g_CLR_RT_ExecutionEngine.m_weakReferences.InsertBeforeNode( ptr, this );
}
else
{
g_CLR_RT_ExecutionEngine.m_weakReferences.LinkAtBack( this );
}
g_CLR_RT_ExecutionEngine.m_weakReferences.LinkAtBack( this );
}


Expand Down
10 changes: 1 addition & 9 deletions src/CLR/Core/TypeSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1121,14 +1121,7 @@ HRESULT CLR_RT_TypeDescriptor::InitializeFromObject( const CLR_RT_HeapBlock& ref
{
CLR_RT_HeapBlock_WeakReference* weak = (CLR_RT_HeapBlock_WeakReference*)obj;

if(weak->m_identity.m_flags & CLR_RT_HeapBlock_WeakReference::WR_ExtendedType)
{
cls = &g_CLR_RT_WellKnownTypes.m_ExtendedWeakReference;
}
else
{
cls = &g_CLR_RT_WellKnownTypes.m_WeakReference;
}
cls = &g_CLR_RT_WellKnownTypes.m_WeakReference;
}
break;

Expand Down Expand Up @@ -2648,7 +2641,6 @@ static const TypeIndexLookup c_TypeIndexLookup[] =
TIL( "System.Reflection" , "RuntimeFieldInfo" , m_FieldInfo ),

TIL( "System" , "WeakReference" , m_WeakReference ),
TIL( "Microsoft.SPOT" , "ExtendedWeakReference" , m_ExtendedWeakReference ),

TIL( "Microsoft.SPOT" , "SerializationHintsAttribute" , m_SerializationHintsAttribute ),

Expand Down
1 change: 0 additions & 1 deletion src/CLR/Include/nanoCLR_Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,6 @@ struct CLR_RT_WellKnownTypes
CLR_RT_TypeDef_Index m_FieldInfo;

CLR_RT_TypeDef_Index m_WeakReference;
CLR_RT_TypeDef_Index m_ExtendedWeakReference;

CLR_RT_TypeDef_Index m_SerializationHintsAttribute;

Expand Down
3 changes: 0 additions & 3 deletions src/CLR/Include/nanoCLR_Runtime__HeapBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -1989,9 +1989,6 @@ struct CLR_RT_HeapBlock_WeakReference : public CLR_RT_HeapBlock_Node // OBJECT H
static const CLR_UINT32 WR_Unused_10000000 = 0x10000000;
static const CLR_UINT32 WR_Persisted = 0x20000000;
static const CLR_UINT32 WR_Restored = 0x40000000;
static const CLR_UINT32 WR_ExtendedType = 0x80000000;

static const CLR_UINT32 WR_MaskForStorage = WR_SurviveBoot | WR_SurvivePowerdown | WR_ArrayOfBytes | WR_ExtendedType;

//--//

Expand Down

0 comments on commit 19edf5e

Please sign in to comment.