<commit_before>#include <iostream>

#include "config.h"
#include "vm.hpp"

#include "exception.hpp"
#include "exception_point.hpp"
#include "arguments.hpp"
#include "dispatch.hpp"
#include "primitives.hpp"
#include "call_frame.hpp"
#include "objectmemory.hpp"
#include "configuration.hpp"
#include "on_stack.hpp"

#include "builtin/array.hpp"
#include "builtin/exception.hpp"
#include "builtin/nativemethod.hpp"
#include "builtin/string.hpp"
#include "builtin/system.hpp"
#include "builtin/tuple.hpp"
#include "builtin/location.hpp"
#include "builtin/ffi_pointer.hpp"

#include "instruments/tooling.hpp"

#include "ontology.hpp"

#include "capi/capi.hpp"
#include "capi/handle.hpp"

#ifdef RBX_WINDOWS
#include <malloc.h>
#endif

namespace rubinius {
  /** Thread-local NativeMethodEnvironment instance. */
  utilities::thread::ThreadData<NativeMethodEnvironment*> native_method_environment;

/* Class methods */

  NativeMethodEnvironment* NativeMethodEnvironment::get() {
    return native_method_environment.get();
  }

  NativeMethodFrame::~NativeMethodFrame() {
    flush_cached_data();
    handles_.deref_all();
  }

  void NativeMethodFrame::check_tracked_handle(capi::Handle* handle,
                                               bool need_update)
  {
    if(need_update) {
      check_handles_ = true;
    }

    if(handles_.add_if_absent(handle)) {
      // We're seeing this object for the first time in this function.
      // Be sure that it's updated.
      handle->update(NativeMethodEnvironment::get());
    }
  }

  VALUE NativeMethodFrame::get_handle(STATE, Object* obj) {

    capi::Handle* handle = obj->handle(state);

    if(handle) {
      if(handles_.add_if_absent(handle)) {
        // We're seeing this object for the first time in this function.
        // Be sure that it's updated.
        handle->update(NativeMethodEnvironment::get());
      }
    } else {
      handle = state->shared().add_global_handle(state, obj);
      handles_.add_if_absent(handle);
    }

    return handle->as_value();
  }
<commit_msg>Assert that whenever we see a Data object it has a handle<commit_after>#include <iostream>

#include "config.h"
#include "vm.hpp"

#include "exception.hpp"
#include "exception_point.hpp"
#include "arguments.hpp"
#include "dispatch.hpp"
#include "primitives.hpp"
#include "call_frame.hpp"
#include "objectmemory.hpp"
#include "configuration.hpp"
#include "on_stack.hpp"

#include "builtin/array.hpp"
#include "builtin/data.hpp"
#include "builtin/exception.hpp"
#include "builtin/nativemethod.hpp"
#include "builtin/string.hpp"
#include "builtin/system.hpp"
#include "builtin/tuple.hpp"
#include "builtin/location.hpp"
#include "builtin/ffi_pointer.hpp"

#include "instruments/tooling.hpp"

#include "ontology.hpp"

#include "capi/capi.hpp"
#include "capi/handle.hpp"

#ifdef RBX_WINDOWS
#include <malloc.h>
#endif

namespace rubinius {
  /** Thread-local NativeMethodEnvironment instance. */
  utilities::thread::ThreadData<NativeMethodEnvironment*> native_method_environment;

/* Class methods */

  NativeMethodEnvironment* NativeMethodEnvironment::get() {
    return native_method_environment.get();
  }

  NativeMethodFrame::~NativeMethodFrame() {
    flush_cached_data();
    handles_.deref_all();
  }

  void NativeMethodFrame::check_tracked_handle(capi::Handle* handle,
                                               bool need_update)
  {
    if(need_update) {
      check_handles_ = true;
    }

    if(handles_.add_if_absent(handle)) {
      // We're seeing this object for the first time in this function.
      // Be sure that it's updated.
      handle->update(NativeMethodEnvironment::get());
    }
  }

  VALUE NativeMethodFrame::get_handle(STATE, Object* obj) {

    capi::Handle* handle = obj->handle(state);

    if(handle) {
      if(handles_.add_if_absent(handle)) {
        // We're seeing this object for the first time in this function.
        // Be sure that it's updated.
        handle->update(NativeMethodEnvironment::get());
      }
    } else {
      assert(!try_as<Data>(obj));
      handle = state->shared().add_global_handle(state, obj);
      handles_.add_if_absent(handle);
    }

    return handle->as_value();
  }

{'fraction_non_alphanumeric': 0.13000954198473283, 'fraction_numerical': 0.0, 'mean_word_length': 3.770193401592719, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '93959', 'n_tokens_mistral': 1326, 'n_tokens_neox': 1316, 'n_words': 270}