Skip to content
Closed
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
21 changes: 21 additions & 0 deletions src/coreclr/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22342,6 +22342,27 @@ size_t gc_heap::exponential_smoothing (int gen, size_t collection_count, size_t
//internal part of gc used by the serial and concurrent version
void gc_heap::gc1()
{
#ifdef FEATURE_EVENT_TRACE
EventArray<uint8_t> arr1;
arr1.Count = 10;
arr1.Data = new (nothrow) uint8_t[10];
for (uint8_t i = 0; i < 10; i++)
{
arr1.Data[i] = i * i + i + 1;
}

EventArray<uint16_t> arr2;
arr2.Count = 6;
arr2.Data = new (nothrow) uint16_t[6];
for (uint16_t i = 0; i < 6; i++)
{
arr2.Data[i] = i * (i + 1);
}

GCEventFireTestArray_V1 (arr1, arr2);
delete[] arr1.Data;
delete[] arr2.Data;
#endif //FEATURE_EVENT_TRACE
#ifdef BACKGROUND_GC
assert (settings.concurrent == (uint32_t)(bgc_thread_id.IsCurrentThread()));
#endif //BACKGROUND_GC
Expand Down
91 changes: 73 additions & 18 deletions src/coreclr/gc/gcevent_serializers.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,22 @@
#define ByteSwap64 __builtin_bswap64
#endif // MSC_VER

namespace gc_event
template<class T>
class EventArray
{
public:
uint8_t Count;
T* Data;
};

namespace gc_event
{
/*
* `EventSerializatonTraits` is a trait implemented by types that
* can be serialized to the payload of a dynamic event.
* `PrimitiveEventSerializatonTraits` is a trait implemented by types that
* can be serialized to the payload of a dynamic event with a fixed size.
*/
template<class T>
struct EventSerializationTraits
struct PrimitiveEventSerializationTraits
{
/*
* Serializes the value `value` to the buffer `buffer`, incrementing
Expand All @@ -66,37 +73,36 @@ struct EventSerializationTraits
* large enough to accommodate the serialized form of T.
*/
static void Serialize(const T& value, uint8_t** buffer) = delete;

/*
* Returns the size of the value `value` if it were to be serialized.
* Returns the size required for serializing this type.
*/
static size_t SerializedSize(const T& value) = delete;
static size_t SerializedSize() = delete;
};

/*
* EventSerializationTraits implementation for uint16_t. Other integral types
* PrimitiveEventSerializationTraits implementation for uint8_t. Other integral types
* can follow this pattern.
*
* The convention here is that integral types are always serialized as
* little-endian.
*/
template<>
struct EventSerializationTraits<uint8_t>
struct PrimitiveEventSerializationTraits<uint8_t>
{
static void Serialize(const uint8_t& value, uint8_t** buffer)
{
**((uint8_t**)buffer) = value;
*buffer += sizeof(uint8_t);
}

static size_t SerializedSize(const uint8_t& value)
static size_t SerializedSize()
{
return sizeof(uint8_t);
}
};

template<>
struct EventSerializationTraits<uint16_t>
struct PrimitiveEventSerializationTraits<uint16_t>
{
static void Serialize(const uint16_t& value, uint8_t** buffer)
{
Expand All @@ -109,14 +115,14 @@ struct EventSerializationTraits<uint16_t>
*buffer += sizeof(uint16_t);
}

static size_t SerializedSize(const uint16_t& value)
static size_t SerializedSize()
{
return sizeof(uint16_t);
}
};

template<>
struct EventSerializationTraits<uint32_t>
struct PrimitiveEventSerializationTraits<uint32_t>
{
static void Serialize(const uint32_t& value, uint8_t** buffer)
{
Expand All @@ -129,14 +135,14 @@ struct EventSerializationTraits<uint32_t>
*buffer += sizeof(uint32_t);
}

static size_t SerializedSize(const uint32_t& value)
static size_t SerializedSize()
{
return sizeof(uint32_t);
}
};

template<>
struct EventSerializationTraits<uint64_t>
struct PrimitiveEventSerializationTraits<uint64_t>
{
static void Serialize(const uint64_t& value, uint8_t** buffer)
{
Expand All @@ -149,27 +155,76 @@ struct EventSerializationTraits<uint64_t>
*buffer += sizeof(uint64_t);
}

static size_t SerializedSize(const uint64_t& value)
static size_t SerializedSize()
{
return sizeof(uint64_t);
}
};

template<>
struct EventSerializationTraits<float>
struct PrimitiveEventSerializationTraits<float>
{
static void Serialize(const float& value, uint8_t** buffer)
{
memcpy(*buffer, &value, sizeof(float));
*buffer += sizeof(float);
}

static size_t SerializedSize(const float& value)
static size_t SerializedSize()
{
return sizeof(float);
}
};

/*
* `EventSerializatonTraits` is a trait implemented by types that
* can be serialized to the payload of a dynamic event.
*/
template<class T>
struct EventSerializationTraits
{
/*
* Serializes the value `value` to the buffer `buffer`, incrementing
* the buffer double-pointer to point to the next byte to be written.
*
* It is the responsibility of the caller to ensure that the buffer is
* large enough to accommodate the serialized form of T.
*/
static void Serialize(const T& value, uint8_t** buffer)
{
PrimitiveEventSerializationTraits<T>::Serialize(value, buffer);
}

/*
* Returns the size of the value `value` if it were to be serialized.
*/
static size_t SerializedSize(const T& value)
{
return PrimitiveEventSerializationTraits<T>::SerializedSize();
}
};

template<class T>
struct EventSerializationTraits<EventArray<T>>
{
static void Serialize(const EventArray<T>& value, uint8_t** pBuffer)
{
uint8_t* buffer = *pBuffer;
buffer[0] = value.Count;
buffer += 1;
for (uint8_t i = 0; i < value.Count; i++)
{
PrimitiveEventSerializationTraits<T>::Serialize(value.Data[i], &buffer);
}
*pBuffer = buffer;
}

static size_t SerializedSize(const EventArray<T>& value)
{
return sizeof(uint8_t) + PrimitiveEventSerializationTraits<T>::SerializedSize() * value.Count;
}
};

/*
* Helper routines for serializing lists of arguments.
*/
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/gc/gcevents.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ DYNAMIC_EVENT(CommittedUsage, GCEventLevel_Information, GCEventKeyword_GC, 1)
DYNAMIC_EVENT(SizeAdaptationTuning, GCEventLevel_Information, GCEventKeyword_GC, 1)
DYNAMIC_EVENT(SizeAdaptationFullGCTuning, GCEventLevel_Information, GCEventKeyword_GC, 1)
DYNAMIC_EVENT(SizeAdaptationSample, GCEventLevel_Information, GCEventKeyword_GC, 1)
DYNAMIC_EVENT(TestArray, GCEventLevel_Information, GCEventKeyword_GC, 1)

#undef KNOWN_EVENT
#undef DYNAMIC_EVENT