tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

source.cpp (1708B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #define ANNOTATE(property) __attribute__((annotate(property)))
      8 
      9 struct Cell {
     10  int f;
     11 } ANNOTATE("GC Thing");
     12 
     13 class AutoSuppressGC_Base {
     14 public:
     15  AutoSuppressGC_Base() {}
     16  ~AutoSuppressGC_Base() {}
     17 } ANNOTATE("Suppress GC");
     18 
     19 class AutoSuppressGC_Child : public AutoSuppressGC_Base {
     20 public:
     21  AutoSuppressGC_Child() : AutoSuppressGC_Base() {}
     22 };
     23 
     24 class AutoSuppressGC {
     25  AutoSuppressGC_Child helpImBeingSuppressed;
     26 
     27 public:
     28  AutoSuppressGC() {}
     29 };
     30 
     31 extern void GC() ANNOTATE("GC Call");
     32 
     33 void GC() {
     34  // If the implementation is too trivial, the function body won't be emitted at
     35  // all.
     36  asm("");
     37 }
     38 
     39 extern void foo(Cell*);
     40 
     41 void suppressedFunction() {
     42  GC();  // Calls GC, but is always called within AutoSuppressGC
     43 }
     44 
     45 void halfSuppressedFunction() {
     46  GC();  // Calls GC, but is sometimes called within AutoSuppressGC
     47 }
     48 
     49 void unsuppressedFunction() {
     50  GC();  // Calls GC, never within AutoSuppressGC
     51 }
     52 
     53 void f() {
     54  Cell* cell1 = nullptr;
     55  Cell* cell2 = nullptr;
     56  Cell* cell3 = nullptr;
     57  {
     58    AutoSuppressGC nogc;
     59    suppressedFunction();
     60    halfSuppressedFunction();
     61  }
     62  foo(cell1);
     63  halfSuppressedFunction();
     64  foo(cell2);
     65  unsuppressedFunction();
     66  {
     67    // Old bug: it would look from the first AutoSuppressGC constructor it
     68    // found to the last destructor. This statement *should* have no effect.
     69    AutoSuppressGC nogc;
     70  }
     71  foo(cell3);
     72 }