<commit_before>/* The GC superclass methods, used by both GCs. */
#include "object_utils.hpp"
#include "gc/gc.hpp"

#include "objectmemory.hpp"

#include "gc/object_mark.hpp"

#include "builtin/class.hpp"
#include "builtin/tuple.hpp"
#include "builtin/module.hpp"
#include "builtin/symbol.hpp"
#include "builtin/weakref.hpp"
#include "builtin/compiledcode.hpp"
#include "builtin/nativemethod.hpp"
#include "call_frame.hpp"
#include "builtin/variable_scope.hpp"
#include "builtin/constantscope.hpp"
#include "builtin/block_environment.hpp"
#include "capi/handle.hpp"

#ifdef ENABLE_LLVM
#include "llvm/state.hpp"
#endif

#include "instruments/tooling.hpp"

#include "arguments.hpp"

#include "object_watch.hpp"

namespace rubinius {

  GCData::GCData(VM* state)
    : roots_(state->globals().roots)
    , handles_(state->om->capi_handles())
    , cached_handles_(state->om->cached_capi_handles())
    , global_cache_(state->shared.global_cache)
    , threads_(state->shared.threads())
    , global_handle_locations_(state->om->global_capi_handle_locations())
    , gc_token_(0)
#ifdef ENABLE_LLVM
    , llvm_state_(LLVMState::get_if_set(state))
#endif
  {}

  GCData::GCData(VM* state, GCToken gct)
    : roots_(state->globals().roots)
    , handles_(state->om->capi_handles())
    , cached_handles_(state->om->cached_capi_handles())
    , global_cache_(state->shared.global_cache)
    , threads_(state->shared.threads())
    , global_handle_locations_(state->om->global_capi_handle_locations())
    , gc_token_(&gct)
#ifdef ENABLE_LLVM
    , llvm_state_(LLVMState::get_if_set(state))
#endif
  {}

  GarbageCollector::GarbageCollector(ObjectMemory *om)
                   :object_memory_(om), weak_refs_(NULL) { }

  VM* GarbageCollector::state() {
    return object_memory_->state();
  }

  /**
   * Scans the specified Object +obj+ for references to other Objects, and
   * marks those Objects as reachable. Understands how to read the inside of
   * an Object and find all references located within. For each reference
   * found, it marks the object pointed to as live (which may trigger
   * movement of the object in a copying garbage collector), but does not
   * recursively scan into the referenced object (since such recursion could
   * be arbitrarily deep, depending on the object graph, and this could cause
   * the stack to blow up).
   * /param obj The Object to be scanned for references to other Objects.
   */
  void GarbageCollector::scan_object(Object* obj) {
    Object* slot;

#ifdef ENABLE_OBJECT_WATCH
    if(watched_p(obj)) {
      std::cout << "detected " << obj << " during scan_object.\n";
    }
#endif

    slot = saw_object(obj->klass());
    if(slot) obj->klass(object_memory_, force_as<Class>(slot));

    if(obj->ivars()->reference_p()) {
      slot = saw_object(obj->ivars());
      if(slot) obj->ivars(object_memory_, slot);
    }

    // Handle Tuple directly, because it's so common
    if(Tuple* tup = try_as<Tuple>(obj)) {
      native_int size = tup->num_fields();

      for(native_int i = 0; i < size; i++) {
        slot = tup->field[i];
        if(slot->reference_p()) {
          Object* moved = saw_object(slot);
          if(moved && moved != slot) {
            tup->field[i] = moved;
            object_memory_->write_barrier(tup, moved);
          }
        }
      }<commit_msg>Don't go through write barrier if not necessary<commit_after>/* The GC superclass methods, used by both GCs. */
#include "object_utils.hpp"
#include "gc/gc.hpp"

#include "objectmemory.hpp"

#include "gc/object_mark.hpp"

#include "builtin/class.hpp"
#include "builtin/tuple.hpp"
#include "builtin/module.hpp"
#include "builtin/symbol.hpp"
#include "builtin/weakref.hpp"
#include "builtin/compiledcode.hpp"
#include "builtin/nativemethod.hpp"
#include "call_frame.hpp"
#include "builtin/variable_scope.hpp"
#include "builtin/constantscope.hpp"
#include "builtin/block_environment.hpp"
#include "capi/handle.hpp"

#ifdef ENABLE_LLVM
#include "llvm/state.hpp"
#endif

#include "instruments/tooling.hpp"

#include "arguments.hpp"

#include "object_watch.hpp"

namespace rubinius {

  GCData::GCData(VM* state)
    : roots_(state->globals().roots)
    , handles_(state->om->capi_handles())
    , cached_handles_(state->om->cached_capi_handles())
    , global_cache_(state->shared.global_cache)
    , threads_(state->shared.threads())
    , global_handle_locations_(state->om->global_capi_handle_locations())
    , gc_token_(0)
#ifdef ENABLE_LLVM
    , llvm_state_(LLVMState::get_if_set(state))
#endif
  {}

  GCData::GCData(VM* state, GCToken gct)
    : roots_(state->globals().roots)
    , handles_(state->om->capi_handles())
    , cached_handles_(state->om->cached_capi_handles())
    , global_cache_(state->shared.global_cache)
    , threads_(state->shared.threads())
    , global_handle_locations_(state->om->global_capi_handle_locations())
    , gc_token_(&gct)
#ifdef ENABLE_LLVM
    , llvm_state_(LLVMState::get_if_set(state))
#endif
  {}

  GarbageCollector::GarbageCollector(ObjectMemory *om)
                   :object_memory_(om), weak_refs_(NULL) { }

  VM* GarbageCollector::state() {
    return object_memory_->state();
  }

  /**
   * Scans the specified Object +obj+ for references to other Objects, and
   * marks those Objects as reachable. Understands how to read the inside of
   * an Object and find all references located within. For each reference
   * found, it marks the object pointed to as live (which may trigger
   * movement of the object in a copying garbage collector), but does not
   * recursively scan into the referenced object (since such recursion could
   * be arbitrarily deep, depending on the object graph, and this could cause
   * the stack to blow up).
   * /param obj The Object to be scanned for references to other Objects.
   */
  void GarbageCollector::scan_object(Object* obj) {
    Object* slot;

#ifdef ENABLE_OBJECT_WATCH
    if(watched_p(obj)) {
      std::cout << "detected " << obj << " during scan_object.\n";
    }
#endif

    slot = saw_object(obj->klass());
    if(slot && slot != obj->klass()) {
      obj->klass(object_memory_, force_as<Class>(slot));
    }

    if(obj->ivars()->reference_p()) {
      slot = saw_object(obj->ivars());
      if(slot && slot != obj->ivars()) {
        obj->ivars(object_memory_, slot);
      }
    }

    // Handle Tuple directly, because it's so common
    if(Tuple* tup = try_as<Tuple>(obj)) {
      native_int size = tup->num_fields();

      for(native_int i = 0; i < size; i++) {
        slot = tup->field[i];
        if(slot->reference_p()) {
          Object* moved = saw_object(slot);
          if(moved && moved != slot) {
            tup->field[i] = moved;
            object_memory_->write_barrier(tup, moved);
          }
        }
      }
{'fraction_non_alphanumeric': 0.13511518015357354, 'fraction_numerical': 0.0005906674542232723, 'mean_word_length': 3.716573816155989, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2167795', 'n_tokens_mistral': 2239, 'n_tokens_neox': 2213, 'n_words': 499}