-/* Copyright (c) 2014. The SimGrid Team.
+/* Copyright (c) 2014-2015. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
#include "mc_private.h"
#include "mc/datatypes.h"
#include <mc/mc.h>
-
-extern "C" {
+#include "mc_hash.hpp"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_hash, mc, "Logging specific to mc_hash");
+namespace simgrid {
+namespace mc {
+
// This is djb2:
-typedef uint64_t mc_hash_t;
-#define MC_HASH_INIT ((uint64_t)5381)
+#define MC_HASH_INIT ((simgrid::mc::hash_type)5381)
-// #define MC_HASH(hash, value) hash = (((hash << 5) + hash) + (uint64_t) value)
-#define MC_HASH(hash, value) \
- { hash = (((hash << 5) + hash) + (uint64_t) value);\
- XBT_DEBUG("%s:%i: %" PRIx64 " -> %" PRIx64, __FILE__, __LINE__, (uint64_t) value, hash); }
+template<class T>
+static void hash_update(hash_type& hash, T const& value)
+{
+ hash = (hash << 5) + hash + (uint64_t) value;
+}
// ***** Hash state
return false;
}
-static void mc_hash_binary(mc_hash_t * hash, const void *s, size_t len)
+static void mc_hash_binary(hash_type * hash, const void *s, size_t len)
{
const char *p = (const char*) s;
for (size_t i = 0; i != len; ++i) {
- MC_HASH(*hash, p[i]);
+ hash_update(*hash, p[i]);
}
}
* \param address address of the variable
* \param type type of the variable
* */
-static void mc_hash_value(mc_hash_t * hash, mc_hashing_state * state,
- mc_object_info_t info, const void *address,
- dw_type_t type)
+static void mc_hash_value(hash_type * hash, mc_hashing_state * state,
+ simgrid::mc::ObjectInformation* info, const void *address,
+ simgrid::mc::Type* type)
{
- mc_process_t process = &mc_model_checker->process();
+ simgrid::mc::Process* process = &mc_model_checker->process();
top:
switch (type->type) {
return;
long element_count = type->element_count;
- dw_type_t subtype = type->subtype;
+ simgrid::mc::Type* subtype = type->subtype;
if (subtype == NULL) {
XBT_DEBUG("Hash array without subtype");
return;
return;
unsigned int cursor = 0;
- dw_type_t member;
+ simgrid::mc::Type* member;
xbt_dynar_foreach(type->members, cursor, member) {
XBT_DEBUG("Hash struct member %s", member->name);
if (type->subtype == NULL)
}
if (type->subtype == NULL) {
- XBT_DEBUG("Missing type for %p (type=%s)", pointed, type->dw_type_id);
+ XBT_DEBUG("Missing type for %p (type=%s)",
+ pointed, type->type_id.c_str());
return;
}
}
}
-static void mc_hash_object_globals(mc_hash_t * hash, mc_hashing_state * state,
- mc_object_info_t info)
+static void mc_hash_object_globals(hash_type * hash, mc_hashing_state * state,
+ simgrid::mc::ObjectInformation* info)
{
unsigned int cursor = 0;
- dw_variable_t variable;
+ simgrid::mc::Variable* variable;
xbt_dynar_foreach(info->global_variables, cursor, variable) {
XBT_DEBUG("Hash global variable %s", variable->name);
- if (variable->type_origin == NULL) {
+ if (variable->type_id == NULL) {
// Nothing
continue;
}
- dw_type_t type = variable->type;
+ simgrid::mc::Type* type = variable->type;
if (type == NULL) {
// Nothing
continue;
}
static void mc_hash_stack_frame(mc_hash_t * hash,
- mc_object_info_t info,
- unw_cursor_t * unw_cursor, dw_frame_t frame,
+ simgrid::mc::ObjectInformation* info,
+ unw_cursor_t * unw_cursor, simgrid::mc::Frame* frame,
char *frame_pointer, mc_hashing_state * state)
{
// return; // TEMP
unsigned int cursor = 0;
- dw_variable_t variable;
+ simgrid::mc::Variable* variable;
xbt_dynar_foreach(frame->variables, cursor, variable) {
- if (variable->type_origin == NULL) {
+ if (variable->type_id == NULL) {
XBT_DEBUG("Hash local variable %s without type", variable->name);
continue;
}
variable->object_info, unw_cursor,
frame_pointer, NULL);
- dw_type_t type = variable->type;
+ simgrid::mc::Type* type = variable->type;
if (type == NULL) {
XBT_DEBUG("Hash local variable %s without loctypeation", variable->name);
continue;
unsigned cursor = 0;
mc_stack_frame_t stack_frame;
- xbt_dynar_foreach(stack->stack_frames, cursor, stack_frame) {
+ for(s_mc_stack_frame_t const& stack_frame : stack->stack_frames) {
- MC_HASH(*hash, stack_frame->ip);
+ hash_update(*hash, stack_frame.ip);
- mc_object_info_t info;
- if (stack_frame->ip >= (unw_word_t) libsimgrid_info->start_exec
- && stack_frame->ip < (unw_word_t) libsimgrid_info->end_exec)
+ simgrid::mc::ObjectInformation* info;
+ if (stack_frame.ip >= (unw_word_t) libsimgrid_info->start_exec
+ && stack_frame.ip < (unw_word_t) libsimgrid_info->end_exec)
info = libsimgrid_info;
- else if (stack_frame->ip >= (unw_word_t) binary_info->start_exec
- && stack_frame->ip < (unw_word_t) binary_info->end_exec)
+ else if (stack_frame.ip >= (unw_word_t) binary_info->start_exec
+ && stack_frame.ip < (unw_word_t) binary_info->end_exec)
info = binary_info;
else
continue;
- mc_hash_stack_frame(hash, info, &(stack_frame->unw_cursor),
- stack_frame->frame, (void *) stack_frame->frame_base,
+ mc_hash_stack_frame(hash, info, &(stack_frame.unw_cursor),
+ stack_frame.frame, (void *) stack_frame.frame_base,
state);
}
unsigned int cursor = 0;
mc_snapshot_stack_t current_stack;
- MC_HASH(*hash, xbt_dynar_length(stacks_areas));
+ hash_update(*hash, xbt_dynar_length(stacks_areas));
int i = 0;
xbt_dynar_foreach(stacks, cursor, current_stack) {
}
#endif
-uint64_t mc_hash_processes_state(int num_state, xbt_dynar_t stacks)
+static hash_type hash(std::vector<s_mc_snapshot_stack_t> const& stacks)
{
- XBT_DEBUG("START hash %i", num_state);
-
#if 0
mc_hashing_state state;
mc_hash_state_init(&state);
#endif
- mc_hash_t hash = MC_HASH_INIT;
+ hash_type hash = MC_HASH_INIT;
- MC_HASH(hash, xbt_swag_size(simix_global->process_list)); // process count
+ hash_update(hash, xbt_swag_size(simix_global->process_list));
#if 0
// mc_hash_object_globals(&hash, &state, binary_info);
// mc_hash_object_globals(&hash, &state, libsimgrid_info);
mc_hash_state_destroy(&state);
#endif
- XBT_DEBUG("END hash %i", num_state);
+
return hash;
}
+hash_type hash(Snapshot const& snapshot)
+{
+ XBT_DEBUG("START hash %i", snapshot.num_state);
+ hash_type res = simgrid::mc::hash(snapshot.stacks);
+ XBT_DEBUG("END hash %i", snapshot.num_state);
+ return res;
+}
+
+}
}