summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-03-26 11:27:01 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-03-26 11:27:01 +0800
commit0415404ae424d9fbf08d10e291d5a73c2ed821e6 (patch)
tree3566c0f894603db92f1294be75c96626f1f85c9c /server
parent02c05d770711b0d1edc3cb42a74fe6d03214903c (diff)
downloadlua-language-server-0415404ae424d9fbf08d10e291d5a73c2ed821e6.zip
内存测试
Diffstat (limited to 'server')
-rw-r--r--server/src/service.lua27
-rw-r--r--server/src/vm/function.lua10
-rw-r--r--server/src/vm/global.lua1
-rw-r--r--server/src/vm/library.lua26
-rw-r--r--server/src/vm/local.lua9
-rw-r--r--server/src/vm/multi.lua3
-rw-r--r--server/src/vm/value.lua7
-rw-r--r--server/src/vm/vm.lua24
8 files changed, 66 insertions, 41 deletions
diff --git a/server/src/service.lua b/server/src/service.lua
index 85d55543..7f22732e 100644
--- a/server/src/service.lua
+++ b/server/src/service.lua
@@ -8,7 +8,9 @@ local core = require 'core'
local lang = require 'language'
local updateTimer= require 'timer'
local buildVM = require 'vm'
-local source = require 'vm.source'
+local sourceMgr = require 'vm.source'
+local localMgr = require 'vm.local'
+local valueMgr = require 'vm.value'
local ErrorCodes = {
-- Defined by JSON RPC
@@ -622,13 +624,24 @@ function mt:_testMemory()
local alivedSource = 0
local deadSource = 0
- for src, id in pairs(source.watch) do
- if source.list[id] then
+ for _, id in pairs(sourceMgr.watch) do
+ if sourceMgr.list[id] then
alivedSource = alivedSource + 1
else
deadSource = deadSource + 1
end
end
+
+ local totalLocal = 0
+ for _ in pairs(localMgr.watch) do
+ totalLocal = totalLocal + 1
+ end
+
+ local totalValue = 0
+ for _ in pairs(valueMgr.watch) do
+ totalValue = totalValue + 1
+ end
+
local mem = collectgarbage 'count'
log.debug(('\n\z
State\n\z
@@ -638,14 +651,18 @@ function mt:_testMemory()
DeadVM: [%d]\n\z
CachedSrc:[%d]\n\z
AlivedSrc:[%d]\n\z
- DeadSrc: [%d]'):format(
+ DeadSrc: [%d]\n\z
+ TotalLoc: [%d]\n\z
+ TotalVal: [%d]'):format(
mem,
cachedVM,
aliveVM,
deadVM,
cachedSource,
alivedSource,
- deadSource
+ deadSource,
+ totalLocal,
+ totalValue
))
end
diff --git a/server/src/vm/function.lua b/server/src/vm/function.lua
index 973f984e..2ca12e2b 100644
--- a/server/src/vm/function.lua
+++ b/server/src/vm/function.lua
@@ -1,6 +1,6 @@
local createMulti = require 'vm.multi'
-local createValue = require 'vm.value'
-local createLocal = require 'vm.local'
+local valueMgr = require 'vm.value'
+local localMgr = require 'vm.local'
local sourceMgr = require 'vm.source'
local mt = {}
@@ -156,7 +156,7 @@ function mt:run(vm)
if self._runed == 1 then
-- 如果是面向对象形式的函数,创建隐藏的参数self
if self._objectSource then
- local loc = createLocal('self', self._objectSource, self._objectValue)
+ local loc = localMgr.create('self', self._objectSource, self._objectValue)
loc:set('hide', true)
self:saveLocal('self', loc)
self.args[#self.args+1] = loc
@@ -195,7 +195,7 @@ function mt:createArg(vm, arg)
vm:instantSource(arg)
arg:set('arg', true)
if arg.type == 'name' then
- local loc = createLocal(arg[1], arg, createValue('nil', arg))
+ local loc = localMgr.create(arg[1], arg, valueMgr.create('nil', arg))
self:saveLocal(arg[1], loc)
self.args[#self.args+1] = loc
elseif arg.type == '...' then
@@ -208,7 +208,7 @@ function mt:createLibArg(arg, source)
self._dots = createMulti()
else
local name = arg.name or '_'
- local loc = createLocal(name, source, createValue('any', source))
+ local loc = localMgr.create(name, source, valueMgr.create('any', source))
self:saveLocal(name, loc)
self.args[#self.args+1] = loc
end
diff --git a/server/src/vm/global.lua b/server/src/vm/global.lua
index 63db8487..54680fd3 100644
--- a/server/src/vm/global.lua
+++ b/server/src/vm/global.lua
@@ -1,4 +1,3 @@
-local createValue = require 'vm.value'
local library = require 'core.library'
local libraryBuilder = require 'vm.library'
local sourceMgr = require 'vm.source'
diff --git a/server/src/vm/library.lua b/server/src/vm/library.lua
index 60f56368..54dca81f 100644
--- a/server/src/vm/library.lua
+++ b/server/src/vm/library.lua
@@ -1,6 +1,6 @@
local sourceMgr = require 'vm.source'
-local createValue
+local valueMgr
local createFunction
local CHILD_CACHE = {}
@@ -13,16 +13,16 @@ function buildLibValue(lib)
if VALUE_CACHE[lib] then
return VALUE_CACHE[lib]
end
- if not createValue then
- createValue = require 'vm.value'
+ if not valueMgr then
+ valueMgr = require 'vm.value'
createFunction = require 'vm.function'
end
local tp = lib.type
local value
if tp == 'table' then
- value = createValue('table', sourceMgr.dummy())
+ value = valueMgr.create('table', sourceMgr.dummy())
elseif tp == 'function' then
- value = createValue('function', sourceMgr.dummy())
+ value = valueMgr.create('function', sourceMgr.dummy())
local func = createFunction()
value:setFunction(func)
if lib.args then
@@ -40,17 +40,17 @@ function buildLibValue(lib)
end
end
elseif tp == 'string' then
- value = createValue('string', sourceMgr.dummy())
+ value = valueMgr.create('string', sourceMgr.dummy())
elseif tp == 'boolean' then
- value = createValue('boolean', sourceMgr.dummy())
+ value = valueMgr.create('boolean', sourceMgr.dummy())
elseif tp == 'number' then
- value = createValue('number', sourceMgr.dummy())
+ value = valueMgr.create('number', sourceMgr.dummy())
elseif tp == 'integer' then
- value = createValue('integer', sourceMgr.dummy())
+ value = valueMgr.create('integer', sourceMgr.dummy())
elseif tp == 'nil' then
- value = createValue('nil', sourceMgr.dummy())
+ value = valueMgr.create('nil', sourceMgr.dummy())
else
- value = createValue(tp or 'any', sourceMgr.dummy())
+ value = valueMgr.create(tp or 'any', sourceMgr.dummy())
end
value:setLib(lib)
VALUE_CACHE[lib] = value
@@ -67,8 +67,8 @@ function buildLibValue(lib)
end
function buildLibChild(lib)
- if not createValue then
- createValue = require 'vm.value'
+ if not valueMgr then
+ valueMgr = require 'vm.value'
createFunction = require 'vm.function'
end
if CHILD_CACHE[lib] then
diff --git a/server/src/vm/local.lua b/server/src/vm/local.lua
index f5e65e83..106606ea 100644
--- a/server/src/vm/local.lua
+++ b/server/src/vm/local.lua
@@ -1,6 +1,7 @@
local sourceMgr = require 'vm.source'
local Sort = 0
+local Watch = setmetatable({}, {__mode = 'kv'})
local mt = {}
mt.__index = mt
@@ -137,7 +138,7 @@ function mt:getSource()
return sourceMgr.list[self.source]
end
-return function (name, source, value)
+local function create(name, source, value)
if not value then
error('Local must has a value')
end
@@ -154,5 +155,11 @@ return function (name, source, value)
value = value,
_info = {},
}, mt)
+ Watch[self] = true
return self
end
+
+return {
+ create = create,
+ watch = Watch,
+}
diff --git a/server/src/vm/multi.lua b/server/src/vm/multi.lua
index bf797f3f..5079468e 100644
--- a/server/src/vm/multi.lua
+++ b/server/src/vm/multi.lua
@@ -1,6 +1,3 @@
-local createValue = require 'vm.value'
-local sourceMgr = require 'vm.source'
-
local mt = {}
mt.__index = mt
mt.type = 'multi'
diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua
index c0f55b9d..11cb9ae1 100644
--- a/server/src/vm/value.lua
+++ b/server/src/vm/value.lua
@@ -3,6 +3,7 @@ local library = require 'core.library'
local sourceMgr = require 'vm.source'
local Sort = 0
+local Watch = setmetatable({}, {__mode = 'kv'})
local mt = {}
mt.__index = mt
@@ -36,6 +37,7 @@ local function create (tp, source, literal)
else
self:setType(tp, 1.0)
end
+ Watch[self] = true
return self
end
@@ -426,4 +428,7 @@ function mt:isGlobal()
return self._global
end
-return create
+return {
+ create = create,
+ watch = Watch,
+}
diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua
index b5ffa459..c519ad72 100644
--- a/server/src/vm/vm.lua
+++ b/server/src/vm/vm.lua
@@ -1,6 +1,6 @@
local library = require 'core.library'
-local createValue = require 'vm.value'
-local createLocal = require 'vm.local'
+local valueMgr = require 'vm.value'
+local localMgr = require 'vm.local'
local createLabel = require 'vm.label'
local createFunction = require 'vm.function'
local sourceMgr = require 'vm.source'
@@ -338,7 +338,7 @@ function mt:call(value, values, source)
end
function mt:createValue(tp, source, literal)
- local value = createValue(tp, source, literal)
+ local value = valueMgr.create(tp, source, literal)
value.uri = self:getUri()
return value
end
@@ -476,7 +476,7 @@ function mt:getSimple(simple, max)
local first = simple[1]
self:instantSource(first)
local value = self:getExp(first)
- value = self:getFirstInMulti(value) or createValue('nil', self:getDefaultSource())
+ value = self:getFirstInMulti(value) or valueMgr.create('nil', self:getDefaultSource())
first:bindValue(value, 'get')
if not max then
max = #simple
@@ -488,7 +488,7 @@ function mt:getSimple(simple, max)
local source = simple[i]
self:instantSource(source)
source:set('simple', simple)
- value = self:getFirstInMulti(value) or createValue('nil', self:getDefaultSource())
+ value = self:getFirstInMulti(value) or valueMgr.create('nil', self:getDefaultSource())
if source.type == 'call' then
local values, args = self:unpackList(source)
@@ -499,7 +499,7 @@ function mt:getSimple(simple, max)
end
object = nil
source:bindCall(func, args)
- value = self:call(func, values, source) or createValue('any', self:getDefaultSource())
+ value = self:call(func, values, source) or valueMgr.create('any', self:getDefaultSource())
elseif source.type == 'index' then
local child = source[1]
local index = self:getIndex(source)
@@ -538,8 +538,8 @@ function mt:getBinary(exp)
self:instantSource(exp)
local v1 = self:getExp(exp[1])
local v2 = self:getExp(exp[2])
- v1 = self:getFirstInMulti(v1) or createValue('nil', exp[1])
- v2 = self:getFirstInMulti(v2) or createValue('nil', exp[2])
+ v1 = self:getFirstInMulti(v1) or valueMgr.create('nil', exp[1])
+ v2 = self:getFirstInMulti(v2) or valueMgr.create('nil', exp[2])
local op = exp.op
-- TODO 搜索元方法
if op == 'or' then
@@ -778,7 +778,7 @@ end
function mt:setOne(var, value)
if not value then
- value = createValue('nil', self:getDefaultSource())
+ value = valueMgr.create('nil', self:getDefaultSource())
end
self:instantSource(var)
if var.type == 'name' then
@@ -882,7 +882,7 @@ function mt:doIn(action)
local args = self:unpackList(action.exp)
self:scopePush(action)
- local func = table.remove(args, 1) or createValue('any', self:getDefaultSource())
+ local func = table.remove(args, 1) or valueMgr.create('any', self:getDefaultSource())
local values = self:call(func, args, action) or createMulti()
self:forList(action.arg, function (arg)
local value = table.remove(values, 1)
@@ -1133,10 +1133,10 @@ function mt:createLocal(key, source, value)
end
if not value then
- value = createValue('nil', self:getDefaultSource())
+ value = valueMgr.create('nil', self:getDefaultSource())
end
- loc = createLocal(key, source, value)
+ loc = localMgr.create(key, source, value)
self:saveLocal(key, loc)
self:bindLocal(source, loc, 'local')
value:addInfo('local', source or self:getDefaultSource())