2018-11-30 19:52:05 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2018-11-30 15:39:55 +00:00
|
|
|
* vim: set ts=4 sw=2 et tw=80:
|
2013-07-03 07:24:32 +00:00
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_jsipc_JavaScriptParent__
|
|
|
|
#define mozilla_jsipc_JavaScriptParent__
|
|
|
|
|
2014-05-16 23:40:36 +00:00
|
|
|
#include "JavaScriptBase.h"
|
2013-07-03 07:24:32 +00:00
|
|
|
#include "mozilla/jsipc/PJavaScriptParent.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace jsipc {
|
|
|
|
|
2014-05-16 23:40:36 +00:00
|
|
|
class JavaScriptParent : public JavaScriptBase<PJavaScriptParent> {
|
2013-07-03 07:24:32 +00:00
|
|
|
public:
|
Bug 1481998 - Make mozilla::Hash{Map,Set}'s entry storage allocation lazy. r=luke,sfink
Entry storage allocation now occurs on the first lookupForAdd()/put()/putNew().
This removes the need for init() and initialized(), and matches how
PLDHashTable/nsTHashtable work. It also removes the need for init() functions
in a lot of types that are built on top of mozilla::Hash{Map,Set}.
Pros:
- No need for init() calls and subsequent checks.
- No memory allocated for empty tables, which are not that uncommon.
Cons:
- An extra branch in lookup() and lookupForAdd(), but not in put()/putNew(),
because the existing checkOverloaded() can handle it.
Specifics:
- Construction now can take a length parameter.
- init() is removed. Explicit length-setting, when necessary, now occurs in the
constructors.
- initialized() is removed.
- capacity() now returns zero when the entry storage is absent.
- lookupForAdd() is no longer `const`, because it can instantiate the storage,
which requires modifications.
- lookupForAdd() can now return an invalid AddPtr in two cases:
- old: hashing failure (due to OOM in the hasher)
- new: OOM while instantiating entry storage
The existing failure handling paths for the old case work for the new case.
- clear(), finish(), and clearAndShrink() are replaced by clear(), compact(),
and reserve(). The old compactIfUnderloaded() is also removed.
- Capacity computation code is now in its own functions, bestCapacity() and
hashShift(). setTableSizeLog2() is removed.
- uint32_t is used throughout for capacities, instead of size_t, for
consistency with other similar values.
- changeTableSize() now takes a capacity instead of a deltaLog2, and it can now
handle !mTable.
Measurements:
- Total source code size is reduced by over 900 lines. Also, lots of existing
lines got shorter (i.e. two checks were reduced to one).
- Executable size barely changed, down by 2 KiB on Linux64. The extra branches
are compensated for by the lack of init() calls.
- Speed changed negligibly. The instruction count for Bench_Cpp_MozHash
increased from 2.84 billion to 2.89 billion but any execution time change was
well below noise.
2018-08-10 08:00:29 +00:00
|
|
|
JavaScriptParent();
|
2014-05-16 23:40:37 +00:00
|
|
|
virtual ~JavaScriptParent();
|
2013-07-03 07:24:32 +00:00
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
void trace(JSTracer* trc);
|
2014-02-05 16:39:59 +00:00
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
void drop(JSObject* obj);
|
2013-07-03 07:24:32 +00:00
|
|
|
|
2015-10-23 23:31:54 +00:00
|
|
|
bool allowMessage(JSContext* cx) override;
|
2016-10-18 22:58:33 +00:00
|
|
|
void afterProcessTask();
|
2014-05-29 01:05:22 +00:00
|
|
|
|
|
|
|
protected:
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool isParent() override { return true; }
|
2015-03-28 22:22:11 +00:00
|
|
|
virtual JSObject* scopeForTargetObjects() override;
|
2016-10-18 22:58:33 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
uint64_t savedNextCPOWNumber_;
|
2013-07-03 07:24:32 +00:00
|
|
|
};
|
|
|
|
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace jsipc
|
|
|
|
} // namespace mozilla
|
2013-07-03 07:24:32 +00:00
|
|
|
|
|
|
|
#endif // mozilla_jsipc_JavaScriptWrapper_h__
|